X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fmda.t;h=5457f17f3cde72e2186f48c079715564114a3bb6;hb=5d8dbb4aca5afcc6b98a4d951f03003fb7eaf356;hp=ddc0c27975288fd66d639246da892c6eece94096;hpb=4da62f284003d75abe7cb35594414eb2224f42bc;p=public-inbox.git diff --git a/t/mda.t b/t/mda.t index ddc0c279..5457f17f 100644 --- a/t/mda.t +++ b/t/mda.t @@ -7,7 +7,9 @@ use Email::MIME; use Cwd qw(getcwd); use PublicInbox::MID qw(mid2path); use PublicInbox::Git; +use PublicInbox::InboxWritable; use PublicInbox::TestCommon; +use PublicInbox::Import; my ($tmpdir, $for_destroy) = tmpdir(); my $home = "$tmpdir/pi-home"; my $pi_home = "$home/.public-inbox"; @@ -47,7 +49,7 @@ my $fail_bad_header = sub ($$$) { "spamc mock found (run in top of source tree"); is(1, mkdir($home, 0755), "setup ~/ for testing"); is(1, mkdir($pi_home, 0755), "setup ~/.public-inbox"); - is(0, system(qw(git init -q --bare), $maindir), "git init (main)"); + PublicInbox::Import::init_bare($maindir); open my $fh, '>>', $pi_config or die; print $fh < }; - close $fh; - my $msg = Email::MIME->new($str); - + my $eml = 't/utf8.eml'; + my $msg = PublicInbox::InboxWritable::mime_from_path($eml) or + die "failed to open $eml: $!"; my $from = $msg->header('From'); my ($author) = PublicInbox::Address::names($from); my ($email) = PublicInbox::Address::emails($from); @@ -88,7 +87,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 @@ -97,8 +96,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; @@ -178,7 +175,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 @@ -187,8 +184,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 })); @@ -215,7 +210,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 @@ -224,8 +219,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'; @@ -240,6 +233,7 @@ EOF "learned ham idempotently "); # ensure trained email is filtered, too + $mime = mime_load 't/mda-mime.eml', sub { my $html_body = "hi"; my $parts = [ Email::MIME->create( @@ -258,7 +252,7 @@ EOF ) ]; $mid = 'multipart-html-sucks@11'; - $mime = Email::MIME->create( + Email::MIME->create( header_str => [ From => 'a@example.com', Subject => 'blah', @@ -267,7 +261,7 @@ EOF 'Content-Type' => 'multipart/alternative', ], parts => $parts, - ); + )}; # mime_load sub { $in = $mime->as_string; @@ -289,7 +283,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 @@ -299,9 +293,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); @@ -309,13 +302,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),