From: Eric Wong <e@80x24.org> To: meta@public-inbox.org Subject: [PATCH 5/8] mbox_reader: add ->reads method to avoid nonsensical formats Date: Mon, 22 Mar 2021 07:53:59 +0000 [thread overview] Message-ID: <20210322075402.27834-6-e@80x24.org> (raw) In-Reply-To: <20210322075402.27834-1-e@80x24.org> Relying on UNIVERSAL::can may cause internal helper methods to be used, which can lead to failures or nonsensical results. --- lib/PublicInbox/InboxWritable.pm | 2 +- lib/PublicInbox/LeiImport.pm | 2 +- lib/PublicInbox/LeiInput.pm | 4 ++-- lib/PublicInbox/MboxReader.pm | 5 +++++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm index c2baeba6..eeebc485 100644 --- a/lib/PublicInbox/InboxWritable.pm +++ b/lib/PublicInbox/InboxWritable.pm @@ -172,7 +172,7 @@ sub _mbox_eml_cb { # MboxReader->mbox* callback sub import_mbox { my ($self, $fh, $variant) = @_; require PublicInbox::MboxReader; - my $cb = PublicInbox::MboxReader->can($variant) or + my $cb = PublicInbox::MboxReader->reads($variant) or die "$variant not supported\n"; my $im = $self->importer(1); $cb->(undef, $fh, \&_mbox_eml_cb, $im, $self->filter); diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index e769fba8..e587ada8 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -96,7 +96,7 @@ error reading $input: $! my $eml = PublicInbox::Eml->new(\$buf); _import_eml($eml, $lei, $kw); } else { # some mbox (->can already checked in call); - my $cb = PublicInbox::MboxReader->can($ifmt) // + my $cb = PublicInbox::MboxReader->reads($ifmt) // die "BUG: bad fmt=$ifmt"; $cb->(undef, $fh, \&_import_eml, $lei, $kw); } diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm index 89585a52..776b3151 100644 --- a/lib/PublicInbox/LeiInput.pm +++ b/lib/PublicInbox/LeiInput.pm @@ -18,7 +18,7 @@ sub check_input_format ($;$) { require PublicInbox::MboxReader; return 1 if $fmt eq 'eml'; # XXX: should this handle {gz,bz2,xz}? that's currently in LeiToMail - PublicInbox::MboxReader->can($fmt) or + PublicInbox::MboxReader->reads($fmt) or return $lei->fail("--$opt_key=$fmt unrecognized"); 1; } @@ -53,7 +53,7 @@ sub prepare_inputs { if (-f $input_path) { require PublicInbox::MboxLock; require PublicInbox::MboxReader; - PublicInbox::MboxReader->can($ifmt) or return + PublicInbox::MboxReader->reads($ifmt) or return $lei->fail("$ifmt not supported"); } elsif (-d _) { require PublicInbox::MdirReader; diff --git a/lib/PublicInbox/MboxReader.pm b/lib/PublicInbox/MboxReader.pm index f93c2ec6..6302d1fa 100644 --- a/lib/PublicInbox/MboxReader.pm +++ b/lib/PublicInbox/MboxReader.pm @@ -133,4 +133,9 @@ sub mboxcl2 { sub new { bless \(my $x), __PACKAGE__ } +sub reads { + my $ifmt = $_[-1]; + $ifmt =~ /\Ambox(?:rd|cl|cl2|o)\z/ ? __PACKAGE__->can($ifmt) : undef +} + 1;
next prev parent reply other threads:[~2021-03-22 7:54 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-22 7:53 [PATCH 0/8] lei input handling improvements Eric Wong 2021-03-22 7:53 ` [PATCH 1/8] lei: support -c <name>=<value> to overrides Eric Wong 2021-03-22 7:53 ` [PATCH 2/8] net_reader: escape nasty chars from Net::NNTP->message Eric Wong 2021-03-22 7:53 ` [PATCH 3/8] lei: share input code between convert and import Eric Wong 2021-03-22 7:53 ` [PATCH 4/8] lei: simplify workers_start and callers Eric Wong 2021-03-22 7:53 ` Eric Wong [this message] 2021-03-22 7:54 ` [PATCH 6/8] lei_input: common filehandle reader for eml + mbox Eric Wong 2021-03-22 7:54 ` [PATCH 7/8] lei_input: drop "From " line on single "eml" (message/rfc822) Eric Wong 2021-03-22 7:54 ` [PATCH 8/8] lei import: ignore Status headers in "eml" messages 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: https://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=20210322075402.27834-6-e@80x24.org \ --to=e@80x24.org \ --cc=meta@public-inbox.org \ --subject='Re: [PATCH 5/8] mbox_reader: add ->reads method to avoid nonsensical formats' \ /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
Code repositories for project(s) associated with this 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).