3 use open ":std", ":encoding(UTF-8)";
8 use File::Temp qw(tempfile);
14 use GotMArc qw(parse san initpage endpage thread_header);
16 my $outdir = $ENV{'OUTDIR'};
17 die 'Set $OUTDIR' unless defined $outdir;
19 unveil("/usr/local/bin/mshow", "rx") or die "unveil mshow: $!";
20 unveil($outdir, "rwc") or die "unveil $outdir: $!";
21 unveil("/tmp", "rwc") or die "unveil /tmp: $!";
22 unveil(".", "r") or die "unveil .: $!";
24 # fattr because of File::Temp somehow.
25 pledge("stdio rpath wpath cpath proc exec fattr") or die "pledge: $!";
29 my ($level, $fname, $mid, $date, $from, $subj) = parse;
31 $tid = $mid if $level == 0;
32 die "unknown tid" unless defined $tid;
34 my $dest = "$outdir/mail/$mid.html";
37 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
41 my ($pfh, $parts) = tempfile "/tmp/gotmark.parts.XXXXXXXXXX";
43 $ENV{'PARTS_PATH'} = $parts;
44 $ENV{'MESSAGE_ID'} = $mid;
45 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
46 or die "can't exec mshow: $!";
48 open(my $text, '>', "$outdir/text/$mid.txt")
49 or die "can't open $outdir/text/$mid.txt: $!";
57 # drop the (1 day ago) string
58 s/\(.*\)// if /^Date:/;
62 thread_header $fh, $tid, $mid, \@hdrs;
71 # generate the listing for the exported parts
76 say $fh "<ul class='parts'>";
80 say $fh "</ul>" if $part_seen;