1 # GotMArc was written by Omar Polo <op@openbsd.org> and is placed in
2 # the public domain. The author hereby disclaims copyright to this
12 our @ISA = qw(Exporter);
13 our @EXPORT_OK = qw(san urlencode parse initpage endpage index_header
14 thread_header threntry);
26 unless (defined($str)) {
27 my ($pkg, $file, $line) = caller 1;
28 die "bad $pkg / $file:$line";
30 $str =~ s/([^-_~.A-Za-z0-9])/sprintf("%%%2X", ord($1))/ge;
43 my ($indent, $fname, $date, $from, $subj) = $line =~ m{
44 ^([^-]*)- # the indent level
46 (\d{4}-\d\d-\d\d[ ]\d\d:\d\d) # date
49 }x or die "can't parse: $line";
51 my $level = length($indent);
52 $level = 10 if $indent =~ m/\.\.\d+\.\./;
57 my ($time, $id) = split /\./, basename($fname);
58 my $mid = "$time.$id";
60 return {level => $level, fname => $fname,
61 mid => $mid, date => $date, from => $from, subj => $subj};
67 open my $fh, "<", $path or die "can't open $path: $!";
71 my $small_logo = readall "logo-small.html";
72 my $hdr = readall "head.html";
73 my $foot = readall "foot.html";
74 my $idxhdr = readall "index-header.html";
77 my ($fh, $title) = @_;
78 say $fh $hdr =~ s/TITLE/$title/r;
87 my ($fh, $page, $subtitle) = @_;
88 my $html = $idxhdr =~ s/PAGE/$page/r;
89 $html =~ s/SUBTITLE/$subtitle/;
94 my ($fh, $tid, $mid, $e) = @_;
97 my $enctid = urlencode $tid if defined $tid;
98 my $encmid = urlencode $mid if defined $mid;
100 print $fh "<header class='mail-header'>\n";
103 print $fh $small_logo;
104 print $fh "<a href='/'>Index</a>";
105 print $fh " | <a href='/thread/$enctid.html#$encmid'>Thread</a>"
107 print $fh " | <a href='/search'>Search</a>";
111 foreach my $entry (@entries) {
112 my ($k, $v) = split /: /, $entry, 2;
114 say $fh "<dt>$k:</dt><dd>$v</dd>";
118 say $fh "<p>Download raw <a href='/text/$encmid.txt'>body</a>.</p>"
121 say $fh "</header>\n";
125 my ($fh, $type, $base, $last_level, $mail, $cur) = @_;
126 my $level = $mail->{level} - $base;
128 say $fh "</ul></li>" x ($last_level - $level) if $last_level > $level;
129 say $fh "<li><ul>" if $last_level < $level;
131 my $encmid = urlencode $mail->{mid};
133 print $fh "<li id='$encmid' class='mail'>";
134 print $fh "<p class='mail-meta'>";
135 print $fh "<time>$mail->{date}</time> ";
136 print $fh "<span class='from'>$mail->{from}</span>";
137 print $fh "<span class='colon'>:</span>";
139 print $fh "<p class='subject'>";
141 my $subj = $mail->{subj};
142 if (!defined($cur) || $mail->{mid} ne $cur->{mid}) {
143 print $fh "<a href='/$type/$encmid.html'>$subj</a>";
145 print $fh "<span>$subj</span>";