# 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 =~ /\@/;
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 {
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;
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);
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");
$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");
}
{