From 9787fae1f7235bd790d1db6f0b513ce420c361bd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 16 May 2020 22:53:53 +0000 Subject: confine Email::MIME use even further To avoid confusing future readers and users, recommend PublicInbox::Eml in our Import POD and refer to PublicInbox::Eml comments at the top of PublicInbox::MIME. mime_load() confined to t/eml.t, since we won't be using it anywhere else in our tests. --- lib/PublicInbox/Import.pm | 22 +++++++++++++--------- lib/PublicInbox/MIME.pm | 4 +++- lib/PublicInbox/TestCommon.pm | 10 +--------- 3 files changed, 17 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index fc61d062..792570c8 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -648,7 +648,10 @@ version 1.0 =head1 SYNOPSIS - use Email::MIME; + use PublicInbox::Eml; + # PublicInbox::Eml exists as of public-inbox 1.5.0, + # Email::MIME was used in older versions + use PublicInbox::Git; use PublicInbox::Import; @@ -664,7 +667,7 @@ version 1.0 "Date: Thu, 01 Jan 1970 00:00:00 +0000\n" . "Message-ID: \n". "\ntest message"; - my $parsed = Email::MIME->new($message); + my $parsed = PublicInbox::Eml->new($message); my $ret = $im->add($parsed); if (!defined $ret) { warn "duplicate: ", @@ -675,7 +678,7 @@ version 1.0 $im->done; # to remove a message - my $junk = Email::MIME->new($message); + my $junk = PublicInbox::Eml->new($message); my ($mark, $orig) = $im->remove($junk); if ($mark eq 'MISSING') { print "not found\n"; @@ -690,8 +693,8 @@ version 1.0 =head1 DESCRIPTION -An importer and remover for public-inboxes which takes L -messages as input and stores them in a git repository as +An importer and remover for public-inboxes which takes C +or L messages as input and stores them in a git repository as documented in L, except it does not allow duplicate Message-IDs. @@ -709,7 +712,7 @@ Initialize a new PublicInbox::Import object. =head2 add - my $parsed = Email::MIME->new($message); + my $parsed = PublicInbox::Eml->new($message); $im->add($parsed); Adds a message to to the git repository. This will acquire @@ -720,12 +723,13 @@ is called, but L may be called on them. =head2 remove - my $junk = Email::MIME->new($message); + my $junk = PublicInbox::Eml->new($message); my ($code, $orig) = $im->remove($junk); Removes a message from the repository. On success, it returns a ':'-prefixed numeric code representing the git-fast-import -mark and the original messages as an Email::MIME object. +mark and the original messages as a PublicInbox::Eml +(or Email::MIME) object. If the message could not be found, the code is "MISSING" and the original message is undef. If there is a mismatch where the "Message-ID" is matched but the subject and body do not match, @@ -749,7 +753,7 @@ The mail archives are hosted at L =head1 COPYRIGHT -Copyright (C) 2016 all contributors L +Copyright (C) 2016-2020 all contributors L License: AGPL-3.0+ L diff --git a/lib/PublicInbox/MIME.pm b/lib/PublicInbox/MIME.pm index 9077386a..831a3d19 100644 --- a/lib/PublicInbox/MIME.pm +++ b/lib/PublicInbox/MIME.pm @@ -4,7 +4,9 @@ # The license for this file differs from the rest of public-inbox. # # We no longer load this in any of our code outside of maintainer -# tests for compatibility. +# tests for compatibility. PublicInbox::Eml is favored throughout +# our codebase for performance and safety reasons, though we maintain +# Email::MIME-compatibility in mail injection and indexing code paths. # # It monkey patches the "parts_multipart" subroutine with patches # from Matthew Horsfall at: diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index d952ee6d..79e597f5 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -9,15 +9,7 @@ use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek); use POSIX qw(dup2); 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 eml_load); - -sub mime_load ($) { - my ($path) = @_; - open(my $fh, '<', $path) or die "open $path: $!"; - # test should've called: require_mods('Email::MIME') - require PublicInbox::MIME; - PublicInbox::MIME->new(\(do { local $/; <$fh> })); -} + run_script start_script key2sub xsys xqx eml_load); sub eml_load ($) { my ($path, $cb) = @_; -- cgit v1.2.3-24-ge0c7