aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-06-19 19:55:38 -0400
committerBrian Cully <bjc@kublai.com>2022-06-19 19:56:37 -0400
commitf2820a509d91061b65fa32ec4e647cbd29760195 (patch)
tree7685f169b96a6b279c910e0021ca38538a124f9b /lib
parente8235e7264e467f6dd64587fbd26faad2f74cbbc (diff)
downloadspamcat-f2820a509d91061b65fa32ec4e647cbd29760195.tar.gz
spamcat-f2820a509d91061b65fa32ec4e647cbd29760195.zip
Change to filter style from pipe.
Diffstat (limited to 'lib')
-rw-r--r--lib/SpamCat.pm38
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 = ?";
}