diff options
Diffstat (limited to 'check_bogofilter.py')
-rwxr-xr-x | check_bogofilter.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/check_bogofilter.py b/check_bogofilter.py index cb292eb..7f992ee 100755 --- a/check_bogofilter.py +++ b/check_bogofilter.py @@ -29,7 +29,7 @@ def move_messages(ids, target): client.uid('STORE', ids_str, '+FLAGS', r'(\Deleted)') -def process_folder(proc_fld_name, target_fld, unsure_fld, +def process_folder(proc_fld_name, target_fld, unsure_fld, spam_fld=None, bogofilter_param=['-l']): ham_msgs = [] @@ -84,10 +84,18 @@ def process_folder(proc_fld_name, target_fld, unsure_fld, else: # 3 or something else I/O error raise IOError('Bogofilter failed with error %d', ret_code) - move_messages(spam_msgs, target_fld) move_messages(unsure_msgs, unsure_fld) + log.debug('ham_msgs = %s, spam_msgs = %s' % (ham_msgs, spam_msgs)) if ham_msgs: - client.uid('STORE', ','.join(ham_msgs), '-FLAGS', r'(\Seen)') + if spam_fld is None: + client.uid('STORE', ','.join(ham_msgs), '-FLAGS', r'(\Seen)') + if spam_msgs: + if spam_fld is not None: + move_messages(spam_msgs, spam_fld) + else: + client.uid('STORE', ','.join(spam_msgs), + '+FLAGS.SILENT', r'(\Deleted \Seen)') + client.uid('EXPUNGE', ','.join(spam_msgs)) client.close() @@ -104,7 +112,7 @@ server = config.get("imap-training", "server") client = imaplib.IMAP4_SSL(server) client.login(login, password) -processedCounter += process_folder('INBOX', '_suspects', '_unsure') +processedCounter += process_folder('INBOX', '_suspects', '_unsure', '_spam') client.logout() |