3 use open ":std", ":encoding(UTF-8)";
13 use GotMArc qw(san $logo mid2path initpage endpage);
15 my $outdir = $ENV{'OUTDIR'};
16 die 'Set $OUTDIR' unless defined $outdir;
18 unveil("/usr/local/bin/mshow", "rx") or die "unveil mshow: $!";
19 unveil($outdir, "rwc") or die "unveil $outdir: $!";
20 unveil(".", "rwc") or die "unveil .: $!";
21 pledge("stdio rpath wpath cpath proc exec") or die "pledge: $!";
27 m/^([^ ]+) <([^>]+)> (.+)(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) <([^>]+)> (.*)/;
28 die "can't parse: $_" unless defined $1;
29 my ($fname, $mid, $indent, $date, $from, $subj) = ($1, $2, $3, $4, $5, $6);
34 $mid = mid2path($mid);
36 my $level = length($indent) - 1;
37 $level = 10 if $indent =~ m/\.\.\d{2}\.\./;
39 $tid = $mid if $level == 0;
40 die "unknown tid" unless defined $tid;
42 my $dest = "$outdir/mail/$mid.html";
45 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
49 # prepare the parts listing file
50 $ENV{'MESSAGE_ID'} = $mid;
51 open(my $parts, '+>', "parts.html")
52 or die "can't create parts.html: $!";
54 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
55 or die "can't exec mshow: $!";
57 open(my $text, '>', "$outdir/text/$mid.txt")
58 or die "can't open $outdir/text/$mid.txt: $!";
60 print $fh "<header class='mail-header'>";
63 print $fh "<a href='/'>Index</a>";
65 print $fh "<a href='/thread/$tid.html#$mid'>Thread</a>";
72 my ($h, $v) = m/^([-A-Za-z]+): (.*)/;
73 die "bogus line? $fname : $_" unless (defined $h and defined $v);
75 # drop the (1 day ago) string
76 $v =~ s/\(.*\)//g if ($h eq "Date");
78 print $fh "<dt>", san($h), ":</dt>";
79 print $fh "<dd>", san($v), "</dd>";
82 print $fh "<p>Download raw <a href='/text/$mid.txt'>body</a>.</p>";
83 print $fh "</header>";
92 # generate the listing for the exported parts
97 say $fh "<ul class='parts'>";
101 say $fh "</ul>" if $part_seen;