output asked headers in the order they were asked; avoid header name spoofing by...
[hband-tools.git] / user-tools / mime-header-decode
blob353f430b0ebe01c1d994c4aa4a36d6876af6f983
1 #!/usr/bin/env perl
3 =pod
5 =head1 NAME
7 mime-header-decode - Decode MIME-encoded stream on stdin line-by-line
9 =cut
12 use Encode;
13 while(<STDIN>)
15 chomp;
16 my $header = decode("MIME-Header", $_);
17 # avoid non-whitespace character at the beginning of lines in the header content,
18 # so header names can not be spoofed.
19 $safe_header = $header =~ s/\n(?![\t ])/\n /gr;
20 # all-whitespace lines are not always taken correctly by downstream programs,
21 # and should not have meaning in themself, so remove.
22 $safe_header =~ s/^\s*\n//gm;
23 chomp $safe_header;
24 print encode("UTF-8", $safe_header) . "\n";