3 # mexp was written by Omar Polo <op@openbsd.org> and is placed in the
4 # public domain. The author hereby disclaims copyright to this source
7 use open ":std", ":encoding(UTF-8)";
12 use File::Temp qw(tempfile);
18 use GotMArc qw(parse san initpage endpage thread_header);
20 my $outdir = $ENV{'OUTDIR'};
21 die 'Set $OUTDIR' unless defined $outdir;
23 unveil("/usr/local/bin/mshow", "rx") or die "unveil mshow: $!";
24 unveil($outdir, "rwc") or die "unveil $outdir: $!";
25 unveil("/tmp", "rwc") or die "unveil /tmp: $!";
26 unveil(".", "r") or die "unveil .: $!";
28 # fattr because of File::Temp somehow.
29 pledge("stdio rpath wpath cpath proc exec fattr") or die "pledge: $!";
33 my ($level, $fname, $mid, $date, $from, $subj) = parse;
35 $tid = $mid if $level == 0;
36 die "unknown tid" unless defined $tid;
38 my $dest = "$outdir/mail/$mid.html";
41 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
45 my ($pfh, $parts) = tempfile "/tmp/gotmark.parts.XXXXXXXXXX";
47 $ENV{'PARTS_PATH'} = $parts;
48 $ENV{'MESSAGE_ID'} = $mid;
49 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
50 or die "can't exec mshow: $!";
52 open(my $text, '>', "$outdir/text/$mid.txt")
53 or die "can't open $outdir/text/$mid.txt: $!";
59 # drop the (1 day ago) string
60 s/ \(.*\)// if /^Date:/;
66 thread_header $fh, $tid, $mid, \@hdrs;
75 # generate the listing for the exported parts
80 say $fh "<ul class='parts'>";
84 say $fh "</ul>" if $part_seen;
87 print $fh "<a href='/text/$mid.txt'>Raw body</a>";
88 print $fh "<a href='/thread/$tid.html#$mid'>Thread</a>";