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' />
44 say; # continue the pipeline
46 m/^([^ ]+) <([^>]+)> (.+)(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) <([^>]+)> (.*)/;
47 die "can't parse: $_" unless defined $1;
48 my ($fname, $mid, $indent, $date, $from, $subj) = ($1, $2, $3, $4, $5, $6);
58 next if -f "$outdir/$mid.html";
60 my $level = length($indent) - 1;
61 $level = 10 if $indent =~ m/\.\.\d{2}\.\./;
63 $tid = $mid if $level == 0;
65 my $dest = "$outdir/$mid.html";
66 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
68 say $fh $hdr =~ s/TITLE/$subj/r;
70 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
71 or die "can't exec mshow: $!";
73 print $fh "<header class='mail-header'>";
76 print $fh "<a href='/'>← Back to the index</a>";
78 print $fh "<a href='/thread/$tid.html#$mid'>→ go to the thread</a>.";
84 my ($h, $v) = m/^([-A-Za-z]+): (.*)/;
85 die "bogus line? $fname : $_" unless (defined $h and defined $v);
87 # drop the (1 day ago) string
88 $v =~ s/\(.*\)//g if ($h eq "Date");
90 print $fh "<dt>", san($h), ":</dt>";
91 print $fh "<dd>", san($v), "</dd>";
93 print $fh "</dl></header>";
101 # print $fh san($_) while <>;
102 print $fh san($body // "");