]> Sergey Matveev's repositories - public-inbox.git/commitdiff
msg_iter: split_quotes adds trailing "\n"
authorEric Wong <e@80x24.org>
Wed, 6 Oct 2021 11:19:36 +0000 (11:19 +0000)
committerEric Wong <e@80x24.org>
Wed, 6 Oct 2021 11:24:35 +0000 (11:24 +0000)
The regexp in split_quotes relies on the presence of a
final "\n", so add it wherever we need to instead of
making it the responsibility of every caller.

This probably doesn't matter in practice since every
email seems to have a "\n" as the final byte (due to
the way SMTP works), but maybe there's some odd ones
that'll get imported via lei.

lib/PublicInbox/LeiViewText.pm
lib/PublicInbox/MsgIter.pm
lib/PublicInbox/View.pm

index 1f002ccd06fb3d10e169431a84d2461070f11fe3..c469d1ea5b1ce77a084b1e19a952cb90797054d4 100644 (file)
@@ -245,7 +245,6 @@ sub add_text_buf { # callback for Eml->each_part
        hdr_buf($self, $part) if $part->{is_submsg};
        $s =~ s/\r\n/\n/sg;
        _xs($s);
-       $s .= "\n" unless substr($s, -1, 1) eq "\n";
        my $diff = ($s =~ /^--- [^\n]+\n\+{3} [^\n]+\n@@ /ms);
        my @sections = PublicInbox::MsgIter::split_quotes($s);
        undef $s; # free memory
index 9c6581cc9dd63415a32a0a8f59bafae1cdb2b86d..dd28417b70c043b092f231147d82580ba94e31cf 100644 (file)
@@ -98,12 +98,16 @@ sub msg_part_text ($$) {
 
 # returns an array of quoted or unquoted sections
 sub split_quotes {
+       # some editors don't put trailing newlines at the end,
+       # make sure split_quotes can work:
+       $_[0] .= "\n" if substr($_[0], -1) ne "\n";
+
        # Quiet "Complex regular subexpression recursion limit" warning
        # in case an inconsiderate sender quotes 32K of text at once.
        # The warning from Perl is harmless for us since our callers can
        # tolerate less-than-ideal matches which work within Perl limits.
        no warnings 'regexp';
-       split(/((?:^>[^\n]*\n)+)/sm, shift);
+       split(/((?:^>[^\n]*\n)+)/sm, $_[0]);
 }
 
 1;
index 069b96806e3af4e331bcb5e70f840902ec52f8d8..64e73234f9ee2b17ca4efc4d5094d402426ee6d8 100644 (file)
@@ -624,9 +624,6 @@ sub add_text_body { # callback for each_part
                $ctx->{-spfx} = $spfx;
        };
 
-       # some editors don't put trailing newlines at the end:
-       $s .= "\n" unless $s =~ /\n\z/s;
-
        # split off quoted and unquoted blocks:
        my @sections = PublicInbox::MsgIter::split_quotes($s);
        undef $s; # free memory