3 use open ":std", ":encoding(UTF-8)";
13 use GotMArc qw(parse san $logo 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: $!";
25 my ($level, $fname, $mid, $date, $from, $subj) = parse;
27 $tid = $mid if $level == 0;
28 die "unknown tid" unless defined $tid;
30 my $dest = "$outdir/mail/$mid.html";
33 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
37 # prepare the parts listing file
38 $ENV{'MESSAGE_ID'} = $mid;
39 open(my $parts, '+>', "parts.html")
40 or die "can't create parts.html: $!";
42 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
43 or die "can't exec mshow: $!";
45 open(my $text, '>', "$outdir/text/$mid.txt")
46 or die "can't open $outdir/text/$mid.txt: $!";
48 print $fh "<header class='mail-header'>";
51 print $fh "<a href='/'>Index</a>";
53 print $fh "<a href='/thread/$tid.html#$mid'>Thread</a>";
60 my ($h, $v) = m/^([-A-Za-z]+): (.*)/;
61 die "bogus line? $fname : $_" unless (defined $h and defined $v);
63 # drop the (1 day ago) string
64 $v =~ s/\(.*\)//g if ($h eq "Date");
66 print $fh "<dt>", san($h), ":</dt>";
67 print $fh "<dd>", san($v), "</dd>";
70 print $fh "<p>Download raw <a href='/text/$mid.txt'>body</a>.</p>";
71 print $fh "</header>";
80 # generate the listing for the exported parts
85 say $fh "<ul class='parts'>";
89 say $fh "</ul>" if $part_seen;