aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2017-10-30 15:34:21 -0400
committerBrian Cully <bjc@kublai.com>2017-10-30 15:34:21 -0400
commit0964736afe66c066f8b77a54d77f27bdb8d24cd5 (patch)
tree5a39219a8f745b0a3b374e25d86c00bbde10fc77
parentf887806c5989fc3e5c86107d6ff945a6fc63b05c (diff)
downloadspamcat-0964736afe66c066f8b77a54d77f27bdb8d24cd5.tar.gz
spamcat-0964736afe66c066f8b77a54d77f27bdb8d24cd5.zip
Add get and set commands for tweaking counts.
Introduce 'get' to query a count for a given email address, and 'set' to manually update it.
-rwxr-xr-xbin/spamcat18
-rw-r--r--lib/SpamCat.pm2
-rw-r--r--t/lib.t5
3 files changed, 22 insertions, 3 deletions
diff --git a/bin/spamcat b/bin/spamcat
index fd37f76..8549d95 100755
--- a/bin/spamcat
+++ b/bin/spamcat
@@ -24,6 +24,14 @@ Print a brief help message and exit.
Load configuration from C<file>
+=item get C<sender>
+
+Show database row for C<sender>.
+
+=item set C<sender> C<count>
+
+Set C<sender>'s remaining message count to C<count>.
+
=item dumpconfig
Dump the current configuration.
@@ -83,6 +91,16 @@ if ($#ARGV >= 0) {
}
print uc($k) . " = " . $v . "\n";
}
+ } elsif ($cmd eq 'get') {
+ my $sender = shift @ARGV;
+ pod2usage(1) unless $sender;
+ my $count = $sch->get_count($sender);
+ print "$sender has $count messages remaining.\n";
+ } elsif ($cmd eq 'set') {
+ my ($sender, $count) = @ARGV;
+ pod2usage(1) unless $count && $count =~ /\d+/;
+ $sch->set_count($sender, $count);
+ print "$sender has $count messages remaining.\n";
} else {
pod2usage(1);
}
diff --git a/lib/SpamCat.pm b/lib/SpamCat.pm
index d470520..7a160cf 100644
--- a/lib/SpamCat.pm
+++ b/lib/SpamCat.pm
@@ -144,7 +144,7 @@ sub set_count_t {
$q = 'INSERT INTO emails (count, sender) VALUES (?, ?)';
} else {
# Otherwise update the record with the new count.
- $q = 'UPDATE emails SET count = ? modified = CURRENT_TIMESTAMP WHERE sender = ?'
+ $q = 'UPDATE emails SET count = ?, modified = CURRENT_TIMESTAMP WHERE sender = ?'
}
my $sth = $self->{dbh}->prepare($q);
$sth->execute($count, $sender);
diff --git a/t/lib.t b/t/lib.t
index 1f32c08..657658e 100644
--- a/t/lib.t
+++ b/t/lib.t
@@ -1,6 +1,6 @@
# -*- Mode: cperl -*-
-use Test::More tests => 41;
+use Test::More tests => 42;
use strict;
use warnings;
@@ -39,7 +39,8 @@ ok(!defined $sch->get_count('doesntexist'),
'Non-existant sender has undefined count');
ok(SpamCat->can('set_count'), 'Has count setter');
-is($sch->set_count('bar', 1), 1, 'Setting count returns existing count');
+is($sch->set_count('bar', 10), 10, 'Setting count returns existing count');
+is($sch->set_count('bar', 1), 1, 'Updating existing count to 1 returns 1');
is($sch->decrement_count('bar'), 0, 'Decrementing count from 1 returns 0');
is($sch->decrement_count('bar'), 0, 'Decrementing count from 0 returns 0');