7 mail-extract-raw-headers - Get named headers from RFC822-format input.
11 mail-extract-raw-headers [OPTIONS] <NAME> [<NAME> [...]]
17 =item -k, --keep-newlines, --keep-linefeeds
19 Keep linefeeds in multiline text.
21 =item -n, --header-names
23 Output the header name(s) too, not only the contents.
30 use Getopt
::Long qw
/:config no_ignore_case bundling no_getopt_compat/;
33 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
39 'k|keep-newlines|keep-linefeeds' => \
$OptKeepLF,
40 'n|header-names' => \
$OptNames,
41 'help|?' => sub { pod2usage
(-exitval
=>0, -verbose
=>99); },
42 ) or pod2usage
(-exitval
=>2, -verbose
=>99);
46 pod2usage
(-exitval
=>2, -verbose
=>99);
49 @asked_headers = map {lc} @ARGV;
57 for my $hdr_ref (@Headers)
59 if(lc $hdr_ref->{"name"} eq $hname)
61 push @return, $hdr_ref->{"content"};
78 # does not care line ending
81 if(my($hdr_name, $content) = /^(\S+?):[ ]?(.*)/)
83 if(lc $hdr_name ~~ @asked_headers)
85 my $hdr_name_pretty = $hdr_name;
86 $hdr_name_pretty =~ s/[^-]*/\L\u$&/g;
88 my $hdr_hash = { "name" => $hdr_name, "pretty_name" => $hdr_name_pretty, "content" => $content, };
89 push @found_headers, $hdr_hash;
90 $last_hdr_ref = $hdr_hash;
94 $last_hdr_ref = undef;
97 elsif(/^\s+(.*)/ and defined $last_hdr_ref)
99 # it is a folded header
100 $last_hdr_ref->{"content"} .= "\n" if $OptKeepLF;
101 $last_hdr_ref->{"content"} .= $1;
108 sprintf "%s: %s\n", $_->{'pretty_name'}, $_->{'content'};
112 sprintf "%s\n", $_->{'content'};