Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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; }

In reply to SpamAssassin IMAP client for exchange by anithri

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-24 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found