-
Notifications
You must be signed in to change notification settings - Fork 1
/
looks-hammy
executable file
·71 lines (55 loc) · 1.74 KB
/
looks-hammy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl -wT
#
# Copyright 2015 by Christian Jaeger, ch at christianjaeger ch
# Published under the same terms as perl itself
#
(my $email='ch%christianjaeger,ch')=~ tr/%,/@./;
use strict; use warnings FATAL => 'uninitialized';
use Cwd 'abs_path';
our ($mydir, $myname); BEGIN {
my $location= (-l $0) ? abs_path ($0) : $0;
$location=~ /(.*?)([^\/]+?)_?\z/s or die "?";
($mydir, $myname)=($1,$2);
}
use lib "$mydir/lib";
use lib "$mydir/functional-perl/lib";
use Carp;
use Chj::Backtrace;
#use Chj::WithRepl qw(push_withrepl WithRepl_eval);
#push_withrepl (0) if $DEBUG;
use Mailmover::MailHead;
use Chj::xopen qw(glob_to_fh);
our $cut_off_score= 2;
sub usage {
print STDERR map{"$_\n"} @_ if @_;
print "$myname source [cut-off-score]
source: file path or '-' for stdin; in the latter case the
filehandle is rewound, so that $myname can be used in .qmail
files
cut-off-score: below which score to return success (default: $cut_off_score)
(Christian Jaeger <$email>)
";
exit @_ ? 1 : 0;
}
usage "wrong number of arguments" unless (@ARGV==2 or @ARGV==1);
my ($source,$maybe_cut_off_score)= @ARGV;
usage if ($source eq "--help" or $source eq "-h");
# XX hmm, and now need "--" quoting as *always*?
$cut_off_score= $maybe_cut_off_score if defined $maybe_cut_off_score;
# XX check if number?
my $head= do {
if ($source eq "-") {
my $in= glob_to_fh *STDIN;
my $h= Mailmover::MailHead->new_from_fh($in);
$in->xrewind;
$h
} else {
Mailmover::MailHead->new_from_path($source);
}
};
if (defined (my $score= $head->maybe_spamscore)) {
exit ($score < $cut_off_score ? 0 : 1);
} else {
warn "message does not contain a spam score; be safe and exit 1";
exit 1
}