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 urlencode 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: $!";
26 # can't use tmppath because File::Temp checks whether /tmp exists.
27 unveil("/tmp", "rwc") or die "unveil /tmp: $!";
28 unveil(".", "r") or die "unveil .: $!";
30 # fattr for File::Temp
31 pledge("stdio rpath wpath cpath proc exec fattr") or die "pledge: $!";
35 my ($level, $fname, $mid, $date, $from, $subj) = parse;
37 $tid = $mid if $level == 0;
38 die "unknown tid" unless defined $tid;
40 my $dest = "$outdir/mail/$mid.html";
43 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
47 my ($pfh, $parts) = tempfile "/tmp/gotmark.parts.XXXXXXXXXX";
49 $ENV{'PARTS_PATH'} = $parts;
50 $ENV{'MESSAGE_ID'} = $mid;
51 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
52 or die "can't exec mshow: $!";
54 open(my $text, '>', "$outdir/text/$mid.txt")
55 or die "can't open $outdir/text/$mid.txt: $!";
61 # drop the (1 day ago) string
62 s/ \(.*\)// if /^Date:/;
68 thread_header $fh, $tid, $mid, \@hdrs;
77 # generate the listing for the exported parts
82 say $fh "<ul class='parts'>";
86 say $fh "</ul>" if $part_seen;
88 my $encmid = urlencode $mid;
89 my $enctid = urlencode $tid;
92 print $fh "<a href='/text/$encmid.txt'>Raw body</a>";
93 print $fh "<a href='/thread/$enctid.html#$encmid'>Thread</a>";