3 use open ":std", ":encoding(UTF-8)";
10 use GotMArc qw(san $logo mid2path initpage endpage);
12 my $outdir = $ENV{'OUTDIR'};
13 die 'Set $OUTDIR' unless defined $outdir;
20 m/^([^ ]+) <([^>]+)> (.+)(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) <([^>]+)> (.*)/;
21 die "can't parse: $_" unless defined $1;
22 my ($fname, $mid, $indent, $date, $from, $subj) = ($1, $2, $3, $4, $5, $6);
27 $mid = mid2path($mid);
29 my $dest = "$outdir/mail/$mid.html";
32 my $level = length($indent) - 1;
33 $level = 10 if $indent =~ m/\.\.\d{2}\.\./;
35 $tid = $mid if $level == 0;
36 die "unknown tid" unless defined $tid;
38 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
42 # prepare the parts listing file
43 $ENV{'MESSAGE_ID'} = $mid;
44 open(my $parts, '+>', "parts.html")
45 or die "can't create parts.html: $!";
47 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
48 or die "can't exec mshow: $!";
50 open(my $text, '>', "$outdir/text/$mid.txt")
51 or die "can't open $outdir/text/$mid.txt: $!";
53 print $fh "<header class='mail-header'>";
56 print $fh "<a href='/'>Index</a>";
58 print $fh "<a href='/thread/$tid.html#$mid'>Thread</a>";
65 my ($h, $v) = m/^([-A-Za-z]+): (.*)/;
66 die "bogus line? $fname : $_" unless (defined $h and defined $v);
68 # drop the (1 day ago) string
69 $v =~ s/\(.*\)//g if ($h eq "Date");
71 print $fh "<dt>", san($h), ":</dt>";
72 print $fh "<dd>", san($v), "</dd>";
75 print $fh "<p>Download raw <a href='/text/$mid.txt'>body</a>.</p>";
76 print $fh "</header>";
85 # generate the listing for the exported parts
90 say $fh "<ul class='parts'>";
94 say $fh "</ul>" if $part_seen;