]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WWW.pm
view: support SHA-1 of Message-IDs for message links
[public-inbox.git] / lib / PublicInbox / WWW.pm
index f070433625623f1c5209824c87438a6dceee1a4a..1814286b5e7647e923e8d1d3376f94d062829510 100644 (file)
@@ -130,13 +130,19 @@ sub get_index {
 # just returns a string ref for the blob in the current ctx
 sub mid2blob {
        my ($ctx) = @_;
-       require Digest::SHA;
-       my $hex = Digest::SHA::sha1_hex($ctx->{mid});
-       $hex =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/i or
-                       die "BUG: not a SHA-1 hex: $hex";
+       my $hex = $ctx->{mid};
+       my ($x2, $x38) = ($hex =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/);
+
+       unless (defined $x38) {
+               # compatibility with old links
+               require Digest::SHA;
+               $hex = Digest::SHA::sha1_hex($hex);
+               ($x2, $x38) = ($hex =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/);
+               defined $x38 or die "BUG: not a SHA-1 hex: $hex";
+       }
 
        my @cmd = ('git', "--git-dir=$ctx->{git_dir}",
-                       qw(cat-file blob), "HEAD:$1/$2");
+                       qw(cat-file blob), "HEAD:$x2/$x38");
        my $cmd = join(' ', @cmd);
        my $pid = open my $fh, '-|';
        defined $pid or die "fork failed: $!\n";
@@ -181,7 +187,7 @@ sub get_full_html {
        require PublicInbox::View;
        require Email::MIME;
        my $foot = footer($ctx);
-       [ 200, [ 'Content-Type' => 'text/html' ],
+       [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
          [ PublicInbox::View->msg_html(Email::MIME->new($x), undef, $foot)] ];
 }
 
@@ -252,10 +258,10 @@ sub footer {
        if ($nurls == 0) {
                $urls = '($GIT_DIR/cloneurl missing)';
        } elsif ($nurls == 1) {
-               $urls = 'git archive URL for <a href="' . SSOMA_URL .
+               $urls = "git URL for <a\nhref=\"" . SSOMA_URL .
                        '">ssoma</a>: ' . $urls[0];
        } else {
-               $urls = 'git archive URLs for <a href="' . SSOMA_URL .
+               $urls = "git URLs for <a\nhref=\"" . SSOMA_URL .
                        "\">ssoma</a>:\n" . join("\n", map { "\t$_" } @urls);
        }
 
@@ -264,13 +270,13 @@ sub footer {
                $addr = $addr->[0]; # first address is primary
        }
 
-       $addr = "<a href=\"mailto:$addr\">$addr</a>";
+       $addr = "<a\nhref=\"mailto:$addr\">$addr</a>";
        $desc =  $desc;
        join("\n",
                '- ' . $desc,
-               'This is a <a href="' . PI_URL . '">public-inbox</a>, '.
-               "anybody may post:",
-               "\t$addr (text-only, no HTML please)",
+               "A <a\nhref=\"" . PI_URL .  '">public-inbox</a>, ' .
+                       'anybody may post in plain-text (not HTML):',
+               $addr,
                $urls
        );
 }