about summary refs log tree commit homepage
path: root/t/filter_rubylang.t
blob: 1288b72f1b8eddf92098f15652abffce8190a00a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright (C) 2017-2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use warnings;
use Test::More;
use Email::MIME;
use PublicInbox::TestCommon;
use_ok 'PublicInbox::Filter::RubyLang';

my $f = PublicInbox::Filter::RubyLang->new;
ok($f, 'created PublicInbox::Filter::RubyLang object');
my $msg = <<'EOF';
Subject: test

keep this

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
EOF
my $mime = Email::MIME->new($msg);
my $ret = $f->delivery($mime);
is($ret, $mime, "delivery successful");
is($mime->body, "keep this\n", 'normal message filtered OK');

SKIP: {
	require_mods('DBD::SQLite', 4);
	use_ok 'PublicInbox::Inbox';
	my ($git_dir, $for_destroy) = tmpdir();
	is(mkdir("$git_dir/public-inbox"), 1, "created public-inbox dir");
	my $altid = [ "serial:ruby-core:file=msgmap.sqlite3" ];
	my $ibx = PublicInbox::Inbox->new({ inboxdir => $git_dir,
						altid => $altid });
	$f = PublicInbox::Filter::RubyLang->new(-inbox => $ibx);
	$msg = <<'EOF';
X-Mail-Count: 12
Message-ID: <a@b>

EOF
	$mime = Email::MIME->new($msg);
	$ret = $f->delivery($mime);
	is($ret, $mime, "delivery successful");
	my $mm = PublicInbox::Msgmap->new($git_dir);
	is($mm->num_for('a@b'), 12, 'MM entry created based on X-ML-Count');

	$msg = <<'EOF';
X-Mail-Cout: 12
Message-ID: <b@b>

EOF

	$mime = Email::MIME->new($msg);
	$ret = $f->delivery($mime);
	is($ret, 100, "delivery rejected without X-Mail-Count");
}

done_testing();