use Email::Filter;
use IPC::Run;
our $VERSION = '0.0.1';
+use constant NO_HTML => '*** We only accept plain-text email, no HTML ***';
# start with the same defaults as mailman
our $BAD_EXT = qr/\.(?:exe|bat|cmd|com|pif|scr|vbs|cpl)\z/i;
# this is highly opinionated delivery
# returns 0 only if there is nothing to deliver
sub run {
- my ($class, $mime) = @_;
+ my ($class, $mime, $filter) = @_;
my $content_type = $mime->header('Content-Type') || 'text/plain';
if ($content_type =~ m!\btext/plain\b!i) {
return 1; # yay, nothing to do
} elsif ($content_type =~ $MIME_HTML) {
+ $filter->reject(NO_HTML) if $filter;
# HTML-only, non-multipart
my $body = $mime->body;
my $ct_parsed = parse_content_type($content_type);
replace_body($mime, $body);
return 1;
} elsif ($content_type =~ m!\bmultipart/!i) {
- return strip_multipart($mime, $content_type);
+ return strip_multipart($mime, $content_type, $filter);
} else {
replace_body($mime, "$content_type message scrubbed");
return 0;
# this is to correct user errors and not expected to cover all corner cases
# if users don't want to hit this, they should be sending text/plain messages
# unfortunately, too many people send HTML mail and we'll attempt to convert
-# it to something safer, smaller and harder-to-track.
+# it to something safer, smaller and harder-to-spy-on-users-with.
sub strip_multipart {
- my ($mime, $content_type) = @_;
+ my ($mime, $content_type, $filter) = @_;
my (@html, @keep);
my $rejected = 0;
if ($part_type =~ m!\btext/plain\b!i) {
push @keep, $part;
} elsif ($part_type =~ $MIME_HTML) {
+ $filter->reject(NO_HTML) if $filter;
push @html, $part;
} elsif ($part_type =~ $MIME_TEXT_ANY) {
# Give other text attachments the benefit of the doubt,
push @keep, $part;
} elsif ($part_type eq '' ||
- $part_type =~ m!\Aapplication/octet-stream\z!i) {
+ $part_type =~ m!\bapplication/octet-stream\b!i) {
# unfortunately, some mailers don't set correct types,
# let messages of unknown type through but do not
# change the sender-specified type
} else {
$rejected++;
}
- } elsif ($part_type =~ m!\Aapplication/pgp-signature\z!i) {
+ } elsif ($part_type =~ m!\bapplication/pgp-signature\b!i) {
# PGP signatures are not huge, we may keep them.
# They can only be valid if it's the last element,
# so we keep them iff the message is unmodified: