]> Sergey Matveev's repositories - public-inbox.git/commitdiff
extmsg: try to fixup common errors
authorEric Wong <e@80x24.org>
Tue, 8 Dec 2015 05:31:23 +0000 (05:31 +0000)
committerEric Wong <e@80x24.org>
Tue, 8 Dec 2015 05:31:23 +0000 (05:31 +0000)
Sometimes users (me :x) blindly append "raw" to a /t/ URL...

lib/PublicInbox/ExtMsg.pm

index 506804711fc0756b37da79d61b01f6bd7d9d0ad4..82f4c63dc5ddd8b19820b58bda131f87a535d68d 100644 (file)
@@ -96,6 +96,8 @@ sub ext_msg {
        eval { require PublicInbox::Msgmap };
        my $have_mm = $@ ? 0 : 1;
        if ($have_mm) {
+               my $tmp_mid = $mid;
+again:
                my $cgi = $ctx->{cgi};
                my $url = ref($cgi) eq 'CGI' ? $cgi->url(-base) . '/'
                                        : $cgi->base->as_string;
@@ -106,13 +108,18 @@ sub ext_msg {
                        my $mm = eval { PublicInbox::Msgmap->new($git_dir) };
 
                        $mm or next;
-                       if (my $res = $mm->mid_prefixes($mid)) {
+                       if (my $res = $mm->mid_prefixes($tmp_mid)) {
                                $n_partial += scalar(@$res);
                                $pfx->{res} = $res;
                                push @partial, $pfx;
                        }
                }
+               # fixup common errors:
+               if (!$n_partial && $tmp_mid =~ s,/[tTf],,) {
+                       goto again;
+               }
        }
+
        my $code = 404;
        my $h = PublicInbox::Hval->new_msgid($mid, 1);
        my $href = $h->as_href;