diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-01-29 17:57:27 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-01-29 17:57:27 +0100 |
commit | 14ea4fac931371709879c2ee24bed9ffe172bf3b (patch) | |
tree | fc169c3224c074ae876fbb2fb0423ea358cf7496 | |
parent | 75566e1d078f6352c951196071b7d59f2f3b64bf (diff) | |
download | imap-folder-training-14ea4fac931371709879c2ee24bed9ffe172bf3b.tar.gz |
Should be working again.
* we have python 2.4.3 only on RHEL-5
* download only headers we need
-rwxr-xr-x | train_dspam_from_folder | 38 |
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() |