diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2017-10-23 20:38:35 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2017-10-23 20:40:47 +0200 |
commit | cc52a775a514b30311c1f8f0ee17095a2088c8a0 (patch) | |
tree | 5a1f6d7caf71b0af5507bf132d0d29cb2e65822b /train_bogofilter.py | |
parent | b3dd3baf5dd4540ffd9adef15432960e3708ce7d (diff) | |
download | imap-folder-training-cc52a775a514b30311c1f8f0ee17095a2088c8a0.tar.gz |
Use logging better.
Diffstat (limited to 'train_bogofilter.py')
-rwxr-xr-x | train_bogofilter.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/train_bogofilter.py b/train_bogofilter.py index 48f20bc..beadacf 100755 --- a/train_bogofilter.py +++ b/train_bogofilter.py @@ -5,21 +5,26 @@ import logging import os.path import subprocess from ConfigParser import ConfigParser + logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', level=logging.DEBUG) +log = logging.getLogger('train_bogofilter') CMD_STR = "/usr/bin/bogofilter -%s" -imaplib.Debug = 4 + +if log.getEffectiveLevel() >= logging.DEBUG: + imaplib.Debug = 4 + def process_folder(proc_fld_name, bogofilter_param, end_fld_name, mark_seen=True): client.select(proc_fld_name) _, resp = client.search(None, "ALL") messages = resp[0].split() - logging.debug('messages = %s', messages) + log.debug('messages = %s', messages) proc_msg_count = 0 for msgId in messages: - logging.debug('msgId = %s', msgId) + log.debug('msgId = %s', msgId) typ, msg_data = client.fetch(msgId, '(RFC822)') msg = hparser.parsestr(msg_data[0][1]) @@ -29,13 +34,13 @@ def process_folder(proc_fld_name, bogofilter_param, end_fld_name, mark_seen=True shell=True) ret.communicate(input=msg_data[0][1]) - logging.debug("ret.returncode = %s", ret.returncode) + log.debug("ret.returncode = %s", ret.returncode) if ret.returncode == 0: del msg['X-Bogosity'] typ, newmsg = client.append(end_fld_name, '', '', msg.as_string(True)) - logging.debug("typ = %s", typ) - logging.debug("newmsg = %s", newmsg) + log.debug("typ = %s", typ) + log.debug("newmsg = %s", newmsg) # if mark_seen: # client.store(newmsg, '+FLAGS', r'(\Seen)') if typ != 'OK': @@ -65,11 +70,11 @@ client = imaplib.IMAP4_SSL(server) client.login(login, password) for box in [('Junk', 's', 'Trash', True), ('Ham', 'n', 'INBOX', False)]: - logging.debug('box = %s', box) + log.debug('box = %s', box) # processedCounter += process_folder(box[0], box[1], box[2], box[3) processedCounter += process_folder(*box) client.logout() if processedCounter > 0: - logging.info("Processed %d spam messages.", processedCounter) + log.info("Processed %d spam messages.", processedCounter) |