]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
www: /$INBOX/$MSGID/d/ to diff reused Message-IDs
[public-inbox.git] / lib / PublicInbox / View.pm
index 0753c06ee4f81b4a4494ab05210b6bc60e71073a..b8d6d85e77470737d4200718c4771d540dd08618 100644 (file)
@@ -80,6 +80,7 @@ sub msg_page {
        # allow user to easily browse the range around this message if
        # they have ->over
        $ctx->{-t_max} = $smsg->{ts};
+       $ctx->{-spfx} = '../' if $ibx->{coderepo};
        PublicInbox::WwwStream::aresponse($ctx, \&msg_page_i);
 }
 
@@ -386,7 +387,8 @@ sub thread_eml_entry {
        my ($ctx, $eml) = @_;
        my ($beg, $end) = thread_adj_level($ctx, $ctx->{level});
        print { $ctx->zfh } $beg, '<pre>';
-       print { $ctx->{zfh} } eml_entry($ctx, $eml), '</pre>', $end;
+       print { $ctx->{zfh} } eml_entry($ctx, $eml), '</pre>';
+       $end;
 }
 
 sub next_in_queue ($$) {
@@ -441,6 +443,7 @@ sub thread_html {
        my $ibx = $ctx->{ibx};
        my ($nr, $msgs) = $ibx->over->get_thread($mid);
        return missing_thread($ctx) if $nr == 0;
+       $ctx->{-spfx} = '../../' if $ibx->{coderepo};
 
        # link $INBOX_DIR/description text to "index_topics" view around
        # the newest message in this thread
@@ -584,24 +587,6 @@ sub add_text_body { # callback for each_part
                $ctx->{-anchors} = {} if $s =~ /^diff --git /sm;
                $diff = 1;
                delete $ctx->{-long_path};
-               my $spfx;
-               # absolute URL (Atom feeds)
-               if ($ibx->{coderepo}) {
-                       if (index($upfx, '//') >= 0) {
-                               $spfx = $upfx;
-                               $spfx =~ s!/([^/]*)/\z!/!;
-                       } else {
-                               my $n_slash = $upfx =~ tr!/!/!;
-                               if ($n_slash == 0) {
-                                       $spfx = '../';
-                               } elsif ($n_slash == 1) {
-                                       $spfx = '';
-                               } else { # nslash == 2
-                                       $spfx = '../../';
-                               }
-                       }
-               }
-               $ctx->{-spfx} = $spfx;
        };
 
        # split off quoted and unquoted blocks:
@@ -638,7 +623,8 @@ sub _msg_page_prepare {
                        return;
                }
                $ctx->{-html_tip} =
-"<pre>WARNING: multiple messages have this Message-ID\n</pre><pre>";
+qq[<pre>WARNING: multiple messages have this Message-ID (<a
+href="d/">diff</a>)</pre><pre>];
        } else {
                $ctx->{first_hdr} = $eml->header_obj;
                $ctx->{chash} = content_hash($eml) if $ctx->{smsg}; # reused MID
@@ -1240,4 +1226,30 @@ sub ghost_index_entry {
                . '</pre>' . $end;
 }
 
+# /$INBOX/$MSGID/d/ endpoint
+sub diff_msg {
+       my ($ctx) = @_;
+       require PublicInbox::MailDiff;
+       my $ibx = $ctx->{ibx};
+       my $over = $ibx->over or return no_over_html($ctx);
+       my ($id, $prev);
+       my $md = bless { ctx => $ctx }, 'PublicInbox::MailDiff';
+       my $next_arg = $md->{next_arg} = [ $ctx->{mid}, \$id, \$prev ];
+       my $smsg = $md->{smsg} = $over->next_by_mid(@$next_arg) or
+               return; # undef == 404
+       $ctx->{-t_max} = $smsg->{ts};
+       $ctx->{-upfx} = '../../';
+       $ctx->{-apfx} = '//'; # fail on to_attr()
+       $ctx->{-linkify} = PublicInbox::Linkify->new;
+       my $mid = ascii_html($smsg->{mid});
+       $ctx->{-title_html} = "diff for duplicates of &lt;$mid&gt;";
+       PublicInbox::WwwStream::html_init($ctx);
+       print { $ctx->{zfh} } '<pre>diff for duplicates of &lt;<a href="../">',
+                               $mid, "</a>&gt;\n\n";
+       sub {
+               $ctx->attach($_[0]->([200, delete $ctx->{-res_hdr}]));
+               $md->begin_mail_diff;
+       };
+}
+
 1;