]> Sergey Matveev's repositories - public-inbox.git/commitdiff
tests: remove Email::MIME->create use entirely
authorEric Wong <e@yhbt.net>
Sat, 25 Apr 2020 05:52:22 +0000 (05:52 +0000)
committerEric Wong <e@yhbt.net>
Sun, 26 Apr 2020 07:03:14 +0000 (07:03 +0000)
Replace them with .eml files generated with the help of
Email::MIME, but without some extraneous and unnecessary
headers, and strip mime_load down to just loading files.

This will give us more freedom to experiment with other mail
libraries which may be more correct, better maintained, use
less memory and/or be faster than Email::MIME.

22 files changed:
MANIFEST
lib/PublicInbox/TestCommon.pm
t/filter_base-junk.eml [new file with mode: 0644]
t/filter_base-xhtml.eml [new file with mode: 0644]
t/filter_base.t
t/filter_mirror.t
t/mda-mime.eml [new file with mode: 0644]
t/mda.t
t/msg_iter-nested.eml [new file with mode: 0644]
t/msg_iter-order.eml [new file with mode: 0644]
t/msg_iter.t
t/plack-2-txt-bodies.eml [new file with mode: 0644]
t/plack-attached-patch.eml [new file with mode: 0644]
t/plack-qp.eml [new file with mode: 0644]
t/plack.t
t/psgi_attach.eml [new file with mode: 0644]
t/psgi_attach.t
t/psgi_v2-new.eml [new file with mode: 0644]
t/psgi_v2-old.eml [new file with mode: 0644]
t/psgi_v2.t
t/search-amsg.eml [new file with mode: 0644]
t/search.t

index b06aa67960ad01068707c05264279d7ec030c53f..e3e0f2a886e8bf9183eaa9c8ce67cec7cae22c2a 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -231,6 +231,8 @@ t/emergency.t
 t/epoll.t
 t/fail-bin/spamc
 t/feed.t
+t/filter_base-junk.eml
+t/filter_base-xhtml.eml
 t/filter_base.t
 t/filter_mirror.t
 t/filter_rubylang.t
@@ -257,10 +259,13 @@ t/init.t
 t/iso-2202-jp.eml
 t/linkify.t
 t/main-bin/spamc
+t/mda-mime.eml
 t/mda.t
 t/mda_filter_rubylang.t
 t/mid.t
 t/mime.t
+t/msg_iter-nested.eml
+t/msg_iter-order.eml
 t/msg_iter.t
 t/msgmap.t
 t/msgtime.t
@@ -270,8 +275,12 @@ t/nntpd-tls.t
 t/nntpd.t
 t/nulsubject.t
 t/over.t
+t/plack-2-txt-bodies.eml
+t/plack-attached-patch.eml
+t/plack-qp.eml
 t/plack.t
 t/precheck.t
+t/psgi_attach.eml
 t/psgi_attach.t
 t/psgi_bad_mids.t
 t/psgi_mount.t
@@ -279,12 +288,15 @@ t/psgi_multipart_not.t
 t/psgi_scan_all.t
 t/psgi_search.t
 t/psgi_text.t
+t/psgi_v2-new.eml
+t/psgi_v2-old.eml
 t/psgi_v2.t
 t/purge.t
 t/qspawn.t
 t/replace.t
 t/reply.t
 t/run.perl
+t/search-amsg.eml
 t/search-thr-index.t
 t/search.t
 t/sigfd.t
index ac14d27bc87b9ba406edd22eb475f704a8dabc39..27390ab2f52e80f59d68bf7486edd233c61047ad 100644 (file)
@@ -11,27 +11,10 @@ use IO::Socket::INET;
 our @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
        run_script start_script key2sub xsys xqx mime_load);
 
-sub mime_load ($;&) {
+sub mime_load ($) {
        my ($path, $cb) = @_;
-       if (open(my $fh, '<', $path)) {
-               PublicInbox::MIME->new(\(do { local $/; <$fh> }));
-       } elsif ($cb) {
-               require File::Temp;
-
-               my $mime = $cb->();
-               my ($dir) = ($path =~ m!(.+)/(?:[^/]+)\z!);
-               -d $dir or die "BUG: dir=$dir is not the dir of $path";
-               my $fh = File::Temp->new(DIR => $dir);
-               $fh->autoflush(1);
-               print $fh $mime->as_string or die "print: $!";
-               my $fn = $fh->filename;
-               rename($fn, $path) or die "link $fn => $path: $!";
-               $fh->unlink_on_destroy(0);
-               pop @_; # retry via tail recursion
-               goto &mime_load;
-       } else {
-               die "open $path: $!";
-       }
+       open(my $fh, '<', $path) or die "open $path: $!";
+       PublicInbox::MIME->new(\(do { local $/; <$fh> }));
 }
 
 sub tmpdir (;$) {
diff --git a/t/filter_base-junk.eml b/t/filter_base-junk.eml
new file mode 100644 (file)
index 0000000..4733bbe
--- /dev/null
@@ -0,0 +1,19 @@
+From: a@example.com
+Subject: blah
+Content-Type: multipart/mixed; boundary="b"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+--b
+Content-Type: application/vnd.ms-excel
+Content-Transfer-Encoding: base64
+
+anVuaw==
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+
+junk=
+
+--b--
diff --git a/t/filter_base-xhtml.eml b/t/filter_base-xhtml.eml
new file mode 100644 (file)
index 0000000..d13a11c
--- /dev/null
@@ -0,0 +1,19 @@
+From: a@example.com
+Subject: blah
+Content-Type: multipart/alternative; boundary="b"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+--b
+Content-Type: text/xhtml; charset=UTF-8
+Content-Transfer-Encoding: base64
+
+PGh0bWw+PGJvZHk+aGk8L2JvZHk+PC9odG1sPg==
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+
+hi =3D "bye"=
+
+--b--
index 7919dd65098e0309662a2f7b7fec70bc9035376f..bbd64189fb5fa2a2484d100bd6a3035708ecade0 100644 (file)
@@ -21,62 +21,13 @@ use_ok 'PublicInbox::Filter::Base';
 
 {
        my $f = PublicInbox::Filter::Base->new;
-       my $email = mime_load 't/filter_base-xhtml.eml', sub {
-       my $html_body = "<html><body>hi</body></html>";
-       my $parts = [
-               Email::MIME->create(
-                       attributes => {
-                               content_type => 'text/xhtml; charset=UTF-8',
-                               encoding => 'base64',
-                       },
-                       body => $html_body,
-               ),
-               Email::MIME->create(
-                       attributes => {
-                               content_type => 'text/plain',
-                               encoding => 'quoted-printable',
-                       },
-                       body => 'hi = "bye"',
-               )
-       ];
-       Email::MIME->create(
-               header_str => [
-                 From => 'a@example.com',
-                 Subject => 'blah',
-                 'Content-Type' => 'multipart/alternative'
-               ],
-               parts => $parts,
-       )}; # mime_load sub
+       my $email = mime_load 't/filter_base-xhtml.eml';
        is($f->delivery($email), 100, "xhtml rejected");
 }
 
 {
        my $f = PublicInbox::Filter::Base->new;
-       my $email = mime_load 't/filter_base-junk.eml', sub {
-       my $parts = [
-               Email::MIME->create(
-                       attributes => {
-                               content_type => 'application/vnd.ms-excel',
-                               encoding => 'base64',
-                       },
-                       body => 'junk',
-               ),
-               Email::MIME->create(
-                       attributes => {
-                               content_type => 'text/plain',
-                               encoding => 'quoted-printable',
-                       },
-                       body => 'junk',
-               )
-       ];
-       Email::MIME->create(
-               header_str => [
-                 From => 'a@example.com',
-                 Subject => 'blah',
-                 'Content-Type' => 'multipart/mixed'
-               ],
-               parts => $parts,
-       )}; # mime_load sub
+       my $email = mime_load 't/filter_base-junk.eml';
        is($f->delivery($email), 100, 'proprietary format rejected on glob');
 }
 
index 694209d9e07076f5e404d1ade759ccd58886f9f4..0e641a03ca61544a7abfacf8d238d3084acaaade 100644 (file)
@@ -9,32 +9,7 @@ use_ok 'PublicInbox::Filter::Mirror';
 my $f = PublicInbox::Filter::Mirror->new;
 ok($f, 'created PublicInbox::Filter::Mirror object');
 {
-       my $email = mime_load 't/filter_mirror.eml', sub {
-       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"',
-               )
-       ];
-       Email::MIME->create(
-               header_str => [
-                 From => 'a@example.com',
-                 Subject => 'blah',
-                 'Content-Type' => 'multipart/alternative'
-               ],
-               parts => $parts,
-       )}; # mime_laod sub
+       my $email = mime_load 't/mda-mime.eml';
        is($f->ACCEPT, $f->delivery($email), 'accept any trash that comes');
 }
 
diff --git a/t/mda-mime.eml b/t/mda-mime.eml
new file mode 100644 (file)
index 0000000..64a9281
--- /dev/null
@@ -0,0 +1,21 @@
+From: a@example.com
+Subject: blah
+Cc: test-public@example.com
+Message-ID: <multipart-html-sucks@11>
+Content-Type: multipart/alternative; boundary="b"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+--b
+Content-Type: text/html; charset=UTF-8
+Content-Transfer-Encoding: base64
+
+PGh0bWw+PGJvZHk+aGk8L2JvZHk+PC9odG1sPg==
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+
+hi =3D "bye"=
+
+--b--
diff --git a/t/mda.t b/t/mda.t
index 5457f17f3cde72e2186f48c079715564114a3bb6..863eaf8fe2dda3d3316b84ddb3737b379efebcce 100644 (file)
--- a/t/mda.t
+++ b/t/mda.t
@@ -3,7 +3,6 @@
 use strict;
 use warnings;
 use Test::More;
-use Email::MIME;
 use Cwd qw(getcwd);
 use PublicInbox::MID qw(mid2path);
 use PublicInbox::Git;
@@ -22,7 +21,6 @@ my $fail_path = "$fail_bin:$ENV{PATH}"; # for spamc spam mock
 my $addr = 'test-public@example.com';
 my $cfgpfx = "publicinbox.test";
 my $faildir = "$home/faildir/";
-my $mime;
 my $git = PublicInbox::Git->new($maindir);
 
 my $fail_bad_header = sub ($$$) {
@@ -233,36 +231,8 @@ EOF
                "learned ham idempotently ");
 
        # ensure trained email is filtered, too
-       $mime = mime_load 't/mda-mime.eml', sub {
-       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"',
-               )
-       ];
-       $mid = 'multipart-html-sucks@11';
-       Email::MIME->create(
-               header_str => [
-                 From => 'a@example.com',
-                 Subject => 'blah',
-                 Cc => $addr,
-                 'Message-ID' => "<$mid>",
-                 'Content-Type' => 'multipart/alternative',
-               ],
-               parts => $parts,
-       )}; # mime_load sub
-
+       my $mime = mime_load 't/mda-mime.eml';
+       ($mid) = ($mime->header_raw('message-id') =~ /<([^>]+)>/);
        {
                $in = $mime->as_string;
                ok(run_script(['-learn', 'ham'], undef, { 0 => \$in }),
diff --git a/t/msg_iter-nested.eml b/t/msg_iter-nested.eml
new file mode 100644 (file)
index 0000000..08d0ada
--- /dev/null
@@ -0,0 +1,26 @@
+From: root@localhost
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="outer"
+
+--outer
+From: sub@localhost
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="inner"
+
+--inner
+MIME-Version: 1.0
+
+a
+--inner
+MIME-Version: 1.0
+
+b
+--inner--
+
+--outer
+MIME-Version: 1.0
+
+sig
+--outer--
diff --git a/t/msg_iter-order.eml b/t/msg_iter-order.eml
new file mode 100644 (file)
index 0000000..153af80
--- /dev/null
@@ -0,0 +1,16 @@
+From: root@localhost
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+MIME-Version: 1.0
+
+a
+
+--b
+MIME-Version: 1.0
+
+b
+
+--b--
index ac2066a2780d8d4fd7acb09a242633ae1863a183..6adbf165b0713268cfb87bf73c9b7b9d7c45d1a9 100644 (file)
@@ -9,12 +9,7 @@ use PublicInbox::InboxWritable;
 use_ok('PublicInbox::MsgIter');
 
 {
-       my $mime = mime_load 't/msg_iter-order.eml', sub {
-       my $parts = [ Email::MIME->create(body => "a\n"),
-                       Email::MIME->create(body => "b\n") ];
-       Email::MIME->create(parts => $parts,
-                               header_str => [ From => 'root@localhost' ]);
-       }; # mime_load sub
+       my $mime = mime_load 't/msg_iter-order.eml';
        my @parts;
        msg_iter($mime, sub {
                my ($part, $level, @ex) = @{$_[0]};
@@ -26,15 +21,7 @@ use_ok('PublicInbox::MsgIter');
 }
 
 {
-       my $mime = mime_load 't/msg_iter-nested.eml', sub {
-       my $parts = [ Email::MIME->create(body => 'a'),
-                       Email::MIME->create(body => 'b') ];
-       $parts = [ Email::MIME->create(parts => $parts,
-                               header_str => [ From => 'sub@localhost' ]),
-                       Email::MIME->create(body => 'sig') ];
-       Email::MIME->create(parts => $parts,
-                               header_str => [ From => 'root@localhost' ]);
-       }; # mime_load sub
+       my $mime = mime_load 't/msg_iter-nested.eml';
        my @parts;
        msg_iter($mime, sub {
                my ($part, $level, @ex) = @{$_[0]};
diff --git a/t/plack-2-txt-bodies.eml b/t/plack-2-txt-bodies.eml
new file mode 100644 (file)
index 0000000..a06cd68
--- /dev/null
@@ -0,0 +1,17 @@
+From: a@example.com
+Subject: blargh
+Message-ID: <multipart@example.com>
+In-Reply-To: <irp@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+hi
+--b
+Content-Type: text/plain
+
+bye
+--b--
diff --git a/t/plack-attached-patch.eml b/t/plack-attached-patch.eml
new file mode 100644 (file)
index 0000000..bc6d295
--- /dev/null
@@ -0,0 +1,20 @@
+From: a@example.com
+Subject: [PATCH] asdf
+Message-ID: <patch@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+hi, see attached
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="foo&.patch"
+
+--- a/file
++++ b/file
+@@ -49, 7 +49,34 @@
+
+--b--
diff --git a/t/plack-qp.eml b/t/plack-qp.eml
new file mode 100644 (file)
index 0000000..d9008c8
--- /dev/null
@@ -0,0 +1,8 @@
+From: qp@example.com
+Subject: QP
+Message-ID: <qp@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: quoted-printable
+Content-Type: text/plain
+
+hi =3D bye=
index d45dbcd2085b2a286625a43299fd7ff359d4f87b..4fff977352b567671bc562934ff8018bc0d98190 100644 (file)
--- a/t/plack.t
+++ b/t/plack.t
@@ -3,7 +3,6 @@
 use strict;
 use warnings;
 use Test::More;
-use Email::MIME;
 use PublicInbox::TestCommon;
 my $psgi = "./examples/public-inbox.psgi";
 my ($tmpdir, $for_destroy) = tmpdir();
@@ -51,65 +50,15 @@ EOF
        chomp @ls;
 
        # multipart with two text bodies
-       my %attr_text = (attributes => { content_type => 'text/plain' });
-       $mime = mime_load 't/plack-2-txt-bodies.eml', sub {
-       my $parts = [
-               Email::MIME->create(%attr_text, body => 'hi'),
-               Email::MIME->create(%attr_text, body => 'bye')
-       ];
-       Email::MIME->create(
-               header_str => [
-                       From => 'a@example.com',
-                       Subject => 'blargh',
-                       'Message-ID' => '<multipart@example.com>',
-                       'In-Reply-To' => '<irp@example.com>'
-               ],
-               parts => $parts,
-       )}; # mime_load sub
+       $mime = mime_load 't/plack-2-txt-bodies.eml';
        $im->add($mime);
 
        # multipart with attached patch + filename
-       $mime = mime_load 't/plack-attached-patch.eml', sub {
-       my $parts = [
-               Email::MIME->create(%attr_text, body => 'hi, see attached'),
-               Email::MIME->create(
-                       attributes => {
-                                       content_type => 'text/plain',
-                                       filename => "foo&.patch",
-                       },
-                       body => "--- a/file\n+++ b/file\n" .
-                               "@@ -49, 7 +49,34 @@\n"
-                       )
-       ];
-       Email::MIME->create(
-               header_str => [
-                       From => 'a@example.com',
-                       Subject => '[PATCH] asdf',
-                       'Message-ID' => '<patch@example.com>'
-               ],
-               parts => $parts
-       )}; # mime_load sub
+       $mime = mime_load 't/plack-attached-patch.eml';
        $im->add($mime);
 
        # multipart collapsed to single quoted-printable text/plain
-       $mime = mime_load 't/plack-qp.eml', sub {
-       my $parts = [
-               Email::MIME->create(
-                       attributes => {
-                               content_type => 'text/plain',
-                               encoding => 'quoted-printable'
-                       },
-                       body => 'hi = bye',
-               )
-       ];
-       Email::MIME->create(
-               header_str => [
-                       From => 'qp@example.com',
-                       Subject => 'QP',
-                       'Message-ID' => '<qp@example.com>',
-                       ],
-               parts => $parts,
-       )};
+       $mime = mime_load 't/plack-qp.eml';
        like($mime->body_raw, qr/hi =3D bye=/, 'our test used QP correctly');
        $im->add($mime);
 
diff --git a/t/psgi_attach.eml b/t/psgi_attach.eml
new file mode 100644 (file)
index 0000000..cfa3622
--- /dev/null
@@ -0,0 +1,38 @@
+From: root@z
+Message-Id: <Z@B>
+Subject: hi
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: inline; filename="queue-pee"
+
+abcdef=3Dg
+=3D=3Dblah
+
+--b
+Content-Type: appication/octet-stream
+Content-Transfer-Encoding: base64
+Content-Disposition: inline; filename="bayce-sixty-four"
+
+YjY03q2+7wo=
+
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="noop.txt"
+
+plain
+text
+pass
+through
+
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename=".dotfile"
+
+dotfile
+
+--b--
index 0dde9323dc3943a265284be192abf63022caa48b..af0fbdd397727db319759e3906825906dc4577e7 100644 (file)
@@ -3,7 +3,6 @@
 use strict;
 use warnings;
 use Test::More;
-use Email::MIME;
 use PublicInbox::TestCommon;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $maindir = "$tmpdir/main.git";
@@ -30,41 +29,7 @@ $im->init_bare;
        my $b64 = "b64\xde\xad\xbe\xef\n";
        my $txt = "plain\ntext\npass\nthrough\n";
        my $dot = "dotfile\n";
-       my $mime = mime_load 't/psgi_attach.eml', sub {
-       my $parts = [
-               Email::MIME->create(
-                       attributes => {
-                               filename => 'queue-pee',
-                               content_type => 'text/plain',
-                               encoding => 'quoted-printable'
-                       },
-                       body => $qp),
-               Email::MIME->create(
-                       attributes => {
-                               filename => 'bayce-sixty-four',
-                               content_type => 'appication/octet-stream',
-                               encoding => 'base64',
-                       },
-                       body => $b64),
-               Email::MIME->create(
-                       attributes => {
-                               filename => 'noop.txt',
-                               content_type => 'text/plain',
-                       },
-                       body => $txt),
-               Email::MIME->create(
-                       attributes => {
-                               filename => '.dotfile',
-                               content_type => 'text/plain',
-                       },
-                       body => $dot),
-       ];
-       Email::MIME->create(
-               parts => $parts,
-               header_str => [ From => 'root@z', 'Message-Id' => '<Z@B>',
-                       Subject => 'hi']
-       )}; # mime_load sub
-       $im->add($mime);
+       $im->add(mime_load('t/psgi_attach.eml'));
        $im->done;
 
        my $www = PublicInbox::WWW->new($config);
diff --git a/t/psgi_v2-new.eml b/t/psgi_v2-new.eml
new file mode 100644 (file)
index 0000000..2c26471
--- /dev/null
@@ -0,0 +1,17 @@
+From: root@z
+Message-ID: <a@dup>
+Subject: hi
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+blah
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="attach.txt"
+
+new
+--b--
diff --git a/t/psgi_v2-old.eml b/t/psgi_v2-old.eml
new file mode 100644 (file)
index 0000000..f82dbf2
--- /dev/null
@@ -0,0 +1,17 @@
+From: root@z
+Message-ID: <a@dup>
+Subject: hi
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+blah
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="attach.txt"
+
+old
+--b--
index 5d212ca6f7ca1bb126bef8f92d02123f01789891..9c19b0413dd1f0c20b61e58ea21c751006b88c9f 100644 (file)
@@ -9,7 +9,7 @@ use PublicInbox::MIME;
 use PublicInbox::Config;
 use PublicInbox::MID qw(mids);
 require_mods(qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
-               URI::Escape Plack::Builder Email::MIME));
+               URI::Escape Plack::Builder));
 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
 use_ok 'PublicInbox::WWW';
 use_ok 'PublicInbox::V2Writable';
@@ -225,26 +225,7 @@ test_psgi(sub { $www->call(@_) }, sub {
 
        # ensure conflicted attachments can be resolved
        foreach my $body (qw(old new)) {
-               $mime = mime_load "t/psgi_v2-$body.eml", sub {
-               my $parts = [
-                       Email::MIME->create(
-                               attributes => { content_type => 'text/plain' },
-                               body => 'blah',
-                       ),
-                       Email::MIME->create(
-                               attributes => {
-                                       filename => 'attach.txt',
-                                       content_type => 'text/plain',
-                               },
-                               body => $body
-                       )
-               ];
-               Email::MIME->create(
-                       parts => $parts,
-                       header_str => [ From => 'root@z',
-                               'Message-ID' => '<a@dup>',
-                               Subject => 'hi']
-               )}; # mime_load sub
+               $mime = mime_load "t/psgi_v2-$body.eml";
                ok($im->add($mime), "added attachment $body");
        }
        $im->done;
diff --git a/t/search-amsg.eml b/t/search-amsg.eml
new file mode 100644 (file)
index 0000000..c87c0f1
--- /dev/null
@@ -0,0 +1,23 @@
+Subject: see attachment
+Message-ID: <file@attached>
+From: "John Smith" <js@example.com>
+To: list@example.com
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain; charset="US-ASCII"
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: attachment; filename="attached_fart.txt"
+
+inside the attachment=
+
+--b
+Content-Type: text/plain; charset="US-ASCII"
+Content-Disposition: attachment; filename="part_deux.txt"
+Content-Transfer-Encoding: quoted-printable
+
+inside another=
+
+--b--
index 0301fd90b6289f379063400ac888343f7ed9d433..40264345985477bc0609381d5dbdd4c606c317ac 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use Test::More;
 use PublicInbox::TestCommon;
-require_mods(qw(DBD::SQLite Search::Xapian Email::MIME));
+require_mods(qw(DBD::SQLite Search::Xapian));
 require PublicInbox::SearchIdx;
 require PublicInbox::Inbox;
 require PublicInbox::InboxWritable;
@@ -371,37 +371,7 @@ $ibx->with_umask(sub {
 }
 
 $ibx->with_umask(sub {
-       my $amsg = mime_load 't/search-amsg.eml', sub {
-       my $part1 = Email::MIME->create(
-                 attributes => {
-                     content_type => 'text/plain',
-                     disposition  => 'attachment',
-                     charset => 'US-ASCII',
-                    encoding => 'quoted-printable',
-                    filename => 'attached_fart.txt',
-                 },
-                 body_str => 'inside the attachment',
-       );
-       my $part2 = Email::MIME->create(
-                 attributes => {
-                     content_type => 'text/plain',
-                     disposition  => 'attachment',
-                     charset => 'US-ASCII',
-                    encoding => 'quoted-printable',
-                    filename => 'part_deux.txt',
-                 },
-                 body_str => 'inside another',
-       );
-       Email::MIME->create(
-               header_str => [
-                       Subject => 'see attachment',
-                       'Message-ID' => '<file@attached>',
-                       From => 'John Smith <js@example.com>',
-                       To => 'list@example.com',
-               ],
-               parts => [ $part1, $part2 ],
-       )}; # mime_load sub
-
+       my $amsg = mime_load 't/search-amsg.eml';
        ok($rw->add_message($amsg), 'added attachment');
        $rw_commit->();
        $ro->reopen;