X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fmda.t;h=863eaf8fe2dda3d3316b84ddb3737b379efebcce;hb=e39585ee2bdcbeaab7b6bd33b3568021042d0879;hp=af5e19319ed82cbbc30b687a0a6b92036db261eb;hpb=d55abcc42bde846d9047491125dd2b32645dafd8;p=public-inbox.git diff --git a/t/mda.t b/t/mda.t index af5e1931..863eaf8f 100644 --- a/t/mda.t +++ b/t/mda.t @@ -3,7 +3,6 @@ use strict; use warnings; use Test::More; -use Email::MIME; use Cwd qw(getcwd); use PublicInbox::MID qw(mid2path); use PublicInbox::Git; @@ -22,7 +21,6 @@ my $fail_path = "$fail_bin:$ENV{PATH}"; # for spamc spam mock my $addr = 'test-public@example.com'; my $cfgpfx = "publicinbox.test"; my $faildir = "$home/faildir/"; -my $mime; my $git = PublicInbox::Git->new($maindir); my $fail_bad_header = sub ($$$) { @@ -87,7 +85,7 @@ die $@ if $@; local $ENV{PI_EMERGENCY} = $faildir; local $ENV{HOME} = $home; local $ENV{ORIGINAL_RECIPIENT} = $addr; - my $simple = Email::Simple->new(< To: You Cc: $addr @@ -96,8 +94,6 @@ Subject: hihi Date: Thu, 01 Jan 1970 00:00:00 +0000 EOF - my $in = $simple->as_string; - # ensure successful message delivery { local $ENV{PATH} = $main_path; @@ -177,7 +173,7 @@ Date: deadbeef local $ENV{ORIGINAL_RECIPIENT} = $addr; local $ENV{PATH} = $main_path; my $mid = 'spam-train@example.com'; - my $simple = Email::Simple->new(< To: You Cc: $addr @@ -186,8 +182,6 @@ Subject: this message will be trained as spam Date: Thu, 01 Jan 1970 00:00:00 +0000 EOF - my $in = $simple->as_string; - { # deliver the spam message, first ok(run_script(['-mda'], undef, { 0 => \$in })); @@ -214,7 +208,7 @@ EOF local $ENV{ORIGINAL_RECIPIENT} = $addr; local $ENV{PATH} = $main_path; my $mid = 'ham-train@example.com'; - my $simple = Email::Simple->new(< To: You Cc: $addr @@ -223,8 +217,6 @@ Subject: this message will be trained as spam Date: Thu, 01 Jan 1970 00:00:00 +0000 EOF - my $in = $simple->as_string; - # now train it # these should be overridden local $ENV{GIT_AUTHOR_EMAIL} = 'trainer@example.com'; @@ -239,35 +231,8 @@ EOF "learned ham idempotently "); # ensure trained email is filtered, too - my $html_body = "hi"; - my $parts = [ - Email::MIME->create( - attributes => { - content_type => 'text/html; charset=UTF-8', - encoding => 'base64', - }, - body => $html_body, - ), - Email::MIME->create( - attributes => { - content_type => 'text/plain', - encoding => 'quoted-printable', - }, - body => 'hi = "bye"', - ) - ]; - $mid = 'multipart-html-sucks@11'; - $mime = Email::MIME->create( - header_str => [ - From => 'a@example.com', - Subject => 'blah', - Cc => $addr, - 'Message-ID' => "<$mid>", - 'Content-Type' => 'multipart/alternative', - ], - parts => $parts, - ); - + my $mime = mime_load 't/mda-mime.eml'; + ($mid) = ($mime->header_raw('message-id') =~ /<([^>]+)>/); { $in = $mime->as_string; ok(run_script(['-learn', 'ham'], undef, { 0 => \$in }), @@ -288,7 +253,7 @@ EOF local $ENV{PATH} = $main_path; my $list_id = 'foo.example.com'; my $mid = 'list-id-delivery@example.com'; - my $simple = Email::Simple->new(< To: You Cc: $addr @@ -298,9 +263,8 @@ Subject: this message will be trained as spam Date: Thu, 01 Jan 1970 00:00:00 +0000 EOF - system(qw(git config --file), $pi_config, "$cfgpfx.listid", $list_id); + xsys(qw(git config --file), $pi_config, "$cfgpfx.listid", $list_id); $? == 0 or die "failed to set listid $?"; - my $in = $simple->as_string; ok(run_script(['-mda'], undef, { 0 => \$in }), 'mda OK with List-Id match'); my $path = mid2path($mid); @@ -308,13 +272,12 @@ EOF like($$msg, qr/\Q$list_id\E/, 'delivered message w/ List-ID matches'); # try a message w/o precheck - $simple = Email::Simple->new(< List-Id: <$list_id> this message would not be accepted without --no-precheck EOF - $in = $simple->as_string; my ($out, $err) = ('', ''); my $rdr = { 0 => \$in, 1 => \$out, 2 => \$err }; ok(run_script(['-mda', '--no-precheck'], undef, $rdr),