use strict;
use warnings;
use Email::Address;
+use Date::Parse qw(strptime);
use constant MAX_SIZE => 1024 * 500; # same as spamc default
# drop plus addressing for matching
sub precheck {
my ($klass, $filter, $recipient) = @_;
my $simple = $filter->simple;
- return 0 unless $simple->header("Message-ID");
- return 0 unless defined($filter->from);
- return 0 unless $simple->header("Subject");
+ my $mid = $simple->header("Message-ID");
+ return 0 unless usable_str(length('<m@h>'), $mid) && $mid =~ /\@/;
+ return 0 unless usable_str(length('u@h'), $filter->from);
+ 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);
}
+sub usable_str {
+ my ($len, $str) = @_;
+ defined($str) && length($str) >= $len;
+}
+
+sub usable_date {
+ my @t = eval { strptime(@_) };
+ scalar @t;
+}
+
sub recipient_specified {
my ($filter, $recipient) = @_;
defined($recipient) or return 1; # for mass imports
Cc => 'c@example.com',
'Content-Type' => 'text/plain',
Subject => 'this is a subject',
- 'Message-ID' => '<MID>',
+ 'Message-ID' => '<MID@host>',
+ Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
],
body => "hello world\n",
));
Cc => 'John Doe <c@example.com>',
'Content-Type' => 'text/plain',
Subject => 'this is a subject',
- 'Message-ID' => '<MID>',
+ 'Message-ID' => '<MID@host>',
+ Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
],
body => "hello world\n",
));
Cc => 'c@example.com',
'Content-Type' => 'text/plain',
Subject => 'this is a subject',
- 'Message-ID' => '<MID>',
+ 'Message-ID' => '<MID@host>',
+ Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
],
body => "hello world\n",
);