]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox.pm
reject messages if ORIGINAL_RECIPIENT is not specified
[public-inbox.git] / lib / PublicInbox.pm
1 # Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 package PublicInbox;
4 use strict;
5 use warnings;
6 use Email::Address;
7
8 # drop plus addressing for matching
9 sub __drop_plus {
10         my ($str_addr) = @_;
11         $str_addr =~ s/\+.*\@/\@/;
12         $str_addr;
13 }
14
15 # do not allow Bcc, only Cc and To if ORIGINAL_RECIPIENT (postfix) env is set
16 sub recipient_specified {
17         my ($klass, $filter) = @_;
18         my $or = $ENV{ORIGINAL_RECIPIENT};
19         defined($or) or return 1; # for imports
20         my @or = Email::Address->parse($or);
21         my $oaddr = __drop_plus($or[0]->address);
22         $oaddr = qr/\b\Q$oaddr\E\b/i;
23         my @to = Email::Address->parse($filter->to);
24         my @cc = Email::Address->parse($filter->cc);
25         foreach my $addr (@to, @cc) {
26                 if (__drop_plus($addr->address) =~ $oaddr) {
27                         return 1;
28                 }
29         }
30         return 0;
31 }
32
33 1;