about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-01-10 23:50:16 +0000
committerEric Wong <e@80x24.org>2014-01-10 23:50:16 +0000
commitbf4630c098ad7159ba36dea6cfe77c4cf6806ffe (patch)
treefe3cedc95cc5376a4eeab337da1b9aa93ae76759 /lib
parentef262d1b0139fbb56b7089a3c921087651ffa46a (diff)
downloadpublic-inbox-bf4630c098ad7159ba36dea6cfe77c4cf6806ffe.tar.gz
SpamAssassin doesn't seem to have this heuristic, but the lack of
the intended email address in To:/Cc: headers cannot be a good
sign (especially when this is a _public_ inbox).
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox.pm33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/PublicInbox.pm b/lib/PublicInbox.pm
new file mode 100644
index 00000000..b51c000f
--- /dev/null
+++ b/lib/PublicInbox.pm
@@ -0,0 +1,33 @@
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
+# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+package PublicInbox;
+use strict;
+use warnings;
+use Email::Address;
+
+# drop plus addressing for matching
+sub __drop_plus {
+        my ($str_addr) = @_;
+        $str_addr =~ s/\+.*\@/\@/;
+        $str_addr;
+}
+
+# do not allow Bcc, only Cc and To if ORIGINAL_RECIPIENT (postfix) env is set
+sub recipient_specified {
+        my ($klass, $filter) = @_;
+        my $or = $ENV{ORIGINAL_RECIPIENT};
+        defined($or) or return 1; # for imports
+        my @or = Email::Address->parse($or);
+        my $oaddr = __drop_plus($or[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;
+                }
+        }
+        return 0;
+}
+
+1;