rhxk has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, My objective is to read newly incoming emails, parse them by to,from,subject,body
and store them in a dbase. I've installed a local copy of Mail::Audit to my
home dir but it seems to have problems reading MIME emails.

If I send an email to my account via my linux /bin/mail, all is OK.
However, if I use my Thunderbird,www.yahoo.com, to send emails
then I get only the body...headers are cut off.

Here's my .forward:
|/home/rob/bin/forward_email

Here's my forward_email:
#!/usr/bin/perl BEGIN{ unshift @INC, '/home/rob/lib/perl5/site_perl/5.8.3'; unshift @INC, '/home/rob/lib/perl5/5.8.3' } $\ = "\n"; select(STDERR); $| = 1; select(STDOUT); $| = 1; use warnings; use Mail::Audit; $mail = Mail::Audit->new(emergency=>"/home/rob/emergency_mbox",log= +>"/home/rob/audit.log",loglevel=>4); $from = $mail->from; $to = $mail->to; $subject = $mail->subject; @body = @{$mail->body}; #chomp($from, $to, $subject); open(FILE, ">> /home/rob/mynewmail.log"); print FILE "from is $from"; print FILE "to is $to"; print FILE "subj is $subject"; print FILE "body is @body"; close(FILE);
All it prints in mynewmail.log is:
from is to is subj is body is &lt the body is here &gt
But interestingly, it prints the true headers in the audit.log
file regardless if it's a MIME message or not. --what do you guys think? --

Replies are listed 'Best First'.
Re: parsing email by Mail::Audit
by Zed_Lopez (Chaplain) on Oct 31, 2005 at 23:48 UTC

    I think I'd like to see the actual raw text of the email from your audit log.

    If you read this article, you'll see that the original author of Mail::Audit now endorses Email::Filter for the purpose.

      Here's the audit.log file:

      The 1st ---new worked fine, but the next 2 didn't.

      But I will read your links and perhaps take that approach...thanx a million!

      --Rob
      161(new): ------------------------------ new run at Mon Oct 31 17:40:20 2005
      
      165(new):    From: Robert Khachikyan <robert@domainname.com>
      
      166(new):      To: rob@destination.com
      
      167(new): Subject: habib "hello"testing
      
      161(new): ------------------------------ new run at Mon Oct 31 17:41:53 2005
      
      165(new):    From: Robert Khachikyan <rhxkrhxk@gmail.com>
      
      166(new):      To: rob@destination.com
      
      167(new): Subject: accent
      
      174(new): message is MIME.  MIME-Version is 1.0
      
      161(new): ------------------------------ new run at Mon Oct 31 17:44:34 2005
      
      165(new):    From: Robert Khachikyan <rhxk@yahoo.com>
      
      166(new):      To: rob@destination.com
      
      167(new): Subject: jan artur
      
      174(new): message is MIME.  MIME-Version is 1.0