about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-04-04 01:42:41 +0000
committerEric Wong <normalperson@yhbt.net>2014-04-05 06:55:35 +0000
commit1397205077a2b2d196f6c469a15a4a4721f1d15f (patch)
treeb8d5aa3c4cfa6370cae24c9e3fa94436d5bd983b
parent71abf270f5b11f147be839a9b057e106d0f8509f (diff)
downloadpublic-inbox-1397205077a2b2d196f6c469a15a4a4721f1d15f.tar.gz
We'll go with .html and .txt suffixes on MIDs to benefit
static hosting setups.
-rw-r--r--lib/PublicInbox/View.pm26
-rw-r--r--t/view.t6
2 files changed, 22 insertions, 10 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 125fcd62..08849a92 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -60,6 +60,15 @@ sub add_filename_line {
         "$pad " . escapeHTML($fn) . " $pad\n";
 }
 
+sub trim_message_id {
+        my ($mid) = @_;
+        $mid =~ tr/<>//d;
+        my $html = escapeHTML($mid);
+        my $href = escapeHTML(escape($mid));
+
+        ($html, $href);
+}
+
 sub headers_to_html_header {
         my ($simple) = @_;
 
@@ -79,15 +88,18 @@ sub headers_to_html_header {
                 }
         }
 
-        foreach my $h (qw(Message-ID In-Reply-To)) {
-                my $v = $simple->header($h);
-                defined $v or next;
-                $v =~ tr/<>//d;
-                my $html = escapeHTML($v);
-                my $href = escapeHTML(escape($v));
-                $rv .= "$h: <a href=\"$href\">$html</a>\n";
+        my $mid = $simple->header('Message-ID');
+        if (defined $mid) {
+                my ($html, $href) = trim_message_id($mid);
+                $rv .= "Message-ID: <a href=$href.html>$html</a> ";
+                $rv .= "(<a href=$href.txt>raw message</a>)\n";
         }
 
+        my $irp = $simple->header('In-Reply-To');
+        if (defined $irp) {
+                my ($html, $href) = trim_message_id($irp);
+                $rv .= "In-Reply-To: <a href=$href.html>$html</a>\n";
+        }
         $rv .= "\n";
 
         return ("<html><head><title>".
diff --git a/t/view.t b/t/view.t
index 93372d16..df79bd49 100644
--- a/t/view.t
+++ b/t/view.t
@@ -22,7 +22,7 @@ use PublicInbox::View;
         my $html = PublicInbox::View->as_html($s);
 
         # ghetto
-        like($html, qr/<a href="hello%40/s, "MID link present");
+        like($html, qr/<a href="?hello%40/s, "MID link present");
         like($html, qr/hello world\b/, "body present");
 }
 
@@ -42,8 +42,8 @@ use PublicInbox::View;
                 header_str => [
                         From => 'a@example.com',
                         Subject => 'blargh',
-                        'Message-ID' => '<blah@xeample.com>',
-                        'In-Reply-To' => '<irp@xeample.com>',
+                        'Message-ID' => '<blah@example.com>',
+                        'In-Reply-To' => '<irp@example.com>',
                         ],
                 parts => $parts,
         );