From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id F17ED1F4C5 for ; Mon, 21 Oct 2019 11:22:29 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/7] watchmaildir: remove redundant _path_to_mime Date: Mon, 21 Oct 2019 11:22:26 +0000 Message-Id: <20191021112229.3029-5-e@80x24.org> In-Reply-To: <20191021112229.3029-1-e@80x24.org> References: <20191021112229.3029-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: InboxWritable::maildir_path_load exists and we may support it for use with standalone scripts. --- lib/PublicInbox/WatchMaildir.pm | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index 08b1aab4..e9231780 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -13,6 +13,7 @@ use File::Temp qw//; use PublicInbox::Filter::Base; use PublicInbox::Spamcheck; *REJECT = *PublicInbox::Filter::Base::REJECT; +*maildir_path_load = *PublicInbox::InboxWritable::maildir_path_load; sub new { my ($class, $config) = @_; @@ -124,7 +125,7 @@ sub _remove_spam { my ($self, $path) = @_; # path must be marked as (S)een $path =~ /:2,[A-R]*S[T-Za-z]*\z/ or return; - my $mime = _path_to_mime($path) or return; + my $mime = maildir_path_load($path) or return; $self->{config}->each_inbox(sub { my ($ibx) = @_; eval { @@ -166,7 +167,7 @@ sub _try_path { $warn_cb->(@_); }; foreach my $ibx (@$inboxes) { - my $mime = _path_to_mime($path) or next; + my $mime = maildir_path_load($path) or next; my $im = _importer_for($self, $ibx); # any header match means it's eligible for the inbox: @@ -259,21 +260,6 @@ sub scan { trigger_scan($self, 'cont') if keys %$opendirs; } -sub _path_to_mime { - my ($path) = @_; - if (open my $fh, '<', $path) { - local $/; - my $str = <$fh>; - $str or return; - return PublicInbox::MIME->new(\$str); - } elsif ($!{ENOENT}) { - return; - } else { - warn "failed to open $path: $!\n"; - return; - } -} - sub _importer_for { my ($self, $ibx) = @_; my $importers = $self->{importers};