about summary refs log tree commit homepage
path: root/lib/PublicInbox/MDA.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-04-28 10:25:58 +0000
committerEric Wong <e@80x24.org>2014-04-28 10:25:58 +0000
commite7875ff77b4cd09831574cc4965e3f7012b81b89 (patch)
tree1256922c2aefcc74642b741992b9bc16c78be515 /lib/PublicInbox/MDA.pm
parentac958d1d52ce32f3ad2c5af134fb229153b26062 (diff)
downloadpublic-inbox-e7875ff77b4cd09831574cc4965e3f7012b81b89.tar.gz
This mimics functionality found in -learn.  Originally the design
allowed for only one address per-list, but when migrating/hijacking
existing mailing lists, having multiple addresses map to the same
inbox is useful.
Diffstat (limited to 'lib/PublicInbox/MDA.pm')
-rw-r--r--lib/PublicInbox/MDA.pm29
1 files changed, 16 insertions, 13 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;