]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox.pm
initial cut at Atom feed generation
[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 use constant MAX_SIZE => 1024 * 500; # same as spamc default
8
9 # drop plus addressing for matching
10 sub __drop_plus {
11         my ($str_addr) = @_;
12         $str_addr =~ s/\+.*\@/\@/;
13         $str_addr;
14 }
15
16 # do not allow Bcc, only Cc and To if ORIGINAL_RECIPIENT (postfix) env is set
17 sub precheck {
18         my ($klass, $filter) = @_;
19         my $simple = $filter->simple;
20         return 0 unless $simple->header("Message-ID");
21         return 0 unless defined($filter->from);
22         return 0 if length($simple->as_string) > MAX_SIZE;
23         recipient_specified($filter);
24 }
25
26 sub recipient_specified {
27         my ($filter) = @_;
28         my $or = $ENV{ORIGINAL_RECIPIENT};
29         defined($or) or return 1; # for imports
30         my @or = Email::Address->parse($or);
31         my $oaddr = __drop_plus($or[0]->address);
32         $oaddr = qr/\b\Q$oaddr\E\b/i;
33         my @to = Email::Address->parse($filter->to);
34         my @cc = Email::Address->parse($filter->cc);
35         foreach my $addr (@to, @cc) {
36                 if (__drop_plus($addr->address) =~ $oaddr) {
37                         return 1;
38                 }
39         }
40         return 0;
41 }
42
43 1;