user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH] view: do not offer links to 0-byte multipart attachments
@ 2020-05-25  8:21 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2020-05-25  8:21 UTC (permalink / raw)
  To: meta

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")
---
 lib/PublicInbox/View.pm | 5 +++++
 t/psgi_attach.t         | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 93a5b329155..a05ac4142f2 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 c6f8072ff9a..9a734f813fa 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,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-25  8:21 [PATCH] view: do not offer links to 0-byte multipart attachments Eric Wong

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git