diff options
Diffstat (limited to 'lib/PublicInbox/Spamcheck/Spamc.pm')
-rw-r--r-- | lib/PublicInbox/Spamcheck/Spamc.pm | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/lib/PublicInbox/Spamcheck/Spamc.pm b/lib/PublicInbox/Spamcheck/Spamc.pm index d2b6429c..b4f95e2b 100644 --- a/lib/PublicInbox/Spamcheck/Spamc.pm +++ b/lib/PublicInbox/Spamcheck/Spamc.pm @@ -1,18 +1,17 @@ -# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org> +# Copyright (C) all contributors <meta@public-inbox.org> # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> # Default spam filter class for wrapping spamc(1) package PublicInbox::Spamcheck::Spamc; -use strict; -use warnings; -use PublicInbox::Spawn qw(popen_rd spawn); +use v5.12; +use PublicInbox::Spawn qw(run_qx run_wait); use IO::Handle; use Fcntl qw(SEEK_SET); sub new { my ($class) = @_; bless { - checkcmd => [qw(spamc -E --headers)], + checkcmd => [qw(spamc -E)], hamcmd => [qw(spamc -L ham)], spamcmd => [qw(spamc -L spam)], }, $class; @@ -21,15 +20,9 @@ sub new { sub spamcheck { my ($self, $msg, $out) = @_; + $out = \(my $buf = '') unless ref($out); my $rdr = { 0 => _msg_to_fh($self, $msg) }; - my ($fh, $pid) = popen_rd($self->{checkcmd}, undef, $rdr); - unless (ref $out) { - my $buf = ''; - $out = \$buf; - } - $$out = do { local $/; <$fh> }; - close $fh or die "close failed: $!"; - waitpid($pid, 0); + $$out = run_qx($self->{checkcmd}, undef, $rdr); ($? || $$out eq '') ? 0 : 1; } @@ -49,9 +42,7 @@ sub _learn { $rdr->{0} = _msg_to_fh($self, $msg); $rdr->{1} ||= $self->_devnull; $rdr->{2} ||= $self->_devnull; - my $pid = spawn($self->{$field}, undef, $rdr); - waitpid($pid, 0); - !$?; + 0 == run_wait($self->{$field}, undef, $rdr); } sub _devnull { |