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

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.

Replies are listed 'Best First'.
Re: Mail::Message and Mail::Field
by Anonymous Monk on Nov 13, 2008 at 15:46 UTC
Re: Mail::Message and Mail::Field
by Anonymous Monk on Nov 13, 2008 at 14:35 UTC
      What is missing? I can't post data without sanitizing it and by then it will be useless as data.
        So where are we supposed to get sample data?