#!/usr/bin/perl # False Positive # # Douglas Thrift # # $Id$ use strict; use warnings; use IO::Socket::SSL; use Mail::IMAPClient; use Mail::SpamAssassin; use MIME::Base64; my $debug = 0; for my $arg (@ARGV) { if ($arg eq "-debug") { $debug = 1; } else { print "Usage: $0 [-debug]\n"; exit 1; } } my $socket = new IO::Socket::SSL(Proto => 'tcp', PeerAddr => 'mail.douglasthrift.net', PeerPort => 993, SSL_ca_file => '/home/douglas/cacert.pem', SSL_verify_mode => SSL_VERIFY_PEER) or die "$0: $@\n"; my $imap = new Mail::IMAPClient(Debug => $debug, Socket => $socket); { my $user = getpwuid $<; open PASS, "$ENV{HOME}/.SpamUpdate.pass" or die "$0: $!\n"; my $pass = ; chomp $pass; close PASS; $pass =~ tr/A-Za-z/N-ZA-Mn-za-m/; $imap->User($user); $imap->Password(decode_base64($pass)); } sub error { die "$0: " . $imap->LastError; } $imap->login or error; $imap->select('Spam.False Positive') or error; my @messages = $imap->search('UNFLAGGED'); error if ($@); if ($#messages != -1) { my $assassin = new Mail::SpamAssassin($debug ? {debug => 'all'} : {}); for my $message (@messages) { my @result = $imap->fetch($message, '(INTERNALDATE BODY[])') or error; die "$0: no message $message\n" if ($result[0] !~ /UID $message/); $result[0] =~ /INTERNALDATE "([^"]+)"/; $imap->append_string('INBOX', $assassin->remove_spamassassin_markup($assassin->parse($result[1])), undef, $1) or error; $imap->mark($message) or error; } } $imap->logout;