Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How do I parse a mail header?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:32 UTC ( #769=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

For a quick-and-dirty solution, try this solution derived from page 222 of the 2nd edition of ``Programming Perl'':

    $/ = '';
    $header = <MSG>;
    $header =~ s/\n\s+/ /g;      # merge continuation lines
    %head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header );

That solution doesn't do well if, for example, you're trying to maintain all the Received lines. A more complete approach is to use the Mail::Header module from CPAN (part of the MailTools package).

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[1nickt]: marto all good after the hurricane?

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2017-10-17 10:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (225 votes). Check out past polls.

    Notices?