diff options
Diffstat (limited to 'train_bogofilter')
-rwxr-xr-x | train_bogofilter | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/train_bogofilter b/train_bogofilter index d4e5bb2..7a4eff2 100755 --- a/train_bogofilter +++ b/train_bogofilter @@ -3,47 +3,47 @@ import imaplib, subprocess, email, sys import logging import email.Parser from ConfigParser import ConfigParser +logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', + level=logging.DEBUG) cmd_string = "/usr/bin/dspam --user dspam --class=spam "\ - + "--source=error --deliver=summary --stdout --signature='%s'" + + "--source=error --deliver=summary --stdout --signature='%s'" -DEBUG=False - -def debug(msg): - if DEBUG: - print >>sys.stderr,msg +DEBUG = False hparser = email.Parser.Parser() config = ConfigParser() -config.read("/etc/dspam-imap-train.cfg") +config.read("/etc/bogofilter-imap-train.cfg") -login = config.get("imap-training","login") -password = config.get("imap-training","password") +login = config.get("imap-training", "login") +password = config.get("imap-training", "password") client = imaplib.IMAP4_SSL("luther.ceplovi.cz") client.login(login, password) client.select("Public folders/Junk") status, resp = client.search(None, "ALL") messages = resp[0].split() processedCounter = 0 -debug(messages) +logging.debug(messages) for msgId in messages: # or no .PEEK ... do I want to mark a message as Seen? - typ, msg_data = client.fetch(msgId, '(BODY.PEEK[HEADER.FIELDS (SUBJECT FROM X-DSPAM-SIGNATURE)])') - debug("msgId = %s" % msgId) - headers = hparser.parsestr(msg_data[0][1],headersonly=True) - debug("headers:\n%s" % headers) + typ, msg_data = client.fetch( + msgId, '(BODY.PEEK[HEADER.FIELDS (SUBJECT FROM X-DSPAM-SIGNATURE)])') + logging.debug("msgId = %s" % msgId) + headers = hparser.parsestr(msg_data[0][1], headersonly=True) + logging.debug("headers:\n%s" % headers) if 'X-Dspam-Signature' in headers.keys(): - ret = subprocess.Popen(cmd_string \ - % headers['X-Dspam-Signature'], shell=True).wait() + ret = subprocess.Popen(cmd_string + % headers['X-Dspam-Signature'], + shell=True).wait() if ret == 0: typ, response = client.store(msgId, '+FLAGS', r'(\Deleted)') processedCounter += 1 else: - raise OSError, "dspam finished with failure code: %d" % ret + raise OSError("dspam finished with failure code: %d" % ret) client.expunge() client.close() client.logout() if processedCounter > 0: - debug("Processed %d spam messages." % processedCounter) + logging.info("Processed %d spam messages." % processedCounter) |