From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2773B1F8DB for ; Thu, 7 May 2020 21:06:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 13/13] eml: drop trailing blank line on missing epilogue Date: Thu, 7 May 2020 21:05:56 +0000 Message-Id: <20200507210556.22995-14-e@yhbt.net> In-Reply-To: <20200507210556.22995-1-e@yhbt.net> References: <20200507210556.22995-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This improves Email::MIME compatibility when running xt/cmp-msgview.t on some GPG-signed messages. Its usefulness is dubious in the long term and this patch may be reverted down the line. --- lib/PublicInbox/Eml.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/Eml.pm b/lib/PublicInbox/Eml.pm index 1adaff04..4508bd84 100644 --- a/lib/PublicInbox/Eml.pm +++ b/lib/PublicInbox/Eml.pm @@ -131,8 +131,12 @@ sub mp_descend ($$) { # Cut at the the first epilogue, not subsequent ones. # *sigh* just the regexp match alone seems to bump RSS by # length($$bdy) on a ~30M string: - $$bdy =~ /((?:\r?\n)?^--$bnd--[ \t]*\r?$)/gsm and + my $epilogue_missing; + if ($$bdy =~ /((?:\r?\n)?^--$bnd--[ \t]*\r?$)/gsm) { substr($$bdy, pos($$bdy) - length($1)) = ''; + } else { + $epilogue_missing = 1; + } # *Sigh* split() doesn't work in-place and return CoW strings # because Perl wants to "\0"-terminate strings. So split() @@ -150,6 +154,10 @@ sub mp_descend ($$) { if (@parts) { # the usual path if we got this far: undef $bdy; # release memory ASAP if $nr > 0 + + # compatibility with Email::MIME + $parts[-1] =~ s/\n\r?\n\z/\n/s if $epilogue_missing; + @parts = grep /[^ \t\r\n]/s, @parts; # ignore empty parts # Keep "From: someone..." from preamble in old,