aboutsummaryrefslogtreecommitdiffstats
path: root/bin/spamcat
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2015-10-20 10:51:11 -0400
committerBrian Cully <bjc@kublai.com>2015-10-20 12:08:36 -0400
commitf887806c5989fc3e5c86107d6ff945a6fc63b05c (patch)
tree433bd701b6b03e6b1ebd0d800e6469aef61cc3e7 /bin/spamcat
parentb22b545fbe0f9d58792fd6b9659dd5013459c66d (diff)
downloadspamcat-f887806c5989fc3e5c86107d6ff945a6fc63b05c.tar.gz
spamcat-f887806c5989fc3e5c86107d6ff945a6fc63b05c.zip
Various changes.
* Use `env' to find perl binary. * Change flag --dumpconfig to command. * Add `dump' command to output table in tab-delimited format. * Update documentation.
Diffstat (limited to 'bin/spamcat')
-rwxr-xr-xbin/spamcat65
1 files changed, 42 insertions, 23 deletions
diff --git a/bin/spamcat b/bin/spamcat
index 2986382..fd37f76 100755
--- a/bin/spamcat
+++ b/bin/spamcat
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
=head1 NAME
@@ -6,27 +6,33 @@ spamcat - Filter spam by number of messages sent.
=head1 SYNOPSIS
-spamcat [options]
+spamcat [--help] [-c config-file] [dumpconfig|dump]
+
+=head1 DESCRIPTION
+
+B<spamcat> allows you to have disposable email addresses.
+
+=head1 OPTIONS
=over 8
-=item B<--help>
+=item --help
Print a brief help message and exit.
-=item B<-c> C<file>
+=item -c C<file>
Load configuration from C<file>
-=item B<--dumpconfig>
+=item dumpconfig
Dump the current configuration.
-=back
+=item dump
-=head1 DESCRIPTION
+Dumps the spamcat database in tab-delimited format.
-B<spamcat> allows you to have disposable email addresses.
+=back
=head1 AUTHOR
@@ -47,26 +53,39 @@ use warnings;
my $DEFAULT_CONFIGFILE = '/usr/local/etc/spamcat.conf';
-my ($help, $configfile, $dumpconfig);
+my ($help, $configfile);
GetOptions('help|h' => \$help,
- 'c=s' => \$configfile,
- 'dumpconfig' => \$dumpconfig) || pod2usage(2);
+ 'c=s' => \$configfile) || pod2usage(2);
pod2usage(1) if $help;
$configfile = $configfile || $DEFAULT_CONFIGFILE;
my %conf = SpamCat::Conf::read($configfile);
-if ($dumpconfig) {
- foreach my $k (keys %conf) {
- my $v = $conf{$k};
- if ($k eq 'domains') {
- $v = join ', ', @{$v};
+my $sch = SpamCat->new(%conf) ||
+ die "Couldn't start spamcat: $!\n";
+if ($#ARGV >= 0) {
+ my $cmd = shift @ARGV;
+ if ($cmd eq 'dump') {
+ my @keys = qw(sender count created modified);
+ print join("\t", @keys) . "\n";
+ foreach my $row (@{$sch->get_table}) {
+ my @vals;
+ foreach my $k (@keys) {
+ push @vals, $row->{$k};
+ }
+ print join("\t", @vals) . "\n";
+ }
+ } elsif ($cmd eq 'dumpconfig') {
+ foreach my $k (keys %conf) {
+ my $v = $conf{$k};
+ if ($k eq 'domains') {
+ $v = join ', ', @{$v};
+ }
+ print uc($k) . " = " . $v . "\n";
+ }
+ } else {
+ pod2usage(1);
}
- print uc($k) . " = " . $v . "\n";
- }
- exit;
+} else {
+ $sch->deliver;
}
-
-my $sch = SpamCat->new(%conf) ||
- die "Couldn't start spamcat: $!\n";
-$sch->deliver;