summaryrefslogtreecommitdiffstats
path: root/train_bogofilter.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2020-07-02 18:20:45 +0200
committerMatěj Cepl <mcepl@cepl.eu>2020-07-02 18:20:45 +0200
commit72bdf2ae75949ff86da0b31ceda6832e17af0f0f (patch)
tree5ef2db6c58af7f1abb9e11273d142d8da3f476c0 /train_bogofilter.py
parent8658b46267349eecf52b756228e02656850fcba1 (diff)
downloadimap-folder-training-master.tar.gz
Make train_bogofilter robust against msgs without Date header.HEADmaster
Diffstat (limited to 'train_bogofilter.py')
-rwxr-xr-xtrain_bogofilter.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/train_bogofilter.py b/train_bogofilter.py
index 8bde56b..afd99c7 100755
--- a/train_bogofilter.py
+++ b/train_bogofilter.py
@@ -6,6 +6,7 @@ import logging
import os.path
import re
import subprocess
+import time
from ConfigParser import ConfigParser
# logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
@@ -35,11 +36,15 @@ def process_folder(proc_fld_name, bogofilter_param, end_fld_name, mark_seen=True
msg = hparser.parsestr(msg_data[0][1])
date_str = msg['Date']
log.debug("date_str = %s", date_str)
- date_tuple=email.utils.parsedate_tz(date_str)
+ date_tuple = email.utils.parsedate_tz(date_str)
log.debug("date_tuple = %s", date_tuple)
# date_tulpe is 10-tuple (including time distance from GMT)
# but Time2Internaldate wants just 9-tuple
- int_date = imaplib.Time2Internaldate(date_tuple[:-1])
+ try:
+ int_date = imaplib.Time2Internaldate(date_tuple[:-1])
+ # For TypeError: 'NoneType' object is unsubscriptable
+ except TypeError:
+ int_date = imaplib.Time2Internaldate(time.gmtime(0))
log.debug("int_date = %s", int_date)
ret = subprocess.Popen(CMD_STR % bogofilter_param,