Data::Header::Fields - encode and decode RFC822 header field lines
use IO::Any; my $email_msg = IO::Any->slurp([ 'path', 'to', 'email.eml' ]); my ($email_header, $email_body) = split(/^\s*$/m, $email_msg, 2); use Data::Header::Fields; my $dhf = Data::Header::Fields->new->decode(\$email_header); print 'From - ', $dhf->get_value('From'), "\n"; print 'Subject - ', $dhf->get_value('Subject'), "\n"; print 'Date - ', $dhf->get_value('Date'), "\n"; print '--- cut ---', "\n"; $dhf->set_value('To' => ' anyone@anywhere'); $dhf->rm_fields('Received'); print $dhf->encode();
experimental, use on your own risk :-)
RFC822 - Standard for ARPA Internet Text Messages (http://tools.ietf.org/html/rfc822#section-3.2) describes the format of header lines used in emails. The tricky part is the line folding.
There are some "forks" of this standard. One of them is Debian RFC-2822-like fields and the other is RFC2425 that defines the so called vCard format. Data::Header::Fields is generic enough to serve as a base class to parse those as well.
One of the main goals of the module is to be able to edit the headers while keeping the lines that were not changed untouched.
For the moment this is all documentation. After more tests with vCards and using this module for the basic parsing in Parse::Deb::Control it will be stable enough.
Currently this distribution is highly radioactive!
http://tools.ietf.org/html/rfc2822 - Internet Message Format