# HG changeset patch # User Paul Boddie # Date 1508001009 -7200 # Node ID 644b7e2590595de06a964a3c949465d0d0fad573 # Parent a7f94e62243e19f495986f7e3c35f3a8f233acb7 Support BCC sending suppression so that routines requesting it can still be used with senders that will not support it, usually because there are no outgoing routing destinations for those senders. diff -r a7f94e62243e -r 644b7e259059 imiptools/mail.py --- a/imiptools/mail.py Sat Oct 14 16:42:55 2017 +0200 +++ b/imiptools/mail.py Sat Oct 14 19:10:09 2017 +0200 @@ -44,11 +44,19 @@ "Sending of outgoing messages." - def __init__(self, lmtp_socket=None, local_smtp=False, sender=None, subject=None, preamble_text=None): + def __init__(self, lmtp_socket=None, local_smtp=False, sender=None, + subject=None, preamble_text=None, suppress_bcc=False): """ Deliver to a local mail system using LMTP if 'lmtp_socket' is provided or if 'local_smtp' is given as a true value. + + Use 'sender' as the sender identity (or the configured default if not + specified). Use any explicitly specified 'subject' and 'preamble_text' + in sent messages. + + Where 'suppress_bcc' is set to a true value, messages will not be sent + to an outgoing destination for the sender even if this is requested. """ self.lmtp_socket = lmtp_socket @@ -56,6 +64,7 @@ self.sender = sender or MESSAGE_SENDER self.subject = subject self.preamble_text = preamble_text + self.suppress_bcc = suppress_bcc # The translation method is set by the client once locale information is # known. @@ -85,7 +94,7 @@ else: smtp = SMTP("localhost") - if outgoing_bcc: + if outgoing_bcc and not self.suppress_bcc: recipients = list(recipients) + ["%s+%s" % (OUTGOING_PREFIX, outgoing_bcc)] elif self.local_smtp: recipients = [self.make_local(recipient) for recipient in recipients] @@ -121,8 +130,10 @@ message["From"] = sender or self.sender for recipient in recipients: message["To"] = recipient - if outgoing_bcc: + + if outgoing_bcc and not self.suppress_bcc: message["Bcc"] = "%s+%s" % (OUTGOING_PREFIX, outgoing_bcc) + message["Subject"] = self.subject or \ self.gettext and self.gettext(MESSAGE_SUBJECT) or MESSAGE_SUBJECT