summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-03-04 11:50:39 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-03-04 11:50:39 +0100
commit08a470594891bf962fa38dfcbaf89753c03e5481 (patch)
treeae6f3037e95a296da2f452ac4dbf207df4fde2ad
parent157d4a04514c2400a161ff3185cc6ca8791365db (diff)
downloadimap-folder-training-08a470594891bf962fa38dfcbaf89753c03e5481.tar.gz
Don't publish our secrets and report number of processed messages.
-rwxr-xr-xtrain_dspam_from_folder12
1 files changed, 9 insertions, 3 deletions
diff --git a/train_dspam_from_folder b/train_dspam_from_folder
index 75ace1a..7d37cb1 100755
--- a/train_dspam_from_folder
+++ b/train_dspam_from_folder
@@ -2,32 +2,38 @@
# Mind you, we have only python 2.4.3 on RHEL-5
import imaplib, subprocess, email
import email.Parser
+from ConfigParser import ConfigParser
cmd_string = "/usr/bin/dspam --user dspam --class=spam "\
+ "--source=error --deliver=summary --stdout --signature='%s'"
hparser = email.Parser.Parser()
+config = ConfigParser()
+config.read(os.path.expanduser("/etc/dspam-imap-train.cfg"))
+login = config.get("imap-training","login")
+password = config.get("imap-training","password")
client = imaplib.IMAP4_SSL("luther.ceplovi.cz")
-client.login("dspam","hnus")
+client.login(login, password)
client.select("Public folders/Junk")
status, resp = client.search(None, "ALL")
messages = resp[0].split()
+processedCounter = 0
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)])')
headers = hparser.parsestr(msg_data[0][1],headersonly=True)
- print headers.keys()
if 'X-Dspam-Signature' in headers.keys():
- print headers['X-Dspam-Signature']
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
client.expunge()
client.close()
client.logout()
+print "Processed %d spam messages." % processedCounter