]> Sergey Matveev's repositories - public-inbox.git/commitdiff
inboxwritable: fix From_ line unescaping
authorEric Wong <e@yhbt.net>
Sat, 4 Apr 2020 06:17:29 +0000 (06:17 +0000)
committerEric Wong <e@yhbt.net>
Sat, 4 Apr 2020 17:48:58 +0000 (17:48 +0000)
We can't rely on Email::MIME noticing the change to our
scalar ref after calling `PublicInbox::MIME->new'.

This is because Email::MIME::body_set (unlike
Email::Simple::body_set) will copy the contents of the body into
`->{body_raw}' as a new scalar.

Furthermore, we need to escape multiple From lines in the body,
not just the first one, using the `g' modifier to `s//'.

Reported-by: Kyle Meyer <kyle@kyleam.com>
lib/PublicInbox/InboxWritable.pm

index ce979ea2bf8c65fe2f5f72ce16ef5d58515b5762..f2ba21fcbdfa02051d1a5d8677a81279942978f5 100644 (file)
@@ -157,12 +157,12 @@ my $from_strict = qr/^From \S+ +\S+ \S+ +\S+ [^:]+:[^:]+:[^:]+ [^:]+/;
 sub mb_add ($$$$) {
        my ($im, $variant, $filter, $msg) = @_;
        $$msg =~ s/(\r?\n)+\z/$1/s;
-       my $mime = PublicInbox::MIME->new($msg);
        if ($variant eq 'mboxrd') {
-               $$msg =~ s/^>(>*From )/$1/sm;
+               $$msg =~ s/^>(>*From )/$1/gms;
        } elsif ($variant eq 'mboxo') {
-               $$msg =~ s/^>From /From /sm;
+               $$msg =~ s/^>From /From /gms;
        }
+       my $mime = PublicInbox::MIME->new($msg);
        if ($filter) {
                my $ret = $filter->scrub($mime) or return;
                return if $ret == REJECT();