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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi, anithri. Thanks for this script. It proved to be VERY useful to me and some co-workers. I took the freedom to adapt your script a little bit... Tested under Debian 'Woody' with Perl v5.6.1, IMAPClient v2.1.4, SpamAssassin v2.60 and Exchange 2000. Primary changes include message rewriting, commandline switches and a check whether the mail was checked earlier...
#!/usr/bin/perl -w ### Modules use strict; use Mail::IMAPClient; use Mail::SpamAssassin; use Proc::Daemon; use Term::ReadKey; use Getopt::Long; ### Variables my ($spamtest, $imap, $status); my ($flag, $password, $msg, $msgtxt); my ($opt_user, $opt_host, $opt_help, $opt_interval); my @messages; ### Initial values my $inbox = "INBOX"; # Name of mailbox to check for SPAM in my $junk = "INBOX/SPAM"; # Name of mailbox to move SPAM to ### Main program print <<_EoT_; IMAP interface to SpamAssassin V1.0 (c)2003 Alexander J. Trentini (thanks to anithri of perlmonks.org) _EoT_ # Check commandline parameters GetOptions("user=s" => \$opt_user, # IMAP user name "host=s" => \$opt_host, # IMAP host name or IP add +res "interval=s" => \$opt_interval, # Check interval "help" => \$opt_help); # Usage text # Help text? if (defined($opt_help)) { print <<_EoT_; Usage: $0 [--user --host --interval] [--help] If no parameters are given on the commandline, the script enter +s interactive mode. Parameters: --help Prints this usage text --user IMAP user name to use --host IMAP host name or IP address to use --interval Check interval Note: The password will ALWAYS be read via interactive mode, du +e to security reasons! _EoT_ exit(1); } # Interactive mode? unless ($opt_host and $opt_user and $opt_interval) { print("Interactive mode.\n\n"); print("Check interval (seconds): "); $opt_interval = <>; chomp($opt_interval); print("IMAP host name or IP address: "); $opt_host = <>; chomp($opt_host); print("IMAP user name: "); $opt_user = <>; chomp($opt_user); } # Get password (always interactive) print "Password for $opt_user: "; ReadMode(2); $password = <>; chomp($password); ReadMode(0); print("\n"); # Interval ok? #TODO if ($opt_interval < 60) { die("Are you crazy? I'm just a little CELERON (60s interval min.)! +\n"); } # Get rid of zombie problems $SIG{CHLD} = 'IGNORE'; # Run as daemon Proc::Daemon::Init; # Initialize SpamAssassin $spamtest = Mail::SpamAssassin->new(); # Loop endlessly while (1) { # Connect to IMAP server $imap = Mail::IMAPClient->new(User => $opt_user, Password => $password, Server => $opt_host, UID => 1, Debug => 0, Peek => 1) or die("Couldn't conn +ect" . " to $opt_host using $opt_user (Incorrect password?).\n"); $imap->select($inbox); # Create $junk folder if not existant unless ($imap->exists($junk)) { $imap->create($junk); } # Omit already checked messages and messages within # the IXOS mail archive (compressed, would result in # garbage output) #TODO @messages = $imap->search('NOT HEADER X-Spam-Checker-Version "Spam +Assassin" NOT SUBJECT "IXOS"'); # Traverse messages foreach $msg (@messages) { # Only check if mail is smaller than 150KB (performance) next if ($imap->size($msg) > 153600); # Get message and pass to SpamAssassin $msgtxt = $imap->message_string($msg); $status = $spamtest->check_message_text($msgtxt); $status->rewrite_mail(); $msgtxt = $status->get_full_message_as_text(); if ($status->is_spam()) { $flag = $imap->append_string($junk, $msgtxt); } else { $flag = $imap->append_string($inbox, $msgtxt); } # If successfully created, delete original from inbox $imap->delete_message($msg) if ($flag); } # Close IMAP session $imap->close(); sleep $opt_interval; }

In reply to Re: SpamAssassin IMAP client for exchange by Anonymous Monk
in thread 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":



  • 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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (6)
    As of 2020-12-02 06:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (34 votes). Check out past polls.

      Notices?