From: Eric Wong Date: Sat, 10 Sep 2022 08:17:07 +0000 (+0000) Subject: view: attach_link: reduce obuf manipulation X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=5ade6f79b3b7b2c3562cfa6fd7b8cf68223f0c0a view: attach_link: reduce obuf manipulation This is another steep towards reducing the maximum size of an obuf by eventually doing compression earlier while we render messages as HTML. And do some golfing while we're at it... --- diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 1b55fe77..0fe645ca 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -524,7 +524,6 @@ sub attach_link ($$$$;$) { # downloads for 0-byte multipart attachments return unless $part->{bdy}; - my $nl = $idx eq '1' ? '' : "\n"; # like join("\n", ...) my $size = length($part->body); delete $part->{bdy}; # save memory @@ -540,23 +539,17 @@ sub attach_link ($$$$;$) { } else { $sfn = 'a.bin'; } - my $rv = $ctx->{obuf}; - $$rv .= qq($nl{mhref}$idx-$sfn">); - if ($err) { - $$rv .= <{mhref}$idx-$sfn">); + $rv .= <header('Content-Description') // $fn // ''; - $desc = ascii_html($desc); - $$rv .= ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]"; - $$rv .= "\n"; - - $$rv .= submsg_hdr($ctx, $part) if $part->{is_submsg}; - - undef; + $rv .= ascii_html($desc)." --]\n[-- " if $desc ne ''; + $rv .= "Type: $ct, Size: $size bytes --]\n"; + $rv .= submsg_hdr($ctx, $part) if $part->{is_submsg}; + $rv; } sub add_text_body { # callback for each_part @@ -568,10 +561,9 @@ sub add_text_body { # callback for each_part my ($part, $depth, $idx) = @$p; my $ct = $part->content_type || 'text/plain'; my $fn = $part->filename; - my ($s, $err) = msg_part_text($part, $ct); - return attach_link($ctx, $ct, $p, $fn) unless defined $s; - my $rv = $ctx->{obuf}; + my ($s, $err) = msg_part_text($part, $ct); + $s // return $$rv .= (attach_link($ctx, $ct, $p, $fn) // ''); if ($part->{is_submsg}) { $$rv .= submsg_hdr($ctx, $part); $$rv .= "\n"; @@ -623,7 +615,7 @@ sub add_text_body { # callback for each_part undef $s; # free memory if (defined($fn) || ($depth > 0 && !$part->{is_submsg}) || $err) { # badly-encoded message with $err? tell the world about it! - attach_link($ctx, $ct, $p, $fn, $err); + $$rv .= attach_link($ctx, $ct, $p, $fn, $err); $$rv .= "\n"; } delete $part->{bdy}; # save memory