about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/PublicInbox/MDA.pm29
-rwxr-xr-xpublic-inbox-mda4
-rw-r--r--t/precheck.t7
3 files changed, 22 insertions, 18 deletions
diff --git a/lib/PublicInbox/MDA.pm b/lib/PublicInbox/MDA.pm
index ed8d74da..ee4d0afe 100644
--- a/lib/PublicInbox/MDA.pm
+++ b/lib/PublicInbox/MDA.pm
@@ -18,7 +18,7 @@ sub __drop_plus {
 
 # do not allow Bcc, only Cc and To if recipient is set
 sub precheck {
-        my ($klass, $filter, $recipient) = @_;
+        my ($klass, $filter, $address) = @_;
         my $simple = $filter->simple;
         my $mid = $simple->header("Message-ID");
         return 0 unless usable_str(length('<m@h>'), $mid) && $mid =~ /\@/;
@@ -26,7 +26,7 @@ sub precheck {
         return 0 unless usable_str(length(':o'), $simple->header("Subject"));
         return 0 unless usable_date($simple->header("Date"));
         return 0 if length($simple->as_string) > MAX_SIZE;
-        recipient_specified($filter, $recipient);
+        alias_specified($filter, $address);
 }
 
 sub usable_str {
@@ -39,17 +39,20 @@ sub usable_date {
         scalar @t;
 }
 
-sub recipient_specified {
-        my ($filter, $recipient) = @_;
-        defined($recipient) or return 1; # for mass imports
-        my @recip = Email::Address->parse($recipient);
-        my $oaddr = __drop_plus($recip[0]->address);
-        $oaddr = qr/\b\Q$oaddr\E\b/i;
-        my @to = Email::Address->parse($filter->to);
-        my @cc = Email::Address->parse($filter->cc);
-        foreach my $addr (@to, @cc) {
-                if (__drop_plus($addr->address) =~ $oaddr) {
-                        return 1;
+sub alias_specified {
+        my ($filter, $address) = @_;
+
+        my @address = ref($address) eq 'ARRAY' ? @$address : ($address);
+        my %ok = map {
+                my @recip = Email::Address->parse($_);
+                lc(__drop_plus($recip[0]->address)) => 1;
+        } @address;
+
+        foreach my $line ($filter->cc, $filter->to) {
+                foreach my $addr (Email::Address->parse($line)) {
+                        if ($ok{lc(__drop_plus($addr->address))}) {
+                                return 1;
+                        }
                 }
         }
         return 0;
diff --git a/public-inbox-mda b/public-inbox-mda
index 50805da2..096421bb 100755
--- a/public-inbox-mda
+++ b/public-inbox-mda
@@ -26,12 +26,12 @@ my $config = PublicInbox::Config->new;
 
 my $recipient = $ENV{ORIGINAL_RECIPIENT};
 defined $recipient or die "ORIGINAL_RECIPIENT not defined in ENV\n";
-my $dst = $config->lookup($recipient);
+my $dst = $config->lookup($recipient); # first check
 defined $dst or exit(1);
 my $main_repo = $dst->{mainrepo} or exit(1);
 my $filtered; # string dest
 
-if (PublicInbox::MDA->precheck($filter, $recipient) &&
+if (PublicInbox::MDA->precheck($filter, $dst->{address}) &&
     do_spamc($filter->simple, \$filtered)) {
         # update our message with SA headers (in case our filter rejects it)
         my $msg = Email::Simple->new($filtered);
diff --git a/t/precheck.t b/t/precheck.t
index 974d6a38..89564097 100644
--- a/t/precheck.t
+++ b/t/precheck.t
@@ -12,9 +12,6 @@ sub do_checks {
 
         my $f = Email::Filter->new(data => $s->as_string);
 
-        ok(PublicInbox::MDA->precheck($f, undef),
-                "ORIGINAL_RECIPIENT unset is OK");
-
         my $recipient = 'foo@example.com';
         ok(!PublicInbox::MDA->precheck($f, $recipient),
                 "wrong ORIGINAL_RECIPIENT rejected");
@@ -26,6 +23,10 @@ sub do_checks {
         $recipient = 'c@example.com';
         ok(PublicInbox::MDA->precheck($f, $recipient),
                 "ORIGINAL_RECIPIENT in Cc: is OK");
+
+        $recipient = [ 'c@example.com', 'd@example.com' ];
+        ok(PublicInbox::MDA->precheck($f, $recipient),
+                "alias list is OK");
 }
 
 {