in reply to Re: Parsing email for headers
in thread Parsing email for headers
Well, to answer some of my own questions :
1. MIME::Parser is way too heavy for this purpose. If you have to call $parser->filer->purge(); to delete all the files created from each of the mails. This really seems too much to "just read 4 fields from an email header".
MIME::Head however seems to fit the bill very well :
my $head = MIME::Head->read( \*FILE ); # TODO : Does it read the WHOLE + email or skips the remaining mail after reading the header? $head->unfold; # Was a "Subject:" field given? # $subject_was_given = $head->count('subject'); print $head->get('subject'); print $head->get('Message-ID'); print $head->get('from'); print $head->get('date');
2. I would appreciate some answers to this.
Of course missing id's will be logged and error handling done, but I was wondering if there are any servers with such known behaviour.
3. This works just dandy :
use Date::Manip; Date_Init("ConvTZ=IGNORE","TZ=GMT"); my $date = UnixDate( $head->get('date') , '%Y_%m_%Q-%H%M%S'); print $date;
This can convert, for eg : "Sat, 9 Feb 2008 17:04:08 EET" to "2008_02_20080209-170408"
Thanks guys for the great insights! Furthur tips/tricks/etc are welcome though.
|
|---|