about summary refs log tree commit homepage
path: root/t/filter.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-08-04 20:16:51 +0000
committerEric Wong <e@80x24.org>2014-08-04 20:16:51 +0000
commitc9ea7a39daff28e0c75df8b5853fbd4a9bda6bba (patch)
treedba3824f88c033f409174261afd2fc892bc2b933 /t/filter.t
parented28a3b51a9b3746ed51ad98c6a69449f22ed81d (diff)
downloadpublic-inbox-c9ea7a39daff28e0c75df8b5853fbd4a9bda6bba.tar.gz
HTML clients also tend to send quoted-printable crap in
their plain-text parts, preserve that so it's displayed
correctly for all QP-capable handlers.
Diffstat (limited to 't/filter.t')
-rw-r--r--t/filter.t47
1 files changed, 47 insertions, 0 deletions
diff --git a/t/filter.t b/t/filter.t
index c3cd39f4..e4f6a2b0 100644
--- a/t/filter.t
+++ b/t/filter.t
@@ -15,6 +15,53 @@ sub count_body_parts {
         $bodies->{$body}++;
 }
 
+# multipart/alternative: HTML and quoted-printable, keep the plain-text
+{
+        my $html_body = "<html><body>hi</body></html>";
+        my $parts = [
+                Email::MIME->create(
+                        attributes => {
+                                content_type => 'text/html; charset=UTF-8',
+                                encoding => 'base64',
+                        },
+                        body => $html_body,
+                ),
+                Email::MIME->create(
+                        attributes => {
+                                content_type => 'text/plain',
+                                encoding => 'quoted-printable',
+                        },
+                        body => 'hi = "bye"',
+                )
+        ];
+        my $email = Email::MIME->create(
+                header_str => [
+                  From => 'a@example.com',
+                  Subject => 'blah',
+                  'Content-Type' => 'multipart/alternative'
+                ],
+                parts => $parts,
+        );
+        is(1, PublicInbox::Filter->run($email), "run was a success");
+        my $parsed = Email::MIME->new($email->as_string);
+        is("text/plain", $parsed->header("Content-Type"));
+        is(scalar $parsed->parts, 1, "HTML part removed");
+        my %bodies;
+        $parsed->walk_parts(sub {
+                my ($part) = @_;
+                return if $part->subparts; # walk_parts already recurses
+                count_body_parts(\%bodies, $part);
+        });
+        is(scalar keys %bodies, 1, "one bodies");
+        is($bodies{"hi =3D \"bye\"="}, 1, "QP text part unchanged");
+        $parsed->walk_parts(sub {
+                my ($part) = @_;
+                my $b = $part->body;
+                $b =~ s/\s*\z//;
+                is($b, "hi = \"bye\"", "decoded body matches");
+        });
+}
+
 # plain-text email is passed through unchanged
 {
         my $s = Email::MIME->create(