summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2014-03-08 00:30:05 +0100
committerMatěj Cepl <mcepl@redhat.com>2014-03-08 00:37:02 +0100
commit2be0c87e00e363f1bc6eea5d26fa4148ba21b2d0 (patch)
tree1a91946b10fc8e079bce4c7d5c4560bc922dacfc
parent63f7a24696ea77bad957d8e634ae908d58966c91 (diff)
downloadimap-folder-training-2be0c87e00e363f1bc6eea5d26fa4148ba21b2d0.tar.gz
Let train_dspam_from_folder generate debug messages.
-rwxr-xr-xtrain_bogofilter49
-rwxr-xr-xtrain_dspam_from_folder13
2 files changed, 60 insertions, 2 deletions
diff --git a/train_bogofilter b/train_bogofilter
new file mode 100755
index 0000000..d4e5bb2
--- /dev/null
+++ b/train_bogofilter
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+import imaplib, subprocess, email, sys
+import logging
+import email.Parser
+from ConfigParser import ConfigParser
+
+cmd_string = "/usr/bin/dspam --user dspam --class=spam "\
+ + "--source=error --deliver=summary --stdout --signature='%s'"
+
+DEBUG=False
+
+def debug(msg):
+ if DEBUG:
+ print >>sys.stderr,msg
+
+hparser = email.Parser.Parser()
+config = ConfigParser()
+config.read("/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(login, password)
+client.select("Public folders/Junk")
+status, resp = client.search(None, "ALL")
+messages = resp[0].split()
+processedCounter = 0
+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)
+ if 'X-Dspam-Signature' in headers.keys():
+ 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()
+if processedCounter > 0:
+ debug("Processed %d spam messages." % processedCounter)
diff --git a/train_dspam_from_folder b/train_dspam_from_folder
index 2aed4b7..6cc9323 100755
--- a/train_dspam_from_folder
+++ b/train_dspam_from_folder
@@ -1,12 +1,18 @@
#!/usr/bin/python
# Mind you, we have only python 2.4.3 on RHEL-5
-import imaplib, subprocess, email
+import imaplib, subprocess, email, sys
import email.Parser
from ConfigParser import ConfigParser
cmd_string = "/usr/bin/dspam --user dspam --class=spam "\
+ "--source=error --deliver=summary --stdout --signature='%s'"
+DEBUG=False
+
+def debug(msg):
+ if DEBUG:
+ print >>sys.stderr,msg
+
hparser = email.Parser.Parser()
config = ConfigParser()
config.read("/etc/dspam-imap-train.cfg")
@@ -19,11 +25,14 @@ client.select("Public folders/Junk")
status, resp = client.search(None, "ALL")
messages = resp[0].split()
processedCounter = 0
+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)
if 'X-Dspam-Signature' in headers.keys():
ret = subprocess.Popen(cmd_string \
% headers['X-Dspam-Signature'], shell=True).wait()
@@ -37,4 +46,4 @@ client.expunge()
client.close()
client.logout()
if processedCounter > 0:
- print "Processed %d spam messages." % processedCounter
+ debug("Processed %d spam messages." % processedCounter)