Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://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":



  • 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 about the Monastery: (2)
As of 2024-04-26 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found