summaryrefslogtreecommitdiffstats
path: root/train_dspam_from_folder
diff options
context:
space:
mode:
Diffstat (limited to 'train_dspam_from_folder')
-rwxr-xr-xtrain_dspam_from_folder38
1 files changed, 21 insertions, 17 deletions
diff --git a/train_dspam_from_folder b/train_dspam_from_folder
index df12433..52df798 100755
--- a/train_dspam_from_folder
+++ b/train_dspam_from_folder
@@ -1,7 +1,12 @@
#!/usr/bin/python
-import imaplib, subprocess, sys, email, os
-cmd_string = "/usr/bin/dspam --user dspam --class=spam --source=error " \
- + "--deliver=summary --stdout --signature='%s' --debug"
+# Mind you, we have only python 2.4.3 on RHEL-5
+import imaplib, subprocess, email
+import email.Parser
+
+cmd_string = "/usr/bin/dspam --user dspam --debug --class=spam "\
+ + "--source=error --deliver=summary --stdout --signature='%s'"
+
+hparser = email.Parser.Parser()
client = imaplib.IMAP4_SSL("luther.ceplovi.cz")
client.login("dspam","hnus")
@@ -9,20 +14,19 @@ client.select("Public folders/Junk")
status, resp = client.search(None, "ALL")
messages = resp[0].split()
-for msg in messages:
- typ, msg_data = client.fetch(msg, '(RFC822)')
- for response_part in msg_data:
- if isinstance(response_part, tuple):
- message = email.message_from_string(response_part[1])
- for header in [ 'subject', 'x-dspam-signature', 'from' ]:
- print '%-8s: %s' \
- % (header.upper(), message[header])
- ret = subprocess.Popen(cmd_string \
- % message['x-dspam-signature'], shell=True).wait()
- if ret == 0:
- typ, response = client.store(msg, '+FLAGS', r'(\Deleted)')
- else:
- raise OSError, "dspam finished with failure code: %d" % ret
+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)')
+ else:
+ raise OSError, "dspam finished with failure code: %d" % ret
client.expunge()
client.close()