user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
blob 4e9695e13eb663a361760e43418aa9b5a4c5ff1f 1712 bytes (raw)
name: t/filter_rubylang.t 	 # note: path name is non-authoritative(*)

 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
57
58
59
60
61
 
# Copyright (C) 2017-2021 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 PublicInbox::Eml;
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 = PublicInbox::Eml->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' can be used here
		# for documentation purposes, but Xapian ignores everything
		# up to and including the '-'
		'serial:core:file=msgmap.sqlite3'
	];
	my $ibx = PublicInbox::Inbox->new({ inboxdir => $git_dir,
						altid => $altid });
	$f = PublicInbox::Filter::RubyLang->new(ibx => $ibx);
	$msg = <<'EOF';
X-Mail-Count: 12
Message-ID: <a@b>

EOF
	$mime = PublicInbox::Eml->new($msg);
	$ret = $f->delivery($mime);
	is($ret, $mime, "delivery successful");
	my $mm = $ibx->mm;
	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 = PublicInbox::Eml->new($msg);
	$ret = $f->delivery($mime);
	is($ret, 100, "delivery rejected without X-Mail-Count");
}

done_testing();

debug log:

solving 4e9695e1 ...
found 4e9695e1 in https://80x24.org/public-inbox.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).