aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVG <vg@devys.org>2016-06-10 23:27:11 +0200
committerVG <vg@devys.org>2016-06-10 23:27:11 +0200
commit232e7d95f0f2d0b00c6476ac89d3f93691ba7b47 (patch)
treeaec32f6a4d2415a42285304ea379fb4af9b38205
parent6e62cf116d561dcb8c7b72c9c5165db97706fec8 (diff)
downloadcliml-232e7d95f0f2d0b00c6476ac89d3f93691ba7b47.tar.gz
climl-232e7d95f0f2d0b00c6476ac89d3f93691ba7b47.tar.bz2
climl-232e7d95f0f2d0b00c6476ac89d3f93691ba7b47.zip
simplify exception display, fix rcpt filename
-rw-r--r--climl/__init__.py9
-rw-r--r--climl/hooks.py8
-rw-r--r--climl/imap.py5
3 files changed, 13 insertions, 9 deletions
diff --git a/climl/__init__.py b/climl/__init__.py
index b4ccecf..e730690 100644
--- a/climl/__init__.py
+++ b/climl/__init__.py
@@ -3,10 +3,11 @@ from . import interface
from . import hooks
import confparser
import os
+import traceback
def on_email(content, hooks, conf):
- #print('on_email:', content)
+ print('▬▬▬▬▬▬▬▶')
context = dict(
conf=conf,
@@ -18,8 +19,10 @@ def on_email(content, hooks, conf):
print('on_email, calling hook {}'.format(hook.__name__))
hook(context)
print('on_email, end of hook {}'.format(hook.__name__))
- except interface.HookStopIteration as e:
- print('hook wanted to stop processing for current email', e)
+ except interface.HookStopIteration:
+ print('hook wanted to stop processing for current email')
+ traceback.print_exc()
+ print('◀▬▬▬▬▬▬▬')
print('now, raising exception (for dev purpose only)')
raise interface.HookAbortError('dev purpose abort')
diff --git a/climl/hooks.py b/climl/hooks.py
index a521376..e4a0a8e 100644
--- a/climl/hooks.py
+++ b/climl/hooks.py
@@ -5,10 +5,10 @@ from . import interface
def hook_extract_listname(context):
lines = context['content'].split(b'\n')
for line in lines:
- print('line: ', line)
if line.startswith(b'Delivered-To: '):
listname = line.split()[1].decode('ascii')
- context['listname'] = listname
+ context['listname'] = listname.split('@')[0]
+ context['listaddress'] = listname
print('found listname: {}'.format(listname))
return
raise interface.HookAbortError('listname not found')
@@ -30,7 +30,7 @@ def hook_generate_rcpt_list(context):
listname = context.get('listname', None)
if not listname:
raise interface.HookStopIteration('list name not found')
- recipients_filename = ''.join([listname, '-recipents.txt'])
+ recipients_filename = ''.join([listname, '-recipients.txt'])
try:
with open(recipients_filename, encoding='utf8') as fi:
recipients = [recipient for recipient in fi]
@@ -51,7 +51,7 @@ def hook_send_all(context):
raise interface.HookStopIteration()
# TODO: how to send emails here ?
- smtp_server = smtplib.SMTP(context.conf.get('smtp.server'))
+ smtp_server = smtplib.SMTP(context['conf']['smtp.server'])
#smtp_server.set_debuglevel(1)
smtp_server.sendmail(listaddress,
context['recipients'],
diff --git a/climl/imap.py b/climl/imap.py
index 5c66833..c23a006 100644
--- a/climl/imap.py
+++ b/climl/imap.py
@@ -5,6 +5,7 @@ import contextlib
import backports.ssl as ssl
import socket
import time
+import traceback
from . import interface
@@ -125,9 +126,9 @@ def process_emails(connection, callback=None, maxsize=None):
callback(data)
print('mark mail {}'.format(oneid))
connection.add_flags([oneid], ['\Answered'])
- except interface.HookAbortError as e:
+ except interface.HookAbortError:
print('callback wanted to skip marking of mail {}'.format(oneid))
- print('reason', e)
+ traceback.print_exc()
data = None