diff options
Diffstat (limited to 'lib/SpamCat.pm')
-rw-r--r-- | lib/SpamCat.pm | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/lib/SpamCat.pm b/lib/SpamCat.pm index 4807149..cbae3fd 100644 --- a/lib/SpamCat.pm +++ b/lib/SpamCat.pm @@ -23,7 +23,7 @@ sub new { bless \%conf, $class; } -sub deliver { +sub filter { my ($self) = @_; local $/; @@ -44,26 +44,22 @@ sub deliver { } } - if (defined $count) { - return if $count == 0; - - if ($count > 0) { - my $count_str = '[' . ($self->{default_count} - $count + 1) . '/' . $self->{default_count} . ']'; - my $new_subject = $email->header('Subject'); - if ($new_subject) { - $new_subject .= ' - ' . $count_str; - } else { - $new_subject = $count_str; - } - $email->header_set('Subject' => $new_subject); - $email->header_set('X-SpamCat-Remaining' => $count); - } + # + # Negative counts indicate unlimited delivery. + # + if (defined $count && $count >= 0) { + my $count_str = '[' . ($self->{default_count} - $count + 1) . '/' . $self->{default_count} . ']'; + my $new_subject = $email->header('Subject'); + if ($new_subject) { + $new_subject .= ' - ' . $count_str; + } else { + $new_subject = $count_str; + } + $email->header_set('Subject' => $new_subject); + $email->header_set('X-SpamCat-Remaining' => $count); } - my $deliverfh = IO::File->new("| " . $self->{deliver}) || - die "Couldn't open pipe to " . $self->{deliver} . ": $!\n"; - print $deliverfh $email->as_string; - $deliverfh->close; + print $email->as_string; } sub parse_to { @@ -164,8 +160,10 @@ sub decrement_count_t { if (!defined $count) { $count = $self->{default_count}; $q = 'INSERT INTO emails (count, sender) VALUES (?, ?)'; + } elsif ($count <= 0) { + return $count; } else { - $count = $count <= 0 ? $count : $count - 1; + $count--; $q = "UPDATE emails SET count = ?, modified = CURRENT_TIMESTAMP WHERE sender = ?"; } |