1.1 --- a/imiptools/mail.py Thu Aug 20 23:52:18 2015 +0200
1.2 +++ b/imiptools/mail.py Fri Aug 21 14:47:53 2015 +0200
1.3 @@ -40,13 +40,15 @@
1.4
1.5 "Sending of outgoing messages."
1.6
1.7 - def __init__(self, lmtp_socket=None, sender=None, subject=None, body_text=None, preamble_text=None):
1.8 + def __init__(self, lmtp_socket=None, local_smtp=False, sender=None, subject=None, body_text=None, preamble_text=None):
1.9
1.10 """
1.11 - Deliver to a local mail system using LMTP if 'lmtp_socket' is provided.
1.12 + Deliver to a local mail system using LMTP if 'lmtp_socket' is provided
1.13 + or if 'local_smtp' is given as a true value.
1.14 """
1.15
1.16 self.lmtp_socket = lmtp_socket
1.17 + self.local_smtp = local_smtp
1.18 self.sender = sender or MESSAGE_SENDER
1.19 self.subject = subject or MESSAGE_SUBJECT
1.20 self.body_text = body_text or MESSAGE_TEXT
1.21 @@ -56,9 +58,9 @@
1.22
1.23 "Return whether local delivery is performed using this messenger."
1.24
1.25 - return self.lmtp_socket is not None
1.26 + return self.lmtp_socket is not None or self.local_smtp
1.27
1.28 - def sendmail(self, recipients, data, sender=None, outgoing_bcc=None, lmtp_socket=None):
1.29 + def sendmail(self, recipients, data, sender=None, outgoing_bcc=None):
1.30
1.31 """
1.32 Send a mail to the given 'recipients' consisting of the given 'data',
1.33 @@ -77,10 +79,27 @@
1.34
1.35 if outgoing_bcc:
1.36 recipients = list(recipients) + ["%s+%s" % (OUTGOING_PREFIX, outgoing_bcc)]
1.37 + elif self.local_smtp:
1.38 + recipients = [self.make_local(recipient) for recipient in recipients]
1.39
1.40 smtp.sendmail(sender or self.sender, recipients, data)
1.41 smtp.quit()
1.42
1.43 + def make_local(self, recipient):
1.44 +
1.45 + """
1.46 + Make the 'recipient' an address for local delivery. For this to function
1.47 + correctly, a virtual alias or equivalent must be defined for addresses
1.48 + of the following form:
1.49 +
1.50 + local+NAME@DOMAIN
1.51 +
1.52 + Such aliases should direct delivery to the local recipient.
1.53 + """
1.54 +
1.55 + parts = recipient.split("+", 1)
1.56 + return "%s+%s" % ("local", parts[-1])
1.57 +
1.58 def make_outgoing_message(self, parts, recipients, sender=None, outgoing_bcc=None):
1.59
1.60 """