Can someone help me parse from the email

Can someone help me parse from the email

Post by sjone » Sun, 11 Apr 2004 14:00:57



I receives like the following -

Is it possible to log onto my POP3 account grab the email and extract the

Order Number
Order Date
Ref# (000000000000)
Ship To: Name and Address

Thanks in advance

******Email Sample*****

C U S T O M E R   R E C E I P T

X O M XXR                                            Order Number: 175381
America's Premier Value Merchant           Order Date: 4/4/2004
84 Commercial Road                                Ship Via: FedEx
Huntington, IN 46750                               Payment: MC
800-348-5004
Fax: 219-358-1806

        Bill To:                                Ship To:
           Steve xxxxx                             Rochelle Trom
                           5xxx South xxxxxx xxx            Re: 000000000000
                                                          1920 West 1 Street
           xxxx Springs, xx xxxx              Superior, WI 54880
                Telephone: (x1x)2x9-xxxx

********End Sample************

 
 
 

Can someone help me parse from the email

Post by Chris F.A. Johnso » Sun, 11 Apr 2004 15:55:38



> I receives like the following -

> Is it possible to log onto my POP3 account grab the email and extract the

> Order Number
> Order Date
> Ref# (000000000000)
> Ship To: Name and Address

    Yes. You can do it all in a shell script if you have bash2 or
    ksh93, but I'd recommend using a mail client to save the
    message to a file.

> ******Email Sample*****

> C U S T O M E R   R E C E I P T

> X O M XXR                                            Order Number: 175381
> America's Premier Value Merchant           Order Date: 4/4/2004
> 84 Commercial Road                                Ship Via: FedEx
> Huntington, IN 46750                               Payment: MC
> 800-348-5004
> Fax: 219-358-1806

>       Bill To:                                Ship To:
>            Steve xxxxx                             Rochelle Trom
>            5xxx South xxxxxx xxx            Re: 000000000000
>                                                           1920 West 1 Street
>            xxxx Springs, xx xxxx              Superior, WI 54880
>               Telephone: (x1x)2x9-xxxx

> ********End Sample************

    It's hard to tell from the mangled message above just which parts
    are the ship-to address (is the REF# actuall in the middle of
    it?), but the Order Number, Order Date, and Ref# can be obtained
    with:

## these work in bash2 and ksh93
NL=$'\n'
CR=$'\r'
## use literal newline and carriage return in other shells

msg=`< MSG-2` ## Use correct name of file
tail=${msg#*Order Number: }
on=${tail%%$NL*}
tail=${tail#*Order Date: }
od=${tail%%$NL*}
ref=${tail#*Re: }
ref=${ref%%$NL*}

echo "ORDER NUMBER: $on"
echo "ORDER DATE:   $od"
echo "REF #:        $ref"
#### EOS ####

    To retrieve the e-mail from a POP3 server in bash or ksh:

## set these variables to appropriate values
pop=localhost
user=bgates
pass=money

cmd() {
  printf "%s\n" "$*" >&3
  read ok num junk <&3
  [ "${ok%$CR}" = "+OK" ] || { printf "%s\n" "$*"; exit 5; }

Quote:}

NL=$'\n'
CR=$'\r'
exec 3<>/dev/tcp/$pop/110
read ok num junk <&3
[ "$ok" = "+OK" ] || exit 5

cmd user $user
cmd pass $pass
cmd stat

msg=1
MSG=$num
while [ $msg -lt $MSG ]
do
    retr=0
    cmd top $msg 0
    while IFS= read -r line <&3
    do
      line=${line%$CR} ## strip CR
      case $line in
          From:*"$from"*) retr=1 ;;
          .) break;;
      esac
    done

    if [ $retr -eq 1 ]
    then
      cmd retr $msg
      while IFS= read -r line <&3
      do
        line=${line%$CR}
        case $line in
            .) break ;;
            *) printf "%s\n" "$line" ;;
        esac
      done >> MSG-$msg
      break
    fi
    msg=$(( $msg + 1 ))
done
#### EOS ####

    Afer running the above script, any messages from the address in
    $from will be stored in MSG-XXX, where XXX is the number of the
    message (as it was on the server).

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

Can someone help me parse from the email

Post by Alan Conno » Sun, 11 Apr 2004 16:26:23



> I receives like the following -

> Is it possible to log onto my POP3 account grab the email and extract the

> Order Number
> Order Date
> Ref# (000000000000)
> Ship To: Name and Address

> Thanks in advance

> ******Email Sample*****

> C U S T O M E R   R E C E I P T

> X O M XXR                                            Order Number: 175381
> America's Premier Value Merchant           Order Date: 4/4/2004
> 84 Commercial Road                                Ship Via: FedEx
> Huntington, IN 46750                               Payment: MC
> 800-348-5004
> Fax: 219-358-1806

>    Bill To:                                Ship To:
>            Steve xxxxx                             Rochelle Trom
>                       5xxx South xxxxxx xxx            Re: 000000000000
>                                                           1920 West 1 Street
>            xxxx Springs, xx xxxx              Superior, WI 54880
>            Telephone: (x1x)2x9-xxxx

> ********End Sample************

Do you run procmail?

Do you use mbox or maildir mailboxes?

What shell do you use?

What do you want the output file to look like?

The answer is yes and fairly simply if you have procmail installed
and configured.

AC

--
Pass-List -----> Block-List ----> Challenge-Response
The key to taking control of your mailbox.
http://www.uwasa.fi/~ts/info/spamfoil.html
http://tinyurl.com/3c3ag

 
 
 

Can someone help me parse from the email

Post by Charles Dem » Sun, 11 Apr 2004 22:51:26




>I receives like the following -

>Is it possible to log onto my POP3 account grab the email and extract the

>Order Number
>Order Date
>Ref# (000000000000)
>Ship To: Name and Address

>Thanks in advance

>******Email Sample*****

>C U S T O M E R   R E C E I P T

>X O M XXR                                            Order Number: 175381
>America's Premier Value Merchant           Order Date: 4/4/2004
>84 Commercial Road                                Ship Via: FedEx
>Huntington, IN 46750                               Payment: MC
>800-348-5004
>Fax: 219-358-1806

>    Bill To:                                Ship To:
>           Steve xxxxx                             Rochelle Trom
>                       5xxx South xxxxxx xxx            Re: 000000000000
>                                                          1920 West 1 Street
>           xxxx Springs, xx xxxx              Superior, WI 54880
>            Telephone: (x1x)2x9-xxxx

>********End Sample************

yes, using gawk (gnu awk)

Here's one way:

gawk -F"  [ ] *" '$NF~"Order Number" {number=$NF}
              $NF~"Order Date" {date=$NF}
              $NF~"Re:" {ref=$NF;next}
              $NF~"Ship To" {tag=1;next}
              NF>1 && tag==1 {nameadd=nameadd $NF "\n"}
              END {print number
                   print date
                   sub(/:/, "f:", ref); print ref
                   print "Name and Address:"
                   print nameadd}' infile

Chuck Demas

--
  Eat Healthy        |   _ _   | Nothing would be done at all,

  Die Anyway         |    v    | That no one could find fault with it.

 
 
 

1. Can someone help me with setting up FreeBSD for pop3 e-mail in an IPX, netware WAN???

Please help, I have never used FreeBSD as a server before, it has always
been a workstation to me.  I currently am a Net Admin for a bank in Southern
CA, USA... I have read and read pop3 config in the complete FreeBSD, and the
man pages.  I need help configuring it for DHCP, and pop3 to serve my up and
coming tcp/ip conversion...  It's 3.3 by the way...

Edward Appel
(909) 715-4566 x.120

2. Advice wanted - linux as a PPP router

3. Someone know of a script 2 parse dhcpd.leases

4. KDevelop License

5. email address parsing routines

6. What could be simpler than old SCSI RAID?

7. Parsing Email Addresses (RFC822) with C

8. Problem with US Robotic Courier Modem

9. Questions about parsing email headers

10. Multi Domain E-mail parsing

11. Can you email my parse questions answer....

12. Parsing email addr to execute command

13. Parse file for e-mail addresses