summaryrefslogtreecommitdiffstats
path: root/ocrloader.py
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2014-09-23 12:25:57 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2014-09-23 12:25:57 (GMT)
commitddbcd61aa4f6863ae14198593f34e13b6b6ea14f (patch)
tree00df00c496071b7db457b7057fc881f1f358ea3b /ocrloader.py
parent410ea2902b8aa70b6198c1a8623a1b3a01d7576d (diff)
downloadpfwbged.ocrloader-ddbcd61aa4f6863ae14198593f34e13b6b6ea14f.zip
pfwbged.ocrloader-ddbcd61aa4f6863ae14198593f34e13b6b6ea14f.tar.gz
pfwbged.ocrloader-ddbcd61aa4f6863ae14198593f34e13b6b6ea14f.tar.bz2
handle more imap server failures
Diffstat (limited to 'ocrloader.py')
-rwxr-xr-xocrloader.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/ocrloader.py b/ocrloader.py
index 975a26d..a777f5c 100755
--- a/ocrloader.py
+++ b/ocrloader.py
@@ -126,10 +126,18 @@ while True:
M.login(section, cfg.get(section, 'password'))
except imaplib.IMAP4.error:
continue
- M.select()
+ try:
+ M.select()
+ except socket.error:
+ logging.error('failure talking to imap server')
+ continue
typ, data = M.search(None, '(NOT SEEN)')
for num in data[0].split():
- typ, data = M.fetch(num, '(RFC822)')
+ try:
+ typ, data = M.fetch(num, '(RFC822)')
+ except socket.error:
+ logging.error('failure talking to imap server')
+ break
msg = email.parser.Parser().parsestr(data[0][1])
enable_ocr = True
if 'disable_ocr' in msg['Subject']:
@@ -141,10 +149,18 @@ while True:
payload = part.get_payload(decode=True)
if not process(dict(cfg.items(section)), filename, payload, enable_ocr):
logging.error(' error -> marking as unseen')
- M.store(num, '-FLAGS', r'\Seen')
+ try:
+ M.store(num, '-FLAGS', r'\Seen')
+ except socket.error:
+ logging.error('failure talking to imap server')
+ pass
break
- M.close()
- M.logout()
+ try:
+ M.close()
+ M.logout()
+ except socket.error:
+ logging.error('failure talking to imap server')
+ pass
logging.debug('waiting a bit %s', time.strftime('%Y-%m-%d %H:%M:%S'))
time.sleep(30)