summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2014-03-08 00:36:56 +0100
committerMatěj Cepl <mcepl@redhat.com>2014-03-08 00:37:22 +0100
commitf182ad26146f0c266217e95d67912efda1233264 (patch)
tree39d5f8e2123ea16333d53eb2639bb5ff6ae0d197
parent2be0c87e00e363f1bc6eea5d26fa4148ba21b2d0 (diff)
downloadimap-folder-training-f182ad26146f0c266217e95d67912efda1233264.tar.gz
Start a bogofilter script
-rwxr-xr-xtrain_bogofilter36
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)