aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-06-19 20:12:04 -0400
committerBrian Cully <bjc@kublai.com>2022-06-19 20:12:04 -0400
commit3da1e1c91effff02857badfe3a472a49aba9d60d (patch)
tree6514d42e41cdcdcf362c63b373e727dec5c2f628
parentf2820a509d91061b65fa32ec4e647cbd29760195 (diff)
downloadspamcat-3da1e1c91effff02857badfe3a472a49aba9d60d.tar.gz
spamcat-3da1e1c91effff02857badfe3a472a49aba9d60d.zip
Fix off-by-one error in subject and remaining count header.
-rw-r--r--lib/SpamCat.pm4
-rw-r--r--t/fixtures/bar.expected2
-rw-r--r--t/fixtures/foo.expected2
-rw-r--r--t/fixtures/foo2.expected2
-rw-r--r--t/fixtures/multiple.expected2
-rw-r--r--t/fixtures/nosubj.expected2
-rw-r--r--t/lib.t12
7 files changed, 13 insertions, 13 deletions
diff --git a/lib/SpamCat.pm b/lib/SpamCat.pm
index cbae3fd..282ac7c 100644
--- a/lib/SpamCat.pm
+++ b/lib/SpamCat.pm
@@ -48,7 +48,7 @@ sub filter {
# Negative counts indicate unlimited delivery.
#
if (defined $count && $count >= 0) {
- my $count_str = '[' . ($self->{default_count} - $count + 1) . '/' . $self->{default_count} . ']';
+ my $count_str = '[' . ($self->{default_count} - $count) . '/' . $self->{default_count} . ']';
my $new_subject = $email->header('Subject');
if ($new_subject) {
$new_subject .= ' - ' . $count_str;
@@ -158,7 +158,7 @@ sub decrement_count_t {
my $q;
my $count = $self->get_count_t($sender);
if (!defined $count) {
- $count = $self->{default_count};
+ $count = $self->{default_count} - 1;
$q = 'INSERT INTO emails (count, sender) VALUES (?, ?)';
} elsif ($count <= 0) {
return $count;
diff --git a/t/fixtures/bar.expected b/t/fixtures/bar.expected
index e554c65..f351443 100644
--- a/t/fixtures/bar.expected
+++ b/t/fixtures/bar.expected
@@ -6,7 +6,7 @@ Received: from mta.example.com
Received: by mta.example.com (Postfix, from userid 1001)
id 844956F1EE; Thu, 20 Nov 2014 17:17:18 -0500 (EST)
To: bar@spamcat.example.com
-Subject: test - [21/20]
+Subject: test - [20/20]
Message-Id: <bar@mta.example.com>
Date: Thu, 20 Nov 2014 17:17:18 -0500 (EST)
From: sender@example.com (Spamcat Sender)
diff --git a/t/fixtures/foo.expected b/t/fixtures/foo.expected
index 7516338..cc0ef3b 100644
--- a/t/fixtures/foo.expected
+++ b/t/fixtures/foo.expected
@@ -10,6 +10,6 @@ Subject: test - [3/20]
Message-Id: <foo@mta.example.com>
Date: Thu, 20 Nov 2014 17:17:18 -0500 (EST)
From: sender@example.com (Spamcat Sender)
-X-SpamCat-Remaining: 18
+X-SpamCat-Remaining: 17
Sample email.
diff --git a/t/fixtures/foo2.expected b/t/fixtures/foo2.expected
index ed86987..da27a77 100644
--- a/t/fixtures/foo2.expected
+++ b/t/fixtures/foo2.expected
@@ -10,6 +10,6 @@ Subject: test - [4/20]
Message-Id: <foo2@mta.example.com>
Date: Thu, 20 Nov 2014 17:17:18 -0500 (EST)
From: sender@example.com (Spamcat Sender)
-X-SpamCat-Remaining: 17
+X-SpamCat-Remaining: 16
Sample email.
diff --git a/t/fixtures/multiple.expected b/t/fixtures/multiple.expected
index c867cc4..66e4fa6 100644
--- a/t/fixtures/multiple.expected
+++ b/t/fixtures/multiple.expected
@@ -11,6 +11,6 @@ Subject: test - [1/20]
Message-Id: <multiple@mta.example.com>
Date: Thu, 20 Nov 2014 17:17:18 -0500 (EST)
From: sender@example.com (Spamcat Sender)
-X-SpamCat-Remaining: 20
+X-SpamCat-Remaining: 19
Sample email.
diff --git a/t/fixtures/nosubj.expected b/t/fixtures/nosubj.expected
index 440a862..cf017ec 100644
--- a/t/fixtures/nosubj.expected
+++ b/t/fixtures/nosubj.expected
@@ -10,6 +10,6 @@ Message-Id: <nosubj@mta.example.com>
Date: Thu, 20 Nov 2014 17:17:18 -0500 (EST)
From: sender@example.com (Spamcat Sender)
Subject: [1/20]
-X-SpamCat-Remaining: 20
+X-SpamCat-Remaining: 19
Sample email.
diff --git a/t/lib.t b/t/lib.t
index 41b5704..efe9b31 100644
--- a/t/lib.t
+++ b/t/lib.t
@@ -30,12 +30,12 @@ my $sch = SpamCat->new(%conf);
ok(defined $sch, 'Constructor returns instance');
ok(SpamCat->can('decrement_count'), 'Has count decrementor');
-is($sch->decrement_count('foo'), $conf{default_count},
+is($sch->decrement_count('foo'), 19,
'Default count for new sender');
-is($sch->decrement_count('foo'), 19, 'Existing sender decrements');
+is($sch->decrement_count('foo'), 18, 'Existing sender decrements');
ok(SpamCat->can('get_count'), 'Has count getter');
-is($sch->get_count('foo'), 19, 'Returns existing sender count');
+is($sch->get_count('foo'), 18, 'Returns existing sender count');
ok(!defined $sch->get_count('doesntexist'),
'Non-existant sender has undefined count');
@@ -77,11 +77,11 @@ is($rows[0]->{count}, -1);
is($rows[1]->{sender}, 'bar');
is($rows[1]->{count}, 0);
is($rows[2]->{sender}, 'foo');
-is($rows[2]->{count}, 16);
+is($rows[2]->{count}, 15);
is($rows[3]->{sender}, 'name1');
-is($rows[3]->{count}, 20);
+is($rows[3]->{count}, 19);
is($rows[4]->{sender}, 'nosubj');
-is($rows[4]->{count}, 20);
+is($rows[4]->{count}, 19);
sub test_file {
my ($filen) = @_;