about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-05-25 08:21:37 +0000
committerEric Wong <e@yhbt.net>2020-05-26 10:54:36 +0000
commit8604ccc806997eadf78e2b6352b4daa0287b8bb0 (patch)
tree828ed68f90a46d697886f24c7bbd4656cbf08e78
parentd6763f26cd82cae90ced264cfa59d0163ee5180f (diff)
downloadpublic-inbox-8604ccc806997eadf78e2b6352b4daa0287b8bb0.tar.gz
Offering links to download 0-byte files is useless.  We could
waste memory by preserving $eml->{bdy} during iteration, but
offering attachments of type "multipart" is not very useful,
as users are usually interested in decoded attachments or
the entire raw message.

Fixes: e60231148eb604a3 ("descend into message/(rfc822|news|global) parts")
-rw-r--r--lib/PublicInbox/View.pm5
-rw-r--r--t/psgi_attach.t2
2 files changed, 7 insertions, 0 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 93a5b329..a05ac414 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -499,6 +499,11 @@ sub submsg_hdr ($$) {
 sub attach_link ($$$$;$) {
         my ($ctx, $ct, $p, $fn, $err) = @_;
         my ($part, $depth, $idx) = @$p;
+
+        # Eml iteration clobbers multipart ->{bdy}, so do not offer
+        # downloads for 0-byte multipart attachments
+        return unless $part->{bdy};
+
         my $nl = $idx eq '1' ? '' : "\n"; # like join("\n", ...)
         my $size = bytes::length($part->body);
 
diff --git a/t/psgi_attach.t b/t/psgi_attach.t
index c6f8072f..9a734f81 100644
--- a/t/psgi_attach.t
+++ b/t/psgi_attach.t
@@ -73,6 +73,8 @@ $im->init_bare;
                 my $mid = '20200418222508.GA13918@dcvr';
                 my $irt = '20200418222020.GA2745@dcvr';
                 $res = $cb->(GET("/test/$mid/"));
+                unlike($res->content, qr! multipart/mixed, Size: 0 bytes!,
+                        '0-byte download not offered');
                 like($res->content, qr/\bhref="2-embed2x\.eml"/s,
                         'href to message/rfc822 attachment visible');
                 like($res->content, qr/\bhref="2\.1\.2-test\.eml"/s,