From f66473b1a41606d8b4cda74c551aa85d12ec37ef Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 14 Jul 2015 21:01:18 +0000 Subject: reject HTML loudly and automatically This should hopefully reduce the delay between when a user fails to send plain-text to when an admin such as myself notices the HTML mail in a sea of spam. Unfortunately, this can lead to backscatter, so avoid doing it until its passed through spamc, at least. --- t/mda.t | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/mda.t b/t/mda.t index 53712a56..67e86f47 100644 --- a/t/mda.t +++ b/t/mda.t @@ -23,6 +23,7 @@ my $fail_path = "$fail_bin:$ENV{PATH}"; # for spamc spam mock my $addr = 'test-public@example.com'; my $cfgpfx = "publicinbox.test"; my $failbox = "$home/fail.mbox"; +my $mime; { ok(-x "$main_bin/spamc", @@ -235,7 +236,7 @@ EOF ) ]; $mid = 'multipart-html-sucks@11'; - my $mime = Email::MIME->create( + $mime = Email::MIME->create( header_str => [ From => 'a@example.com', Subject => 'blah', @@ -276,6 +277,38 @@ EOF ok(-d $faildir, "emergency exists"); my @new = glob("$faildir/new/*"); is(scalar(@new), 1, "message delivered"); + is(unlink(@new), 1, "removed emergency message"); + + local $ENV{PATH} = $main_path; + $in = < +To: $addr +Content-Type: text/html +Message-ID: +Subject: faildir subject +Date: Thu, 01 Jan 1970 00:00:00 +0000 + +bad +EOF + my $out = ''; + my $err = ''; + run([$mda], \$in, \$out, \$err); + isnt($?, 0, "mda exited with failure"); + is(length $out, 0, 'nothing in stdout'); + isnt(length $err, 0, 'error message in stderr'); + + @new = glob("$faildir/new/*"); + is(scalar(@new), 0, "new message did not show up"); + + # reject multipart again + $in = $mime->as_string; + $err = ''; + run([$mda], \$in, \$out, \$err); + isnt($?, 0, "mda exited with failure"); + is(length $out, 0, 'nothing in stdout'); + isnt(length $err, 0, 'error message in stderr'); + @new = glob("$faildir/new/*"); + is(scalar(@new), 0, "new message did not show up"); } done_testing(); -- cgit v1.2.3-24-ge0c7