1 # Copyright (C) 2013-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # For the -mda script (mail delivery agent)
5 package PublicInbox::MDA;
9 use Date::Parse qw(strptime);
10 use constant MAX_SIZE => 1024 * 500; # same as spamc default, should be tunable
11 use constant MAX_MID_SIZE => 244; # max term size - 1 in Xapian
15 qw(delivered-to x-original-to), # prevent training loops
17 # The rest are taken from Mailman 2.1.15:
18 # could contain passwords:
19 qw(approved approve x-approved x-approve urgent),
20 # could be used phishing:
21 qw(return-receipt-to disposition-notification-to x-confirm-reading-to),
26 # drop plus addressing for matching
29 $str_addr =~ s/\+.*\@/\@/;
33 # do not allow Bcc, only Cc and To if recipient is set
35 my ($klass, $simple, $address) = @_;
36 my @mid = $simple->header('Message-ID');
37 return 0 if scalar(@mid) != 1;
39 return 0 if (length($mid) > MAX_MID_SIZE);
40 return 0 unless usable_str(length('<m@h>'), $mid) && $mid =~ /\@/;
41 return 0 unless usable_str(length('u@h'), $simple->header("From"));
42 return 0 unless usable_str(length(':o'), $simple->header("Subject"));
43 return 0 unless usable_date($simple->header("Date"));
44 return 0 if length($simple->as_string) > MAX_SIZE;
45 alias_specified($simple, $address);
50 defined($str) && length($str) >= $len;
54 my @t = eval { strptime(@_) };
59 my ($simple, $address) = @_;
61 my @address = ref($address) eq 'ARRAY' ? @$address : ($address);
63 lc(__drop_plus($_)) => 1;
66 foreach my $line ($simple->header('Cc'), $simple->header('To')) {
67 my @addrs = ($line =~ /([^,<\s]+\@[^,>\s]+)/g);
68 foreach my $addr (@addrs) {
69 if ($ok{lc(__drop_plus($addr))}) {
77 sub set_list_headers {
78 my ($class, $simple, $dst) = @_;
79 unless (defined $simple->header('List-Id')) {
80 my $pa = $dst->{-primary_address};
81 $pa =~ tr/@/./; # RFC2919
82 $simple->header_set("List-Id", "<$pa>");