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 width='64' height='39'
31 alt='"GOT", but the "O" is a cute, smiling sun' />
43 my ($fname, $mid) = @_;
45 open(my $fh, ">", "$outdir/mbox/$mid.mbox")
46 or die "can't open $outdir/mbox/$mid.mbox: $!";
49 die "fork: $!" unless defined $pid;
51 open \*STDOUT, '>&', $fh;
52 exec('mexport', $fname)
53 or die "exec mexport: $!";
55 die "waitpid: $!" if waitpid($pid, 0) == -1;
56 die "mexport failed with $?" if $? != 0;
63 say; # continue the pipeline
65 m/^([^ ]+) <([^>]+)> (.+)(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) <([^>]+)> (.*)/;
66 die "can't parse: $_" unless defined $1;
67 my ($fname, $mid, $indent, $date, $from, $subj) = ($1, $2, $3, $4, $5, $6);
77 my $dest = "$outdir/mail/$mid.html";
80 my $level = length($indent) - 1;
81 $level = 10 if $indent =~ m/\.\.\d{2}\.\./;
83 $tid = $mid if $level == 0;
85 genmbox($fname, $mid);
87 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
89 say $fh $hdr =~ s/TITLE/$subj/r;
91 # prepare the parts listing file
92 $ENV{'MESSAGE_ID'} = $mid;
93 open(my $parts, '+>', "parts.html")
94 or die "can't create parts.html: $!";
96 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
97 or die "can't exec mshow: $!";
99 open(my $text, '>', "$outdir/text/$mid.txt")
100 or die "can't open $outdir/text/$mid.txt: $!";
102 print $fh "<header class='mail-header'>";
105 print $fh "<a href='/'>← Back to the index</a>";
107 print $fh "<a href='/thread/$tid.html#$mid'>→ go to the thread</a>.";
114 my ($h, $v) = m/^([-A-Za-z]+): (.*)/;
115 die "bogus line? $fname : $_" unless (defined $h and defined $v);
117 # drop the (1 day ago) string
118 $v =~ s/\(.*\)//g if ($h eq "Date");
120 print $fh "<dt>", san($h), ":</dt>";
121 print $fh "<dd>", san($v), "</dd>";
124 print $fh "<p>Raw <a href='/mbox/$mid.mbox'>message</a>";
125 print $fh " or <a href='/text/$mid.txt'>body</a>.</p>";
126 print $fh "</header>";
134 print $fh san($body // "");
139 # generate the listing for the exported parts
144 say $fh "<ul class='parts'>";
148 say $fh "</ul>" if $part_seen;