aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVG <vg@devys.org>2016-06-09 23:27:17 +0200
committerVG <vg@devys.org>2016-06-09 23:27:17 +0200
commitf168bde66cbbabe1fcec9b123a5be8e2cdf6ba38 (patch)
treec4d283ff7e63e023ed6d4a1212e0a3ae24bda7dc
parent30c21dc7f2f164e4b52940d4b394bfd0ac82df5e (diff)
downloadcliml-f168bde66cbbabe1fcec9b123a5be8e2cdf6ba38.tar.gz
climl-f168bde66cbbabe1fcec9b123a5be8e2cdf6ba38.tar.bz2
climl-f168bde66cbbabe1fcec9b123a5be8e2cdf6ba38.zip
make simpler context, detect listname
-rw-r--r--climl/__init__.py17
-rw-r--r--climl/hooks.py32
-rw-r--r--climl/imap.py3
3 files changed, 31 insertions, 21 deletions
diff --git a/climl/__init__.py b/climl/__init__.py
index 147dfc3..e46baab 100644
--- a/climl/__init__.py
+++ b/climl/__init__.py
@@ -8,22 +8,19 @@ import os
def on_email(content, hooks, conf):
#print('on_email:', content)
- class Context(dict):
- def __init__(self):
- self.conf = conf
+ context = dict(
+ conf=conf,
+ rawcontent=content,
+ )
- context = Context()
try:
for hook in hooks:
print('on_email, calling hook {}'.format(hook.__name__))
- context2, content2 = hook(context, content)
- if context2:
- context = context2
- if content2:
- content = content2
+ hook(context)
+ print('on_email, end of hook {}'.format(hook.__name__))
except interface.HookStopIteration:
pass
- print('now, raising exception')
+ print('now, raising exception (for dev purpose only)')
raise interface.HookAbortError()
diff --git a/climl/hooks.py b/climl/hooks.py
index cf8ae9d..fcc43f4 100644
--- a/climl/hooks.py
+++ b/climl/hooks.py
@@ -2,32 +2,44 @@ import smtplib
from . import interface
-def hook_extract_listname(context, content):
- print('hook_extract_listname:')
- print(content)
-
-
-def hook_check_ml_restrictions(context, content):
+def hook_extract_listname(context):
+ lines = 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
+ print('found listname: {}'.format(listname))
+ return
+ raise interface.HookAbortError('listname not found')
+
+
+def hook_check_ml_restrictions(context):
pass
-def hook_validate_poster(context, content):
+def hook_validate_poster(context):
pass
-def hook_process_subscribe_queries(context, content):
+def hook_process_subscribe_queries(context):
pass
-def hook_generate_rcpt_list(context, content):
+def hook_generate_rcpt_list(context):
+ print(1)
listname = context.get('listname', None)
+ print(2)
if not listname:
raise interface.HookStopIteration('list name not found')
+ print(3)
recipients_filename = ''.join([listname, '-recipents.txt'])
+ print(4)
try:
with open(recipients_filename, encoding='utf8') as fi:
recipients = [recipient for recipient in fi]
context['recipients'] = recipients
+ print(5)
except FileNotFoundError as e:
n = interface.HookAbortError('recipients list not found')
n.args.append({'listname': listname,
@@ -35,7 +47,7 @@ def hook_generate_rcpt_list(context, content):
raise n from e
-def hook_send_all(context, content):
+def hook_send_all(context):
listaddress = context.get('listaddress', None)
if not listaddress:
raise interface.HookStopIteration('list address not found')
diff --git a/climl/imap.py b/climl/imap.py
index b21a8f6..7743712 100644
--- a/climl/imap.py
+++ b/climl/imap.py
@@ -121,7 +121,8 @@ def process_emails(connection, callback=None, maxsize=None):
data = response[oneid][b'RFC822']
print('calling callback...')
try:
- callback('mail: ' + str(oneid) + ': ' + str(data))
+ #callback('mail: ' + str(oneid) + ': ' + str(data))
+ callback(data)
print('mark mail {}'.format(oneid))
connection.add_flags([oneid], ['\Answered'])
except interface.HookAbortError: