From: Don Armstrong Date: Fri, 15 Dec 2017 21:48:13 +0000 (-0800) Subject: abstract out spamc_bug from spam_score X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0a1fcf5eea5e1f6992b74003aa527510461fd35d;p=debbugs.git abstract out spamc_bug from spam_score --- diff --git a/bin/debbugs-spam b/bin/debbugs-spam index 613eec27..51542ce8 100755 --- a/bin/debbugs-spam +++ b/bin/debbugs-spam @@ -302,10 +302,11 @@ sub spam_score_bug { return @records; } -sub spam_score { +sub spamc_bug { my ($record,$spamc,$spamc_opts) = @_; - my ($score,$threshold,$report); - my $is_spam = 0; + my $first_line = ''; + my $report = ''; + my $exit_code = 0; eval { my ($spamc_in,$spamc_out); my $old_sig = $SIG{"PIPE"}; @@ -314,7 +315,7 @@ sub spam_score { }; my $childpid = open3($spamc_in,$spamc_out,0, - $spamc,'-E',@{$spamc_opts}) or + $spamc,@{$spamc_opts}) or die "Unable to fork spamc: $!"; if (not $childpid) { die "Unable to fork spamc"; @@ -323,19 +324,10 @@ sub spam_score { close($spamc_in) or die "Unable to close spamc_in: $!"; waitpid($childpid,0); if ($? >> 8) { - $is_spam = 1; - } - my ($first_line,@report) = <$spamc_out>; - if ($DEBUG) { - print STDERR "[$?;".($? >> 8)."] "; - print STDERR $first_line,@report; - print STDERR " "; - } - if (defined $first_line) { - chomp $first_line; - ($score,$threshold) = $first_line =~ m{^(-?[\d\.]+)/(-?[\d\.]+)$}; - $report = join('',@report); + $exit_code = $? >> 8; } + local $/; + $report = <$spamc_out>; close($spamc_out); $SIG{"PIPE"} = $old_sig; }; @@ -343,7 +335,19 @@ sub spam_score { carp "processing of message failed [$@]\n"; return undef; } - return wantarray?($score,$is_spam,$report):$score; + return ($exit_code,$report); +} + +sub spam_score { + my ($record,$spamc,$spamc_opts) = @_; + my ($score,$threshold,$report,$exit_code); + ($exit_code,$report) = + spamc_bug($record,$spamc,[@{$spamc_opts},'-c']); + if (defined $report) { + ($score,$threshold) = $report =~ s{^(-?[\d\.]+)/(-?[\d\.]+)\n?}{}; + } + return wantarray?($score,$exit_code,$report):$score; +} } sub foreachmsg {