]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: update IRP and MID links
authorEric Wong <e@80x24.org>
Fri, 4 Apr 2014 01:42:41 +0000 (01:42 +0000)
committerEric Wong <normalperson@yhbt.net>
Sat, 5 Apr 2014 06:55:35 +0000 (06:55 +0000)
We'll go with .html and .txt suffixes on MIDs to benefit
static hosting setups.

lib/PublicInbox/View.pm
t/view.t

index 125fcd622bc15cfe389fcb6898cbb0f49c5b7961..08849a9207abc130c237c2a3e354fa49f41a3032 100644 (file)
@@ -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>".
index 93372d16ca227ef609845fac55425c1f98057e21..df79bd49cc66e842a0b01306a7d0b382f93b466b 100644 (file)
--- 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,
        );