Blob


1 #!/usr/bin/env perl
3 use open ":std", ":encoding(UTF-8)";
4 use utf8;
5 use strict;
6 use warnings;
7 use v5.32;
9 use lib ".";
10 use GotMArc qw(san $logo mid2path initpage endpage);
12 my $outdir = $ENV{'OUTDIR'};
13 die 'Set $OUTDIR' unless defined $outdir;
14 mkdir $outdir;
16 my $tid;
17 while (<>) {
18 chomp;
20 m/^([^ ]+) <([^>]+)> (.+)(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) <([^>]+)> (.*)/;
21 die "can't parse: $_" unless defined $1;
22 my ($fname, $mid, $indent, $date, $from, $subj) = ($1, $2, $3, $4, $5, $6);
23 $subj = san($subj);
24 $subj =~ s/\s+/ /g;
25 $subj =~ s/\s+$//;
27 $mid = mid2path($mid);
29 my $dest = "$outdir/mail/$mid.html";
30 next if -f $dest;
32 my $level = length($indent) - 1;
33 $level = 10 if $indent =~ m/\.\.\d{2}\.\./;
35 $tid = $mid if $level == 0;
36 die "unknown tid" unless defined $tid;
38 open(my $fh, '>', "$dest") or die "can't open $dest: $!";
40 initpage $fh, $subj;
42 # prepare the parts listing file
43 $ENV{'MESSAGE_ID'} = $mid;
44 open(my $parts, '+>', "parts.html")
45 or die "can't create parts.html: $!";
47 open(my $mshow, "-|", "mshow", "-nNA", "text/plain", $fname)
48 or die "can't exec mshow: $!";
50 open(my $text, '>', "$outdir/text/$mid.txt")
51 or die "can't open $outdir/text/$mid.txt: $!";
53 print $fh "<header class='mail-header'>";
54 print $fh "<p>";
55 print $fh $logo;
56 print $fh "<a href='/'>Index</a>";
57 print $fh " | ";
58 print $fh "<a href='/thread/$tid.html#$mid'>Thread</a>";
59 print $fh "</p>";
60 print $fh "<dl>";
61 while (<$mshow>) {
62 chomp;
63 say $text $_;
64 last if /^$/;
65 my ($h, $v) = m/^([-A-Za-z]+): (.*)/;
66 die "bogus line? $fname : $_" unless (defined $h and defined $v);
68 # drop the (1 day ago) string
69 $v =~ s/\(.*\)//g if ($h eq "Date");
71 print $fh "<dt>", san($h), ":</dt>";
72 print $fh "<dd>", san($v), "</dd>";
73 }
74 print $fh "</dl>";
75 print $fh "<p>Download raw <a href='/text/$mid.txt'>body</a>.</p>";
76 print $fh "</header>";
78 print $fh "<pre>";
79 while (<$mshow>) {
80 print $text $_;
81 print $fh san($_);
82 }
83 print $fh "</pre>";
85 # generate the listing for the exported parts
86 my $part_seen = 0;
87 while (<$parts>) {
88 if (!$part_seen) {
89 $part_seen = 1;
90 say $fh "<ul class='parts'>";
91 }
92 print $fh $_;
93 }
94 say $fh "</ul>" if $part_seen;
96 endpage $fh;
98 close($text);
99 close($mshow);
100 close($parts);
101 close($fh);
104 unlink "parts.html";