Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (4)
    As of 2020-11-24 01:11 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found