my $email = Email::Simple->new($text); my $header = $email->header_obj; print $header->as_string;
Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.
my $header = Email::Simple::Header->new($head, \%arg);
$head is a string containing a valid email header, or a reference to such a string. If a reference is passed in, don't expect that it won't be altered.
Valid arguments are:
crlf - the header's newline; defaults to CRLF
my $string = $header->as_string(\%arg);
This returns a stringified version of the header.
my @pairs = $header->header_raw_pairs; my $first_name = $pairs[0]; my $first_value = $pairs[1];
This method returns a list of all the field/value pairs in the header, in the order that they appear in the header. (Remember: don't try assigning that to a hash. Some fields may appear more than once!)
my $first_value = $header->header_raw($field); my $nth_value = $header->header_raw($field, $index); my @all_values = $header->header_raw($field);
This method returns the value or values of the given header field. If the named field does not appear in the header, this method returns false.
$header->header_raw_set($field => @values);
This method updates the value of the given header. Existing headers have their values set in place. Additional headers are added at the end. If no values are given to set, the header will be removed from to the message entirely.
$header->header_raw_prepend($field => $value);
This method adds a new instance of the name field as the first field in the header.
$header->header_rename($field, $new_name, $nth);
This renames the named field to the new name. If $nth is given, only the nth instance of the field will be renamed. It is fatal to rename an instance that does not exist. The first instance of a header is the 0th.
If $nth is omitted, all instances of the header are renamed.
When picking headers to rename, $field is matched case insensitively. So, given this header:
happythoughts: yes HappyThoughts: so many hapPyThouGhts: forever
Then this code...
$header->rename_header('happythoughts', 'Delights');
...will result in this:
Delights: yes Delights: so many Delights: forever
Headers may be rewrapped as a result of renaming.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.