From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 114F61FAE7; Thu, 29 Mar 2018 10:28:30 +0000 (UTC) From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Cc: "Eric Wong (Contractor, The Linux Foundation)" Subject: [PATCH 04/14] www: fix attachment downloads for conflicted Message-IDs Date: Thu, 29 Mar 2018 10:28:09 +0000 Message-Id: <20180329102819.15234-5-e@80x24.org> In-Reply-To: <20180329102819.15234-1-e@80x24.org> References: <20180329102819.15234-1-e@80x24.org> List-Id: By using the "primary" Message-ID in WwwAttach, we can avoid conflicts in the links we use for downloading attachments. --- lib/PublicInbox/View.pm | 14 +++++++++----- t/psgi_v2.t | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 133c30a..aad860e 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -24,7 +24,7 @@ sub th_pfx ($) { $_[0] == 0 ? '' : TCHILD }; # public functions: (unstable) sub msg_html { - my ($ctx, $mime, $more) = @_; + my ($ctx, $mime, $more, $smsg) = @_; my $hdr = $mime->header_obj; my $ibx = $ctx->{-inbox}; my $obfs_ibx = $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef; @@ -33,7 +33,9 @@ sub msg_html { PublicInbox::WwwStream->response($ctx, 200, sub { my ($nr, undef) = @_; if ($nr == 1) { - $tip . multipart_text_as_html($mime, '', $obfs_ibx) . + # $more cannot be true w/o $smsg being defined: + my $upfx = $more ? '../'.mid_escape($smsg->mid).'/' : ''; + $tip . multipart_text_as_html($mime, $upfx, $obfs_ibx) . '
' } elsif ($more && @$more) { ++$end; @@ -57,12 +59,13 @@ sub msg_page { my $mid = $ctx->{mid}; my $ibx = $ctx->{-inbox}; my ($first, $more, $head, $tail, $db); + my $smsg; if (my $srch = $ibx->search) { $srch->retry_reopen(sub { ($head, $tail, $db) = $srch->each_smsg_by_mid($mid); for (; !defined($first) && $head != $tail; $head++) { my @args = ($head, $db, $mid); - my $smsg = PublicInbox::SearchMsg->get(@args); + $smsg = PublicInbox::SearchMsg->get(@args); $first = $ibx->msg_by_smsg($smsg); } if ($head != $tail) { @@ -73,7 +76,7 @@ sub msg_page { } else { $first = $ibx->msg_by_mid($mid) or return; } - msg_html($ctx, PublicInbox::MIME->new($first), $more); + msg_html($ctx, PublicInbox::MIME->new($first), $more, $smsg); } sub msg_html_more { @@ -93,8 +96,9 @@ sub msg_html_more { } if ($smsg) { my $mime = $smsg->{mime}; + my $upfx = '../' . mid_escape($smsg->mid) . '/'; _msg_html_prepare($mime->header_obj, $ctx, $more, $nr) . - multipart_text_as_html($mime, '', + multipart_text_as_html($mime, $upfx, $ctx->{-obfs_ibx}) . '
' } else { diff --git a/t/psgi_v2.t b/t/psgi_v2.t index 11b2c79..31c4178 100644 --- a/t/psgi_v2.t +++ b/t/psgi_v2.t @@ -171,6 +171,42 @@ test_psgi(sub { $www->call(@_) }, sub { is($res->code, 200, 'got info refs for dumb clones'); $res = $cb->(GET('/v2test/info/refs')); is($res->code, 404, 'unpartitioned git URL fails'); + + # ensure conflicted attachments can be resolved + foreach my $body (qw(old new)) { + my $parts = [ + PublicInbox::MIME->create( + attributes => { content_type => 'text/plain' }, + body => 'blah', + ), + PublicInbox::MIME->create( + attributes => { + filename => 'attach.txt', + content_type => 'text/plain', + }, + body => $body + ) + ]; + $mime = PublicInbox::MIME->create( + parts => $parts, + header_str => [ From => 'root@z', + 'Message-ID' => '', + Subject => 'hi'] + ); + ok($im->add($mime), "added attachment $body"); + } + $im->done; + $config->each_inbox(sub { $_[0]->search->reopen }); + $res = $cb->(GET('/v2test/a@dup/')); + my @links = ($res->content =~ m!"\.\./([^/]+/2-attach\.txt)\"!g); + is(scalar(@links), 2, 'both attachment links exist'); + isnt($links[0], $links[1], 'attachment links are different'); + { + my $old = $cb->(GET('/v2test/' . $links[0])); + my $new = $cb->(GET('/v2test/' . $links[1])); + is($old->content, 'old', 'got expected old content'); + is($new->content, 'new', 'got expected new content'); + } }); done_testing(); -- EW