about summary refs log tree commit homepage
path: root/script/public-inbox-learn
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-06-24 01:15:13 +0000
committerEric Wong <e@80x24.org>2016-06-24 02:00:26 +0000
commitc515264dd69156fc89c59685f788b1093afb8731 (patch)
treeada1a21aa82b369dbe1ac8c865474a9318228f7d /script/public-inbox-learn
parent3c24b7e7e47be9646226d921897cc9ec92e9be8a (diff)
downloadpublic-inbox-c515264dd69156fc89c59685f788b1093afb8731.tar.gz
This should hopefully make it easier to try other anti-spam
systems (or none at all) in the future.
Diffstat (limited to 'script/public-inbox-learn')
-rwxr-xr-xscript/public-inbox-learn21
1 files changed, 7 insertions, 14 deletions
diff --git a/script/public-inbox-learn b/script/public-inbox-learn
index b05ef056..7ef2a312 100755
--- a/script/public-inbox-learn
+++ b/script/public-inbox-learn
@@ -14,12 +14,13 @@ use Email::MIME;
 use Email::MIME::ContentType;
 $Email::MIME::ContentType::STRICT_PARAMS = 0; # user input is imperfect
 use PublicInbox::Address;
-use PublicInbox::Spawn qw(spawn);
+use PublicInbox::Spamcheck::Spamc;
 my $train = shift or die "usage: $usage\n";
 if ($train !~ /\A(?:ham|spam)\z/) {
         die "`$train' not recognized.\nusage: $usage\n";
 }
 
+my $spamc = PublicInbox::Spamcheck::Spamc->new;
 my $pi_config = PublicInbox::Config->new;
 my $err;
 my $mime = Email::MIME->new(eval {
@@ -27,19 +28,11 @@ my $mime = Email::MIME->new(eval {
         my $data = scalar <STDIN>;
         $data =~ s/\AFrom [^\r\n]*\r?\n//s;
         eval {
-                my @cmd = (qw(spamc -L), $train);
-                my ($r, $w);
-                pipe($r, $w) or die "pipe failed: $!";
-                open my $null, '>', '/dev/null' or
-                                        die "failed to open /dev/null: $!";
-                my $nullfd = fileno($null);
-                my %rdr = (0 => fileno($r), 1 => $nullfd, 2 => $nullfd);
-                my $pid = spawn(\@cmd, undef, \%rdr);
-                close $null;
-                close $r or die "close \$r failed: $!";
-                print $w $data or die "print \$w failed: $!";
-                close $w or die "close \$w failed: $!";
-                waitpid($pid, 0);
+                if ($train eq 'ham') {
+                        $spamc->hamlearn(\$data);
+                } else {
+                        $spamc->spamlearn(\$data);
+                }
                 die "spamc failed with: $?\n" if $?;
         };
         $err = $@;