CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Parsing email with an OR?

 



yim11
Novice

Aug 8, 2000, 10:19 PM

Post #1 of 1 (489 views)
Parsing email with an OR? Can't Post

Hello,
I have a perl script that looks at a users mailbox (var/spool/mail/USERNAME) and takes a message extracts the To, From, CC, BCC, Subject, and Message out and enters them as a comments in a database. The script looks for the email address in the To field by extracting everything between qoutes (" ").
Which works great for email sent from Lotus Notes [4.6] as that is the format Notes uses. Unfortunatly, MS Outlook does not use quotes in that field. So all email sent from Outlook is ignored. What I am looking for is any help that will allow me to change the script to look for quotes OR anything after FROM: so that all email will be processed the same. I have included the section of script I am referring to at the bottom of this post. Thanks VERY much in advance for any and all help on this. It has been a huge source of frustration for me and the company I work for.
TIA!
-Jim
---Begin Code Section---
foreach(@mbox) {
foreach(@$_) {
if ($current_key eq "contents") {
if ($_=~m"Content-Disposition: attachment") {
$bad=1;
}
if (!$bad) {
if (exists($message{$current_key})) {
$message{$current_key}="$message{$current_key} $_";
} else {
$message{$current_key}=$_;
}
}
} else {
@pieces=split(': ',$_,2);
if ($pieces[1] ne "") { # Is this a unique entry or a continuation of the previous
$current_key=$pieces[0];
if (($current_key eq "Content-Type") | | ($current_key eq "Content-Disposition") ) {
$current_key="contents";
}
chomp($pieces[1]);
if (exists($message{$current_key})) {
$message{$current_key} = "$message{$current_key} $pieces[1]";
} else {
$message{$current_key}="$pieces[1]";
}
} else {
chomp($pieces[0]);
if (($current_key eq "To")| |($current_key eq "cc")| |($current_key eq "Subject")) {
$result=($pieces[0]=~s" ""g);
}
if (exists($message{$current_key})) {
$message{$current_key} = "$message{$current_key} $pieces[0]";
} else {
$message{$current_key}="$pieces[0]";
}
}
}
}

# We need to remove the extraneous information from the addressing fields
@tmp=split('"',$message{'From'});
$message{'From'}=$tmp[1];

if ($message{'To'}=~m"<") {
@tmp=split(',',$message{'To'});

foreach(@tmp) {
@tmp2=split('<',$_,2);
@tmp3=split('>',$tmp2[1],2);
$_=@tmp3[0];
}
$message{'To'}=join(',',@tmp);
}
if ($message{'cc'}) {
@tmp=split(',',$message{'cc'});
foreach(@tmp) {
@tmp2=split('<',$_,2);
@tmp3=split('>',$tmp2[1],2);
$_=@tmp3[0];
}
$message{'cc'}=join(',',@tmp);
} else {
$message{'cc'}=" ";
}
# Date needs to be corrected to the dd-Mon-yyyy format
$result=($message{'Date'}=~s"([0-9]) (...) ([0-9])"$1-$2-$3");
@tmp=split(' ',$message{'Date'});
$message{'Date'}=$tmp[1];
# Contents and subject must be escaped
$result=($message{'Subject'}=~s"'"''"g);
$result=($message{'Subject'}=~s"`"``"g);
$result=($message{'contents'}=~s"'"''"g);
$result=($message{'contents'}=~s"`"``"g);
$result=($message{'contents'}=~s"\\"\\\\"g);
@tmp=split(' ',$message{'Subject'});
$catno="";
foreach(@tmp) {
if ($_=~m"[0-9]-") {
$catno=$_;
}
}

$sent=$message{'Date'};
$subject=$message{'Subject'};
$whofrom=$message{'From'};
$sendto=$message{'To'};
$cc=$message{'cc'};
$contents=$message{'contents'};
---End Code Section---

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives