# 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;
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) .
'</pre><hr>'
} elsif ($more && @$more) {
++$end;
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) {
} 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 {
}
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}) .
'</pre><hr>'
} else {
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' => '<a@dup>',
+ 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();