From d1525c3b35e9aa1bb14143996a7fa2b6e34cba3e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 28 Oct 2019 10:45:20 +0000 Subject: mda: hoist out List-ID handling and reuse in -learn It's now possible to inject false-positive ham into an inbox the same way -mda does via List-ID. --- lib/PublicInbox/MDA.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/PublicInbox/MDA.pm b/lib/PublicInbox/MDA.pm index 9cafda13..ce2c870f 100644 --- a/lib/PublicInbox/MDA.pm +++ b/lib/PublicInbox/MDA.pm @@ -83,4 +83,19 @@ sub set_list_headers { } } +# TODO: deal with multiple List-ID headers? +sub inbox_for_list_id ($$) { + my ($klass, $config, $simple) = @_; + + # newer Email::Simple allows header_raw, as does Email::MIME: + my $list_id = $simple->can('header_raw') ? + $simple->header_raw('List-Id') : + $simple->header('List-Id'); + my $ibx; + if (defined $list_id && $list_id =~ /<[ \t]*(.+)?[ \t]*>/) { + $ibx = $config->lookup_list_id($1); + } + $ibx; +} + 1; -- cgit v1.2.3-24-ge0c7 From 84d811cfb3a0c8724c52ce485402e4586d5c9e04 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 28 Oct 2019 10:45:21 +0000 Subject: filter/base: remove MAX_MID_SIZE constant We don't need it in the filter, here, since we have one in the MDA package. --- lib/PublicInbox/Filter/Base.pm | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/PublicInbox/Filter/Base.pm b/lib/PublicInbox/Filter/Base.pm index 052cd332..7a0c720f 100644 --- a/lib/PublicInbox/Filter/Base.pm +++ b/lib/PublicInbox/Filter/Base.pm @@ -6,7 +6,6 @@ package PublicInbox::Filter::Base; use strict; use warnings; use PublicInbox::MsgIter; -use constant MAX_MID_SIZE => 244; # max term size - 1 in Xapian sub No ($) { "*** We only accept plain-text mail, No $_[0] ***" } -- cgit v1.2.3-24-ge0c7 From 6c559dae69e244895fd7e6c5a9ae29f58d03058e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 28 Oct 2019 10:45:24 +0000 Subject: inboxwritable: add assert_usable_dir sub And use it for mda, since "0" could be a usable directory if somebody insists on using relative paths... --- lib/PublicInbox/InboxWritable.pm | 9 ++++++++- lib/PublicInbox/V2Writable.pm | 5 ++--- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm index ab7b0ed5..9eab394d 100644 --- a/lib/PublicInbox/InboxWritable.pm +++ b/lib/PublicInbox/InboxWritable.pm @@ -30,12 +30,19 @@ sub new { $self; } +sub assert_usable_dir { + my ($self) = @_; + my $dir = $self->{inboxdir}; + return $dir if defined($dir) && $dir ne ''; + die "no inboxdir defined for $self->{name}\n"; +} + sub init_inbox { my ($self, $shards, $skip_epoch, $skip_artnum) = @_; # TODO: honor skip_artnum my $v = $self->{version} || 1; if ($v == 1) { - my $dir = $self->{inboxdir} or die "no inboxdir in inbox\n"; + my $dir = assert_usable_dir($self); PublicInbox::Import::init_bare($dir); } else { my $v2w = importer($self); diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index ad2e8e62..1825da2c 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -77,7 +77,8 @@ sub new { # $creat may be any true value, or 0/undef. A hashref is true, # and $creat->{nproc} may be set to an integer my ($class, $v2ibx, $creat) = @_; - my $dir = $v2ibx->{inboxdir} or die "no inboxdir in inbox\n"; + $v2ibx = PublicInbox::InboxWritable->new($v2ibx); + my $dir = $v2ibx->assert_usable_dir; unless (-d $dir) { if ($creat) { require File::Path; @@ -86,8 +87,6 @@ sub new { die "$dir does not exist\n"; } } - - $v2ibx = PublicInbox::InboxWritable->new($v2ibx); $v2ibx->umask_prepare; my $xpfx = "$dir/xap" . PublicInbox::Search::SCHEMA_VERSION; -- cgit v1.2.3-24-ge0c7 From 74a3206babe0572a1494500d21267a31873af7b0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 28 Oct 2019 10:45:26 +0000 Subject: mda: support multiple List-ID matches While it's not RFC2919-conformant, mail software can theoretically set multiple List-ID headers. Deliver to all inboxes which match a given List-ID since that's likely the intended. Cc: Eric W. Biederman Link: https://public-inbox.org/meta/87pniltscf.fsf@x220.int.ebiederm.org/ --- lib/PublicInbox/MDA.pm | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/MDA.pm b/lib/PublicInbox/MDA.pm index ce2c870f..b0dfac45 100644 --- a/lib/PublicInbox/MDA.pm +++ b/lib/PublicInbox/MDA.pm @@ -83,19 +83,25 @@ sub set_list_headers { } } -# TODO: deal with multiple List-ID headers? -sub inbox_for_list_id ($$) { +sub inboxes_for_list_id ($$) { my ($klass, $config, $simple) = @_; # newer Email::Simple allows header_raw, as does Email::MIME: - my $list_id = $simple->can('header_raw') ? + my @list_ids = $simple->can('header_raw') ? $simple->header_raw('List-Id') : $simple->header('List-Id'); - my $ibx; - if (defined $list_id && $list_id =~ /<[ \t]*(.+)?[ \t]*>/) { - $ibx = $config->lookup_list_id($1); + my @dests; + for my $list_id (@list_ids) { + $list_id =~ /<[ \t]*(.+)?[ \t]*>/ or next; + if (my $ibx = $config->lookup_list_id($1)) { + push @dests, $ibx; + } + } + if (scalar(@list_ids) > 1) { + warn "W: multiple List-IDs in message:\n"; + warn "W: List-ID: $_\n" for @list_ids } - $ibx; + \@dests; } 1; -- cgit v1.2.3-24-ge0c7