ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/Mail/FalsePositive.pl
Revision: 831
Committed: 2006-07-07T04:37:49-07:00 (19 years ago) by douglas
Content type: text/x-perl
File size: 1937 byte(s)
Log Message:
Woo!

File Contents

# User Rev Content
1 douglas 811 #!/usr/bin/perl
2     # False Positive
3     #
4     # Douglas Thrift
5     #
6     # $Id$
7    
8     use strict;
9     use warnings;
10    
11 douglas 829 use Mail::Cclient;
12 douglas 811 use Mail::SpamAssassin;
13 douglas 829 use POSIX qw(:signal_h);
14 douglas 811
15 douglas 829 my $error;
16     my $debug = 0;
17     my @messages;
18     my $critical = 0;
19     my $set = POSIX::SigSet->new(&POSIX::SIGHUP, &POSIX::SIGINT);
20 douglas 811
21 douglas 829 for my $arg (@ARGV)
22 douglas 811 {
23 douglas 829 if ($arg eq "-debug")
24     {
25     $debug = 1;
26     }
27     else
28     {
29     print "Usage: $0 [-debug]\n";
30    
31     exit 1;
32     }
33 douglas 811 }
34    
35 douglas 831 Mail::Cclient::set_callback(searched => \&mm_searched, log => \&mm_log, dlog => \&mm_dlog, critical => \&mm_critical, nocritical => \&mm_nocritical, diskerror => \&mm_diskerror, fatal => \&mm_fatal);
36 douglas 811
37 douglas 829 my $positive = Mail::Cclient->new('Spam/False Positive', $debug ? 'debug' : ()) or die "$0: $error\n";
38    
39     $positive->search(SEARCH => 'UNFLAGGED');
40    
41     my $assassin = Mail::SpamAssassin->new($debug ? {debug => 'all'} : {});
42    
43     $positive->fetch_flags(join(',', @messages));
44    
45     for my $message (@messages)
46     {
47     my $message_ = $assassin->remove_spamassassin_markup($assassin->parse($positive->fetch_message($message)));
48    
49     # XXX: stupid SpamAssassin!
50     if ($message_ =~ /^((?:[!-9;-~]+:[^\r\n]+\n(?:[ \t][^\r\n]+\n)*)+\n)(.*)$/s)
51     {
52     my ($header, $body) = ($1, $2);
53    
54     $header =~ s/\n/\r\n/gs;
55    
56     $message_ = $header . $body;
57     }
58    
59     $positive->append('INBOX', $message_, $positive->elt($message)->imapdate);
60     $positive->setflag($message, '\Flagged');
61     }
62    
63     $positive->close();
64    
65     sub mm_searched
66     {
67     $messages[$#messages + 1] = $_[1];
68     }
69    
70     sub mm_log
71     {
72     if ($debug)
73     {
74     print "$_[1]: $_[0]\n";
75     }
76    
77     if ($_[1] eq 'error')
78     {
79     $error = $_[0];
80     }
81     }
82    
83     sub mm_dlog
84     {
85     print STDERR "$_[0]\n";
86     }
87    
88     sub mm_critical
89     {
90     if (!$critical++)
91     {
92     POSIX::sigprocmask(POSIX::SIG_BLOCK, $set) or die;
93     }
94     }
95    
96     sub mm_nocritical
97     {
98     if (!--$critical)
99     {
100     POSIX::sigprocmask(POSIX::SIG_UNBLOCK, $set) or die;
101     }
102     }
103    
104     sub mm_diskerror
105     {
106     print STDERR "diskerror:\n errcode = $_[1]\n serious = $_[2]\n";
107    
108     return 1;
109     }
110 douglas 831
111     sub mm_fatal
112     {
113     print STDERR "fatal:\n string = $_[0]\n";
114     }

Properties

Name Value
svn:executable *
svn:keywords Id