user/dev discussion of public-inbox itself
 help / color / Atom feed
7016e8bfd3fc54e7b559d5c4e56e95f5a5d4bb6d blob 1466 bytes (raw)

 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
 
# Copyright (C) 2016-2018 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 Cwd;
use Email::Simple;
use IO::File;
use File::Temp qw/tempdir/;
use Fcntl qw(:DEFAULT SEEK_SET);
my $tmpdir = tempdir('spamcheck_spamc-XXXXXX', TMPDIR => 1, CLEANUP => 1);

use_ok 'PublicInbox::Spamcheck::Spamc';
my $spamc = PublicInbox::Spamcheck::Spamc->new;
$spamc->{checkcmd} = [qw(cat)];

{
	open my $fh, '+>', "$tmpdir/file" or die "open failed: $!";
	ok(!$spamc->spamcheck($fh), 'empty '.ref($fh));
}
ok(!$spamc->spamcheck(IO::File->new_tmpfile), 'IO::File->new_tmpfile');

my $dst = '';
my $src = <<'EOF';
Date: Thu, 01 Jan 1970 00:00:00 +0000
To: <e@example.com>
From: <e@example.com>
Subject: test
Message-ID: <testmessage@example.com>

EOF
ok($spamc->spamcheck(Email::Simple->new($src), \$dst), 'Email::Simple works');
is($dst, $src, 'input == output');

$dst = '';
$spamc->{checkcmd} = ['sh', '-c', 'cat; false'];
ok(!$spamc->spamcheck(Email::Simple->new($src), \$dst), 'Failed check works');
is($dst, $src, 'input == output for spammy example');

for my $l (qw(ham spam)) {
	my $file = "$tmpdir/$l.out";
	$spamc->{$l.'cmd'} = ['tee', $file ];
	my $method = $l.'learn';
	ok($spamc->$method(Email::Simple->new($src)), "$method OK");
	open my $fh, '<', $file or die "failed to open $file: $!";
	is(eval { local $/, <$fh> }, $src, "$l command ran alright");
}

done_testing();
debug log:

solving 7016e8b ...
found 7016e8b in https://80x24.org/public-inbox.git

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox