From 0f6b0cac5bf10d036a84dbab732e8991edf56c34 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 18 Apr 2020 03:38:46 +0000 Subject: inboxwritable: mime_from_path: reuse in more places There's nothing Maildir-specific about the function, so `maildir_path_load' was a bad name. So give it a more appropriate name and use it in our tests. This save ourselves some code and inconsistency by reusing an existing internal library routine in more places. We can drop the "From_" line in some of our (formerly) mbox sample files. --- t/iso-2202-jp.eml | 9 +++++++++ t/iso-2202-jp.mbox | 10 ---------- t/mda.t | 10 ++++------ t/msg_iter.t | 18 ++++++------------ t/nntpd-tls.t | 8 +++----- t/search.t | 12 ++++-------- t/solver_git.t | 4 ++-- t/utf8.eml | 11 +++++++++++ t/utf8.mbox | 12 ------------ 9 files changed, 39 insertions(+), 55 deletions(-) create mode 100644 t/iso-2202-jp.eml delete mode 100644 t/iso-2202-jp.mbox create mode 100644 t/utf8.eml delete mode 100644 t/utf8.mbox (limited to 't') diff --git a/t/iso-2202-jp.eml b/t/iso-2202-jp.eml new file mode 100644 index 00000000..9e0bbad4 --- /dev/null +++ b/t/iso-2202-jp.eml @@ -0,0 +1,9 @@ +Message-Id: <199707281508.AAA24167@hoyogw.example> +Date: Tue, 29 Jul 97 00:08:29 +0900 +From: matz@example.com +Subject: [ruby-dev:4] +To: ruby-dev@example +Mime-Version: 1.0 +Content-Type: text/plain; charset=ISO-2022-JP + +|$B$1$$$8$e!w:#$O%U%j!<(B(^^;;;$B$G$9(B. diff --git a/t/iso-2202-jp.mbox b/t/iso-2202-jp.mbox deleted file mode 100644 index 1a8e1974..00000000 --- a/t/iso-2202-jp.mbox +++ /dev/null @@ -1,10 +0,0 @@ -From historical@ruby-dev Thu Jan 1 00:00:00 1970 -Message-Id: <199707281508.AAA24167@hoyogw.example> -Date: Tue, 29 Jul 97 00:08:29 +0900 -From: matz@example.com -Subject: [ruby-dev:4] -To: ruby-dev@example -Mime-Version: 1.0 -Content-Type: text/plain; charset=ISO-2022-JP - -|$B$1$$$8$e!w:#$O%U%j!<(B(^^;;;$B$G$9(B. diff --git a/t/mda.t b/t/mda.t index ddc0c279..ec09cf69 100644 --- a/t/mda.t +++ b/t/mda.t @@ -7,6 +7,7 @@ use Email::MIME; use Cwd qw(getcwd); use PublicInbox::MID qw(mid2path); use PublicInbox::Git; +use PublicInbox::InboxWritable; use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); my $home = "$tmpdir/pi-home"; @@ -62,12 +63,9 @@ local $ENV{GIT_COMMITTER_NAME} = eval { use PublicInbox::MDA; use PublicInbox::Address; use Encode qw/encode/; - my $mbox = 't/utf8.mbox'; - open(my $fh, '<', $mbox) or die "failed to open mbox: $mbox\n"; - my $str = eval { local $/; <$fh> }; - close $fh; - my $msg = Email::MIME->new($str); - + my $eml = 't/utf8.eml'; + my $msg = PublicInbox::InboxWritable::mime_from_path($eml) or + die "failed to open $eml: $!"; my $from = $msg->header('From'); my ($author) = PublicInbox::Address::names($from); my ($email) = PublicInbox::Address::emails($from); diff --git a/t/msg_iter.t b/t/msg_iter.t index d303564f..573ee412 100644 --- a/t/msg_iter.t +++ b/t/msg_iter.t @@ -5,6 +5,7 @@ use warnings; use Test::More; use Email::MIME; use PublicInbox::Hval qw(ascii_html); +use PublicInbox::InboxWritable; use_ok('PublicInbox::MsgIter'); { @@ -42,12 +43,9 @@ use_ok('PublicInbox::MsgIter'); } { - my $f = 't/iso-2202-jp.mbox'; - my $mime = Email::MIME->new(do { - open my $fh, '<', $f or die "open($f): $!"; - local $/; - <$fh>; - }); + my $f = 't/iso-2202-jp.eml'; + my $mime = PublicInbox::InboxWritable::mime_from_path($f) or + die "open $f: $!"; my $raw = ''; msg_iter($mime, sub { my ($part, $level, @ex) = @{$_[0]}; @@ -61,12 +59,8 @@ use_ok('PublicInbox::MsgIter'); { my $f = 't/x-unknown-alpine.eml'; - my $mime = Email::MIME->new(do { - open my $fh, '<', $f or die "open($f): $!"; - local $/; - binmode $fh; - <$fh>; - }); + my $mime = PublicInbox::InboxWritable::mime_from_path($f) or + die "open $f: $!"; my $raw = ''; msg_iter($mime, sub { my ($part, $level, @ex) = @{$_[0]}; diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t index 0714631d..a0522e1f 100644 --- a/t/nntpd-tls.t +++ b/t/nntpd-tls.t @@ -63,11 +63,9 @@ EOF { my $im = $ibx->importer(0); - my $mime = PublicInbox::MIME->new(do { - open my $fh, '<', 't/data/0001.patch' or die; - local $/; - <$fh> - }); + my $eml = 't/data/0001.patch'; + my $mime = PublicInbox::InboxWritable::mime_from_path($eml) or + die "open $eml: $!"; ok($im->add($mime), 'message added'); $im->done; if ($version == 1) { diff --git a/t/search.t b/t/search.t index 839a320a..101d44e9 100644 --- a/t/search.t +++ b/t/search.t @@ -7,6 +7,7 @@ use PublicInbox::TestCommon; require_mods(qw(DBD::SQLite Search::Xapian)); require PublicInbox::SearchIdx; require PublicInbox::Inbox; +require PublicInbox::InboxWritable; use Email::MIME; my ($tmpdir, $for_destroy) = tmpdir(); my $git_dir = "$tmpdir/a.git"; @@ -290,14 +291,9 @@ $ibx->with_umask(sub { }); $ibx->with_umask(sub { - my $str = eval { - my $mbox = 't/utf8.mbox'; - open(my $fh, '<', $mbox) or die "failed to open mbox: $mbox\n"; - local $/; - <$fh> - }; - $str =~ s/\AFrom [^\n]+\n//s; - my $mime = Email::MIME->new($str); + my $eml = 't/utf8.eml'; + my $mime = PublicInbox::InboxWritable::mime_from_path($eml) or + die "open $eml: $!"; my $doc_id = $rw->add_message($mime); ok($doc_id > 0, 'message indexed doc_id with UTF-8'); my $msg = $rw->query('m:testmessage@example.com', {limit => 1})->[0]; diff --git a/t/solver_git.t b/t/solver_git.t index 2dbb07b0..7f0cd999 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -28,8 +28,8 @@ my $im = PublicInbox::V2Writable->new($ibx, 1); $im->{parallel} = 0; my $deliver_patch = sub ($) { - open my $fh, '<', $_[0] or die "open: $!"; - my $mime = PublicInbox::MIME->new(do { local $/; <$fh> }); + my $mime = PublicInbox::InboxWritable::mime_from_path($_[0]) or + die "open $_[0]: $!"; $im->add($mime); $im->done; }; diff --git a/t/utf8.eml b/t/utf8.eml new file mode 100644 index 00000000..9bf1002c --- /dev/null +++ b/t/utf8.eml @@ -0,0 +1,11 @@ +Date: Thu, 01 Jan 1970 00:00:00 +0000 +To: =?utf-8?Q?El=C3=A9anor?= +From: =?utf-8?Q?El=C3=A9anor?= +Subject: Testing for =?utf-8?Q?El=C3=A9anor?= +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit + +This is a test message for Eléanor diff --git a/t/utf8.mbox b/t/utf8.mbox deleted file mode 100644 index cebaf9b0..00000000 --- a/t/utf8.mbox +++ /dev/null @@ -1,12 +0,0 @@ -From e@yhbt.net Thu Jan 01 00:00:00 1970 -Date: Thu, 01 Jan 1970 00:00:00 +0000 -To: =?utf-8?Q?El=C3=A9anor?= -From: =?utf-8?Q?El=C3=A9anor?= -Subject: Testing for =?utf-8?Q?El=C3=A9anor?= -Message-ID: -MIME-Version: 1.0 -Content-Type: text/plain; charset=utf-8 -Content-Disposition: inline -Content-Transfer-Encoding: 8bit - -This is a test message for Eléanor -- cgit v1.2.3-24-ge0c7