3 use open ":std", ":encoding(UTF-8)";
9 my $outdir = $ENV{'OUTDIR'};
10 die 'Set $OUTDIR' unless defined $outdir;
15 open my $fh, "<", "head.html"
16 or die "can't open head.html: $!";
22 open my $fh, "<", "foot.html"
23 or die "can't open foot.html: $!";
28 <img srcset='/got-tiny.png, /got-tiny@2x.png 2x'
30 alt='"GOT", but the "O" is a cute, smiling sun' />
42 my ($fname, $mid) = @_;
44 open(my $fh, ">", "$outdir/mbox/$mid.mbox")
45 or die "can't open $outdir/mbox/$mid.mbox: $!";
48 die "fork: $!" unless defined $pid;
50 open \*STDOUT, '>&', $fh;
51 exec('mexport', $fname)
52 or die "exec mexport: $!";
54 die "waitpid: $!" if waitpid($pid, 0) == -1;
55 die "mexport failed with $?" if $? != 0;
62 say; # continue the pipeline
64 m/^([^ ]+) <([^>]+)> (.+)(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) <([^>]+)> (.*)/;
65 die "can't parse: $_" unless defined $1;
66 my ($fname, $mid, $indent, $date, $from, $subj) = ($1, $2, $3, $4, $5, $6);
76 next if -f "$outdir/$mid.html";
78 my $level = length($indent) - 1;
79 $level = 10 if $indent =~ m/\.\.\d{2}\.\./;
81 $tid = $mid if $level == 0;
83 genmbox($fname, $mid);
85 my $dest = "$outdir/$mid.html";
86 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
88 say $fh $hdr =~ s/TITLE/$subj/r;
90 # prepare the parts listing file
91 $ENV{'MESSAGE_ID'} = $mid;
92 open(my $parts, '+>', "parts.html")
93 or die "can't create parts.html: $!";
95 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
96 or die "can't exec mshow: $!";
98 open(my $text, '>', "$outdir/text/$mid.txt")
99 or die "can't open $outdir/text/$mid.txt: $!";
101 print $fh "<header class='mail-header'>";
104 print $fh "<a href='/'>← Back to the index</a>";
106 print $fh "<a href='/thread/$tid.html#$mid'>→ go to the thread</a>.";
113 my ($h, $v) = m/^([-A-Za-z]+): (.*)/;
114 die "bogus line? $fname : $_" unless (defined $h and defined $v);
116 # drop the (1 day ago) string
117 $v =~ s/\(.*\)//g if ($h eq "Date");
119 print $fh "<dt>", san($h), ":</dt>";
120 print $fh "<dd>", san($v), "</dd>";
123 print $fh "<p>Raw <a href='/mbox/$mid.mbox'>message</a>";
124 print $fh " or <a href='/text/$mid.txt'>body</a>.</p>";
125 print $fh "</header>";
133 print $fh san($body // "");
138 # generate the listing for the exported parts
143 say $fh "<ul class='parts'>";
147 say $fh "</ul>" if $part_seen;