From 8e066eaa9707536a59d03b0d729d070c342adba5 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sat, 9 Jul 2016 09:58:01 +0200 Subject: [PATCH] Add SMTP delivery labels - SMTP delivery now has from and to labels for local addresses --- src/class_smtpDeliver.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/class_smtpDeliver.py b/src/class_smtpDeliver.py index 2c63d830..42baf989 100644 --- a/src/class_smtpDeliver.py +++ b/src/class_smtpDeliver.py @@ -1,4 +1,5 @@ from email.mime.text import MIMEText +from email.header import Header import smtplib import sys import threading @@ -54,9 +55,13 @@ class smtpDeliver(threading.Thread, StoppableThread): to = urlparse.parse_qs(u.query)['to'] client = smtplib.SMTP(u.hostname, u.port) msg = MIMEText(body, 'plain', 'utf-8') - msg['Subject'] = subject + msg['Subject'] = Header(subject, 'utf-8') msg['From'] = fromAddress + '@' + SMTPDOMAIN - msg['To'] = toAddress + '@' + SMTPDOMAIN + toLabel = map (lambda y: shared.safeConfigGet(y, "label"), filter(lambda x: x == toAddress, shared.config.sections())) + if len(toLabel) > 0: + msg['To'] = "\"%s\" <%s>" % (Header(toLabel[0], 'utf-8'), toAddress + '@' + SMTPDOMAIN) + else: + msg['To'] = toAddress + '@' + SMTPDOMAIN client.ehlo() client.starttls() client.ehlo()