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>"
110 foreach my $entry (@entries) {
111 my ($k, $v) = split /: /, $entry, 2;
113 say $fh "<dt>$k:</dt><dd>$v</dd>";
117 say $fh "<p>Download raw <a href='/text/$encmid.txt'>body</a>.</p>"
120 say $fh "</header>\n";
124 my ($fh, $type, $base, $last_level, $mail, $cur) = @_;
125 my $level = $mail->{level} - $base;
127 say $fh "</ul></li>" x ($last_level - $level) if $last_level > $level;
128 say $fh "<li><ul>" if $last_level < $level;
130 my $encmid = urlencode $mail->{mid};
132 print $fh "<li id='$encmid' class='mail'>";
133 print $fh "<p class='mail-meta'>";
134 print $fh "<time>$mail->{date}</time> ";
135 print $fh "<span class='from'>$mail->{from}</span>";
136 print $fh "<span class='colon'>:</span>";
138 print $fh "<p class='subject'>";
140 my $subj = $mail->{subj};
141 if (!defined($cur) || $mail->{mid} ne $cur->{mid}) {
142 print $fh "<a href='/$type/$encmid.html'>$subj</a>";
144 print $fh "<span>$subj</span>";