Commit Diff
Diff:
890362cd906d770a9ed8af92b2c281c113f9c18e
f0fb0f0898465906e605ce59cd2b31d1730d6d8c
Commit:
f0fb0f0898465906e605ce59cd2b31d1730d6d8c
Tree:
1a15a2f832c05e440c097588470e2b3474d2b8b4
Author:
Omar Polo <op@omarpolo.com>
Date:
Tue Aug 30 11:40:44 2022 UTC
Message:
urlencode the mail/thread id

reminded by semarie@, thanks!
commit - 890362cd906d770a9ed8af92b2c281c113f9c18e
commit + f0fb0f0898465906e605ce59cd2b31d1730d6d8c
blob - 81bae9be0eed05cdf1f2b61fbb63f7e88d4b908d
blob + 533da445bdd961874847d9785f922a37c475c766
--- GotMArc.pm
+++ GotMArc.pm
@@ -9,7 +9,7 @@ our @EXPORT_OK = qw(san parse initpage endpage index_h
use Exporter;
our @ISA = qw(Exporter);
-our @EXPORT_OK = qw(san parse initpage endpage index_header thread_header);
+our @EXPORT_OK = qw(san urlencode parse initpage endpage index_header thread_header);
sub san {
my $str = shift;
@@ -19,6 +19,16 @@ sub ssan {
return $str;
}
+sub urlencode {
+ my $str = shift;
+ unless (defined($str)) {
+ my ($pkg, $file, $line) = caller 1;
+ die "bad $pkg / $file:$line";
+ }
+ $str =~ s/([^-_~.A-Za-z0-9])/sprintf("%%%2X", ord($1))/ge;
+ return $str;
+}
+
sub ssan {
my $str = shift;
$str =~ s/\s+/ /g;
@@ -86,13 +96,16 @@ sub thread_header {
my ($fh, $tid, $mid, $e) = @_;
my @entries = @$e;
+ my $enctid = urlencode $tid if defined $tid;
+ my $encmid = urlencode $mid if defined $mid;
+
print $fh "<header class='mail-header'>\n";
print $fh "<p>";
print $fh $small_logo;
print $fh "<a href='/'>Index</a>";
- print $fh " | <a href='/thread/$tid.html#$mid'>Thread</a>"
- if defined $tid;
+ print $fh " | <a href='/thread/$enctid.html#$encmid'>Thread</a>"
+ if defined $enctid;
print $fh "</p>\n";
say $fh "<dl>";
@@ -103,8 +116,8 @@ sub thread_header {
}
say $fh "</dl>";
- say $fh "<p>Download raw <a href='/text/$mid.txt'>body</a>.</p>"
- if defined $mid;
+ say $fh "<p>Download raw <a href='/text/$encmid.txt'>body</a>.</p>"
+ if defined $encmid;
say $fh "</header>\n";
};
blob - acfd9974e463b664ad9b3ba61bb7ddf9d965338e
blob + 6b9c9f1df418f69a0e51538f76672171d03ab8c1
--- mexp
+++ mexp
@@ -15,7 +15,7 @@ use GotMArc qw(parse san initpage endpage thread_heade
use OpenBSD::Unveil;
use lib ".";
-use GotMArc qw(parse san initpage endpage thread_header);
+use GotMArc qw(parse san urlencode initpage endpage thread_header);
my $outdir = $ENV{'OUTDIR'};
die 'Set $OUTDIR' unless defined $outdir;
@@ -85,9 +85,12 @@ while (<>) {
}
say $fh "</ul>" if $part_seen;
+ my $encmid = urlencode $mid;
+ my $enctid = urlencode $tid;
+
print $fh "<nav>";
- print $fh "<a href='/text/$mid.txt'>Raw body</a>";
- print $fh "<a href='/thread/$tid.html#$mid'>Thread</a>";
+ print $fh "<a href='/text/$encmid.txt'>Raw body</a>";
+ print $fh "<a href='/thread/$enctid.html#$encmid'>Thread</a>";
print $fh "</nav>\n";
endpage $fh;
blob - ae10febaf5a5454f532b0b0556276cf7fe984f0c
blob + 23a471248e697b6a326de2aedfff857e105ee153
--- mkindex
+++ mkindex
@@ -15,7 +15,7 @@ use GotMArc qw(parse san initpage endpage index_header
use OpenBSD::Unveil;
use lib ".";
-use GotMArc qw(parse san initpage endpage index_header thread_header);
+use GotMArc qw(parse san urlencode initpage endpage index_header thread_header);
my $outdir = $ENV{'OUTDIR'};
die 'Set $OUTDIR' unless defined $outdir;
@@ -138,14 +138,16 @@ sub entry {
sub entry {
my ($fh, $type, $mid, $date, $from, $subj) = @_;
- print $fh "<li id='$mid' class='mail'>";
+ my $encmid = urlencode $mid;
+
+ print $fh "<li id='$encmid' class='mail'>";
print $fh "<p class='mail-meta'>";
print $fh "<time>$date</time> ";
print $fh "<span class='from'>$from</span>";
print $fh "<span class='colon'>:</span>";
print $fh "</p>";
print $fh "<p class='subject'>";
- print $fh "<a href='/$type/$mid.html'>$subj</a>";
+ print $fh "<a href='/$type/$encmid.html'>$subj</a>";
print $fh "</p>";
print $fh "</li>\n";
}
Omar Polo