user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 2/3] tests: remove Email::MIME->create use entirely
Date: Sat, 25 Apr 2020 05:52:22 +0000	[thread overview]
Message-ID: <20200425055223.21879-3-e@yhbt.net> (raw)
In-Reply-To: <20200425055223.21879-1-e@yhbt.net>

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.
---
 MANIFEST                      | 12 ++++++++
 lib/PublicInbox/TestCommon.pm | 23 ++------------
 t/filter_base-junk.eml        | 19 ++++++++++++
 t/filter_base-xhtml.eml       | 19 ++++++++++++
 t/filter_base.t               | 53 ++------------------------------
 t/filter_mirror.t             | 27 +----------------
 t/mda-mime.eml                | 21 +++++++++++++
 t/mda.t                       | 34 ++-------------------
 t/msg_iter-nested.eml         | 26 ++++++++++++++++
 t/msg_iter-order.eml          | 16 ++++++++++
 t/msg_iter.t                  | 17 ++---------
 t/plack-2-txt-bodies.eml      | 17 +++++++++++
 t/plack-attached-patch.eml    | 20 ++++++++++++
 t/plack-qp.eml                |  8 +++++
 t/plack.t                     | 57 ++---------------------------------
 t/psgi_attach.eml             | 38 +++++++++++++++++++++++
 t/psgi_attach.t               | 37 +----------------------
 t/psgi_v2-new.eml             | 17 +++++++++++
 t/psgi_v2-old.eml             | 17 +++++++++++
 t/psgi_v2.t                   | 23 ++------------
 t/search-amsg.eml             | 23 ++++++++++++++
 t/search.t                    | 34 ++-------------------
 22 files changed, 271 insertions(+), 287 deletions(-)
 create mode 100644 t/filter_base-junk.eml
 create mode 100644 t/filter_base-xhtml.eml
 create mode 100644 t/mda-mime.eml
 create mode 100644 t/msg_iter-nested.eml
 create mode 100644 t/msg_iter-order.eml
 create mode 100644 t/plack-2-txt-bodies.eml
 create mode 100644 t/plack-attached-patch.eml
 create mode 100644 t/plack-qp.eml
 create mode 100644 t/psgi_attach.eml
 create mode 100644 t/psgi_v2-new.eml
 create mode 100644 t/psgi_v2-old.eml
 create mode 100644 t/search-amsg.eml

diff --git a/MANIFEST b/MANIFEST
index b06aa679..e3e0f2a8 100644
--- 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
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index ac14d27b..27390ab2 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -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
index 00000000..4733bbe5
--- /dev/null
+++ b/t/filter_base-junk.eml
@@ -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
index 00000000..d13a11cd
--- /dev/null
+++ b/t/filter_base-xhtml.eml
@@ -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--
diff --git a/t/filter_base.t b/t/filter_base.t
index 7919dd65..bbd64189 100644
--- a/t/filter_base.t
+++ b/t/filter_base.t
@@ -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');
 }
 
diff --git a/t/filter_mirror.t b/t/filter_mirror.t
index 694209d9..0e641a03 100644
--- a/t/filter_mirror.t
+++ b/t/filter_mirror.t
@@ -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
index 00000000..64a92816
--- /dev/null
+++ b/t/mda-mime.eml
@@ -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 5457f17f..863eaf8f 100644
--- 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
index 00000000..08d0adac
--- /dev/null
+++ b/t/msg_iter-nested.eml
@@ -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
index 00000000..153af800
--- /dev/null
+++ b/t/msg_iter-order.eml
@@ -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--
diff --git a/t/msg_iter.t b/t/msg_iter.t
index ac2066a2..6adbf165 100644
--- a/t/msg_iter.t
+++ b/t/msg_iter.t
@@ -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
index 00000000..a06cd688
--- /dev/null
+++ b/t/plack-2-txt-bodies.eml
@@ -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
index 00000000..bc6d295d
--- /dev/null
+++ b/t/plack-attached-patch.eml
@@ -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
index 00000000..d9008c8e
--- /dev/null
+++ b/t/plack-qp.eml
@@ -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=
diff --git a/t/plack.t b/t/plack.t
index d45dbcd2..4fff9773 100644
--- 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
index 00000000..cfa3622c
--- /dev/null
+++ b/t/psgi_attach.eml
@@ -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--
diff --git a/t/psgi_attach.t b/t/psgi_attach.t
index 0dde9323..af0fbdd3 100644
--- a/t/psgi_attach.t
+++ b/t/psgi_attach.t
@@ -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
index 00000000..2c264714
--- /dev/null
+++ b/t/psgi_v2-new.eml
@@ -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
index 00000000..f82dbf2f
--- /dev/null
+++ b/t/psgi_v2-old.eml
@@ -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--
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 5d212ca6..9c19b041 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -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
index 00000000..c87c0f15
--- /dev/null
+++ b/t/search-amsg.eml
@@ -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--
diff --git a/t/search.t b/t/search.t
index 0301fd90..40264345 100644
--- a/t/search.t
+++ b/t/search.t
@@ -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;

  parent reply	other threads:[~2020-04-25  5:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-25  5:52 [PATCH 0/3] remove Email::MIME->create use Eric Wong
2020-04-25  5:52 ` [PATCH 1/3] testcommon: introduce mime_load sub Eric Wong
2020-04-25  5:52 ` Eric Wong [this message]
2020-04-25  5:52 ` [PATCH 3/3] tests: replace mime_from_path with mime_load Eric Wong
2020-04-26  7:35 ` [PATCH 4/3] testcommon: mime_load: drop extra $cb arg Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200425055223.21879-3-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).