about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-10-15 03:40:19 +0000
committerEric Wong <e@80x24.org>2019-10-15 20:26:41 +0000
commit7e881ac8227d1882c92de6f6701ffcba7cef9191 (patch)
tree771d41fc13cbbb894d92abccfb87a68ac67949a4 /t
parent849f57851a04e376cf2327d9e98e8128bf3c756e (diff)
downloadpublic-inbox-7e881ac8227d1882c92de6f6701ffcba7cef9191.tar.gz
This also adds watchheader tests for -watch, which we never
had before :x
Diffstat (limited to 't')
-rw-r--r--t/mda.t28
-rw-r--r--t/watch_maildir_v2.t31
2 files changed, 59 insertions, 0 deletions
diff --git a/t/mda.t b/t/mda.t
index 5621b7d6..3cab590b 100644
--- a/t/mda.t
+++ b/t/mda.t
@@ -267,6 +267,34 @@ EOF
         }
 }
 
+# List-ID based delivery
+{
+        local $ENV{PI_EMERGENCY} = $faildir;
+        local $ENV{HOME} = $home;
+        local $ENV{ORIGINAL_RECIPIENT} = undef;
+        local $ENV{PATH} = $main_path;
+        my $list_id = 'foo.example.com';
+        my $mid = 'list-id-delivery@example.com';
+        my $simple = Email::Simple->new(<<EOF);
+From: user <user\@example.com>
+To: You <you\@example.com>
+Cc: $addr
+Message-ID: <$mid>
+List-Id: <$list_id>
+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);
+        $? == 0 or die "failed to set listid $?";
+        my $in = $simple->as_string;
+        IPC::Run::run([$mda], \$in);
+        is($?, 0, 'mda OK with List-Id match');
+        my $path = mid2path($mid);
+        my $msg = `git --git-dir=$maindir cat-file blob HEAD:$path`;
+        like($msg, qr/\Q$list_id\E/, 'delivered message w/ List-ID matches');
+}
+
 done_testing();
 
 sub fail_bad_header {
diff --git a/t/watch_maildir_v2.t b/t/watch_maildir_v2.t
index 0a5a8017..99551ceb 100644
--- a/t/watch_maildir_v2.t
+++ b/t/watch_maildir_v2.t
@@ -171,4 +171,35 @@ EOF
         is($both, $$msg, 'got original message back from v2');
 }
 
+{
+        my $want = <<'EOF';
+From: <u@example.com>
+List-Id: <i.want.you.to.want.me>
+Message-ID: <do.want@example.com>
+EOF
+        my $do_not_want = <<'EOF';
+From: <u@example.com>
+List-Id: <do.not.want>
+X-Mailing-List: no@example.com
+Message-ID: <do.not.want@example.com>
+EOF
+        my $cfg = $orig."$cfgpfx.listid=i.want.you.to.want.me\n";
+        PublicInbox::Emergency->new($maildir)->prepare(\$want);
+        PublicInbox::Emergency->new($maildir)->prepare(\$do_not_want);
+        my $config = PublicInbox::Config->new(\$cfg);
+        PublicInbox::WatchMaildir->new($config)->scan('full');
+        $ibx = $config->lookup_name('test');
+        my $num = $ibx->mm->num_for('do.want@example.com');
+        ok(defined $num, 'List-ID matched for watch');
+        $num = $ibx->mm->num_for('do.not.want@example.com');
+        is($num, undef, 'unaccepted List-ID matched for watch');
+
+        $cfg = $orig."$cfgpfx.watchheader=X-Mailing-List:no\@example.com\n";
+        $config = PublicInbox::Config->new(\$cfg);
+        PublicInbox::WatchMaildir->new($config)->scan('full');
+        $ibx = $config->lookup_name('test');
+        $num = $ibx->mm->num_for('do.not.want@example.com');
+        ok(defined $num, 'X-Mailing-List matched');
+}
+
 done_testing;