about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-28 07:14:40 +0000
committerEric Wong <e@yhbt.net>2020-06-28 18:35:47 +0000
commit52e37476e8e62e8e54104d9a2abcf2a86d1d1a32 (patch)
tree45b30d09fdf06c5baf475771d6e2c825abf14c50
parent0d62ec0906ebdb4e9358ccb1c0d41a30f20711cf (diff)
downloadpublic-inbox-52e37476e8e62e8e54104d9a2abcf2a86d1d1a32.tar.gz
Apparently, using $1 from an octet string still results in a
multi-byte string.  Thus we need to perform utf8::encode after
the regexp character match to ensure wide characters don't get
passed to encode_base64.

This fixes a bug in which caused -watch to crash when using
PublicInbox::Filter::SubjectTag to remove "[list prefix]"
tags from Subject: lines.

I only found this bug because the proposed -watch updates for
NNTP/IMAP support introduced a possible bug which triggered a
full rescan of old archives:

  https://public-inbox.org/meta/20200627100400.9871-1-e@yhbt.net/
-rw-r--r--lib/PublicInbox/Eml.pm7
-rw-r--r--t/filter_subjecttag.t10
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/PublicInbox/Eml.pm b/lib/PublicInbox/Eml.pm
index ec682b91..1fecd41b 100644
--- a/lib/PublicInbox/Eml.pm
+++ b/lib/PublicInbox/Eml.pm
@@ -368,9 +368,12 @@ sub header_str_set {
         my ($self, $name, @vals) = @_;
         for (@vals) {
                 next unless /[^\x20-\x7e]/;
-                utf8::encode($_); # to octets
                 # 39: int((75 - length("Subject: =?UTF-8?B?".'?=') ) / 4) * 3;
-                s/(.{1,39})/'=?UTF-8?B?'.encode_base64($1, '').'?='/ges;
+                s/(.{1,39})/
+                        my $x = $1;
+                        utf8::encode($x); # to octets
+                        '=?UTF-8?B?'.encode_base64($x, '').'?='
+                /xges;
         }
         header_set($self, $name, @vals);
 }
diff --git a/t/filter_subjecttag.t b/t/filter_subjecttag.t
index 75effa27..e2d91e74 100644
--- a/t/filter_subjecttag.t
+++ b/t/filter_subjecttag.t
@@ -24,4 +24,14 @@ $mime->header_str_set('Subject', '[FOO] bar');
 $mime = $f->delivery($mime);
 is($mime->header('Subject'), 'bar', 'filtered non-reply');
 
+$f = PublicInbox::Filter::SubjectTag->new(-tag => '[sox-devel]');
+my $eml = PublicInbox::Eml->new(<<EOF);
+Subject: Re: [SoX-devel] =?utf-8?b?xaE?=
+
+EOF
+$eml = $f->delivery($eml);
+my $s = $eml->header('Subject');
+utf8::encode($s); # to octets
+is($s, "Re: \xc5\xa1", 'subject filtered correctly');
+
 done_testing();