aboutsummaryrefslogtreecommitdiffstats
path: root/climl/hooks.py
diff options
context:
space:
mode:
Diffstat (limited to 'climl/hooks.py')
-rw-r--r--climl/hooks.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/climl/hooks.py b/climl/hooks.py
index e4a0a8e..027329b 100644
--- a/climl/hooks.py
+++ b/climl/hooks.py
@@ -5,7 +5,7 @@ from . import interface
def hook_extract_listname(context):
lines = context['content'].split(b'\n')
for line in lines:
- if line.startswith(b'Delivered-To: '):
+ if line.startswith(b'To: '):
listname = line.split()[1].decode('ascii')
context['listname'] = listname.split('@')[0]
context['listaddress'] = listname
@@ -26,6 +26,20 @@ def hook_process_subscribe_queries(context):
pass
+def hook_modify_reply_to(context):
+ content = context['content']
+ listaddress = context['listaddress'].encode('ascii')
+ try:
+ index = content.index(b'\r\n\r\n')
+ context['content'] = b''.join([
+ content[0:index],
+ b'\r\nReply-To: ', listaddress, # same header line
+ content[index:]])
+ except ValueError as e:
+ raise interface.HookAbortError('bad email, missing header separator') \
+ from e
+
+
def hook_generate_rcpt_list(context):
listname = context.get('listname', None)
if not listname:
@@ -51,9 +65,10 @@ def hook_send_all(context):
raise interface.HookStopIteration()
# TODO: how to send emails here ?
- smtp_server = smtplib.SMTP(context['conf']['smtp.server'])
- #smtp_server.set_debuglevel(1)
- smtp_server.sendmail(listaddress,
- context['recipients'],
- context['content'])
- smtp_server.quit()
+ print('server_smtp:', context['conf']['smtp.server'])
+ with smtplib.SMTP('devys.org') as smtp_server:
+ #smtp_server.set_debuglevel(1)
+ smtp_server.sendmail(listaddress,
+ context['recipients'],
+ context['content'],
+ mail_options=['SMTPUTF8'])