X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fmda.t;h=d20cdb92be30fb8b962dac42585b1e7204c627ee;hb=2f8d15b1170b137a0512a4f3163b236a5dcbf0b8;hp=fb505146f8feb080db191dfaad9e2f334e0d2957;hpb=5f113019334c3fcdcc71e8a573c30ec10f7bcbb9;p=public-inbox.git diff --git a/t/mda.t b/t/mda.t index fb505146..d20cdb92 100644 --- a/t/mda.t +++ b/t/mda.t @@ -1,9 +1,8 @@ -# Copyright (C) 2014-2020 all contributors +# Copyright (C) 2014-2021 all contributors # License: AGPL-3.0+ 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 ($$$) { @@ -64,9 +62,7 @@ local $ENV{GIT_COMMITTER_NAME} = eval { use PublicInbox::MDA; use PublicInbox::Address; use Encode qw/encode/; - my $eml = 't/utf8.eml'; - my $msg = PublicInbox::InboxWritable::mime_from_path($eml) or - die "failed to open $eml: $!"; + my $msg = eml_load 't/utf8.eml'; my $from = $msg->header('From'); my ($author) = PublicInbox::Address::names($from); my ($email) = PublicInbox::Address::emails($from); @@ -233,35 +229,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 = eml_load 't/mda-mime.eml'; + ($mid) = ($mime->header_raw('message-id') =~ /<([^>]+)>/); { $in = $mime->as_string; ok(run_script(['-learn', 'ham'], undef, { 0 => \$in }), @@ -292,7 +261,7 @@ Subject: this message will be trained as spam Date: Thu, 01 Jan 1970 00:00:00 +0000 EOF - xsys(qw(git config --file), $pi_config, "$cfgpfx.listid", $list_id); + xsys(qw(git config --file), $pi_config, "$cfgpfx.listid", uc $list_id); $? == 0 or die "failed to set listid $?"; ok(run_script(['-mda'], undef, { 0 => \$in }), 'mda OK with List-Id match'); @@ -330,9 +299,17 @@ EOF ok(run_script(['-mda'], undef, $rdr), 'mda OK with multiple List-Id matches'); $cur = $git->qx(qw(diff HEAD~1..HEAD)); - like($cur, qr/Message-ID: <2lids\@example>/, + like($cur, qr/^\+Message-ID: <2lids\@example>/sm, 'multi List-ID match delivered'); like($err, qr/multiple List-ID/, 'warned about multiple List-ID'); + + # ensure -learn rm works after inbox address is updated + ($out, $err) = ('', ''); + xsys(qw(git config --file), $pi_config, "$cfgpfx.address", + 'updated-address@example.com'); + ok(run_script(['-learn', 'rm'], undef, $rdr), 'rm-ed via -learn'); + $cur = $git->qx(qw(diff HEAD~1..HEAD)); + like($cur, qr/^-Message-ID: <2lids\@example>/sm, 'changed in git'); } done_testing();