I am writing a script where I need to parse email source and in particular I need to process 'received' headers. My script successfully extracts all the 'received' headers using Mail::Message. However, the only module I can find that supposedly parses those headers is Mail::Field::Received. Mail::Field seems to want to read the email itself but Mail::Message has already done that. Not being a perl guru I can only guess that in spite of the documentation that says Mail::Field::Received should not be used directly, doing so is the way to accomplish what I want. Basically, how do I pass the received header from Mail::Message to Mail::Field::Received without Mail::Field re-reading the message source? That is, is the structure of the headers from Mail::Message compatible with what Mail::Field::Received wants to parse? TIA.
#!/usr/bin/perl -w
use strict;
use Mail::Message;
use Mail::Field;
use Data::Dumper;
my $msg=Mail::Message->read(\*STDIN);
my $head=$msg->head();
my $from=$msg->from;
my @to=$msg->to;
my @subject=$msg->subject;
my @recv=$head->get('received');
foreach my $recv_item (@recv) {
# I need to create an array of hashes, each of which
# contains a parsed 'received' header
}
I think there is also a monkey wrench in here as the headers can wrap, according to the documentation. I think that means a single received header can wind up in 2 array items. That will be another can of worms but I will be happy for now just being able to parse the non-wrapped headers.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.