http://qs321.pair.com?node_id=195210

for reasons I don't care to discuss I use Outlook/Exchange as my primary mailer. I have been searcing for ways to use SpamAssassin with Outlook that doesn't screw up the integrity of the email in outlook (stupid MS MIME problems and such). After reading about the POP3 proxy, i twigged on the idea of using IMAP to shuffle message between mailboxes. There is no rewriting of messages with the SpamAssassin messages. This is a working script using perl 5.6.1 on RedHat. YMMV
#!/opt/perl/bin/perl -w use strict; use Mail::IMAPClient; use Mail::SpamAssassin; use Mail::Audit; use Carp; use Proc::Daemon; #Set initial Values. my $inbox = "INBOX"; #Name of Mailbox to check for Spam in my $junk = "Junk Mail"; #Name of Mailbox to Move Spam To my $user = ""; #IMAP user name my $host = ""; #IMAP host name or IP address my $interval = 300; #Duration in seconds to wait between cy +cles #Password is not hardcoded and not entered on commandline for security + purposes print "Password: "; my $password = <>; chomp $password; #Get rid of Zombie problems $SIG{CHLD} = 'IGNORE'; #Run as Daemon Proc::Daemon::Init; #Initialize SpamAssassin my $spamtest = Mail::SpamAssassin->new(); #loop while (1) { #connect to imap server my $imap = Mail::IMAPClient->new(User=>$user,Password=>$password,S +erver=>$host,UID=>1, Peek=>1) or die "Incorrect Password"; #Operate on $inbox $imap->select($inbox); #Retrieve list of messages my @messages = $imap->messages; #loop through messages foreach my $msg (@messages) { #get whole message and save in array. my $msgtxt = $imap->message_string($msg); my $hashref = $imap->parse_headers($msg,"Subject"); #check $msgtxt for spam my $status = $spamtest->check_message_text($msgtxt); #print $hashref->{Subject}->[0] . " " . $status->get_hits . "\ +n"; if ($status->is_spam()) { #move suspected spam to junk box my $yes = $imap->move($junk,$msg); if ($yes) { #If we successfully moved it, then delete it from inbo +x $imap->delete_message($msg); } } } #Close IMAP session $imap->close; #sleep #exit; sleep $interval; }