LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   perl extract email subject (https://www.linuxquestions.org/questions/linux-general-1/perl-extract-email-subject-476803/)

winchester169 08-23-2006 09:25 PM

perl extract email subject
 
How can I use Perl to extract the subject and body of emails. I have gotten this far but am stumped as what I am trying wont work in the script remodification.


#!/usr/bin/perl -w
#################################################################
use Mail::Header;
$messagefile = "/home/user/mail/cur/1156385158.M530962P31815V000000000
open(MESSAGE,"$messagefile") or
die "Unable to open $messagefile:$!\n";
$header = new Mail::Header \*MESSAGE;
close(MESSAGE);


print join("\n",sort $header->tags);


and modified (doesnt work)

#!/usr/bin/perl -w
#################################################################
use Mail::Header;
$messagefile = "/home/user/mail/cur/1156385158.M530962P31815V000000000
open(MESSAGE,"$messagefile") or
die "Unable to open $messagefile:$!\n";
$header = new Mail::Header \*MESSAGE;
$received = $header->get("Received");
$body = $header->get("Body");
close(MESSAGE);


print join("\n",sort $header->tags);
print $recived;
print $body;


I would actually like it to check for the existance of files, the names of mail files, extract the data and do something with it then delete the file.

Thank you

spirit receiver 08-24-2006 04:55 AM

Seems like Mail::Header doesn't care about the body at all. I suggest you use Email::Simple instead.


All times are GMT -5. The time now is 11:43 PM.