Add SMTP delivery labels

- SMTP delivery now has from and to labels for local addresses
This commit is contained in:
Peter Šurda 2016-07-09 09:58:01 +02:00
parent b8a08a0ce9
commit 8e066eaa97
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -1,4 +1,5 @@
from email.mime.text import MIMEText
from email.header import Header
import smtplib
import sys
import threading
@ -54,8 +55,12 @@ 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
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()