# HG changeset patch # User Paul Boddie # Date 1438007380 -7200 # Node ID ed0f68dfd13d34161764f99393ecd14089267b2f # Parent d75510f99c062055b79f63602dcb69915e820036 Propagated various parameters to the recipient abstraction, changing the messenger to be initialised with any LMTP socket information. diff -r d75510f99c06 -r ed0f68dfd13d imiptools/__init__.py --- a/imiptools/__init__.py Sun Jul 26 23:43:26 2015 +0200 +++ b/imiptools/__init__.py Mon Jul 27 16:29:40 2015 +0200 @@ -50,9 +50,9 @@ "The processing framework." - def __init__(self, handlers, messenger=None): + def __init__(self, handlers): self.handlers = handlers - self.messenger = messenger or Messenger() + self.messenger = None self.lmtp_socket = None self.store_dir = None self.publishing_dir = None @@ -85,13 +85,13 @@ if not outgoing_only: original_recipients = original_recipients or get_addresses(get_all_values(msg, "To") or []) for recipient in original_recipients: - Recipient(get_uri(recipient), messenger, store, publisher, self).process(msg, senders, outgoing_only) + Recipient(get_uri(recipient), messenger, store, publisher, self.handlers, self.debug).process(msg, senders, outgoing_only) # However, outgoing messages do not usually presume anything about the # eventual recipients. else: - Recipient(None, messenger, store, publisher, self).process(msg, senders, outgoing_only) + Recipient(None, messenger, store, publisher, self.handlers, self.debug).process(msg, senders, outgoing_only) def process_args(self, args, stream): @@ -151,8 +151,7 @@ else: l.append(arg) - self.messenger.sender = senders and senders[0] or self.messenger.sender - self.lmtp_socket = lmtp and lmtp[0] or None + self.messenger = Messenger(lmtp_socket=lmtp and lmtp[0] or None, sender=senders and senders[0] or None) self.store_dir = store_dir and store_dir[0] or None self.publishing_dir = publishing_dir and publishing_dir[0] or None self.process(stream, original_recipients, outgoing_only) @@ -192,15 +191,16 @@ "A processor acting as a client on behalf of a recipient." - def __init__(self, user, messenger, store, publisher, processor): + def __init__(self, user, messenger, store, publisher, handlers, debug): """ Initialise the recipient with the given 'user' identity, 'messenger', - 'store', 'publisher' and 'processor'. + 'store', 'publisher' and 'debug' status. """ Client.__init__(self, user, messenger, store, publisher) - self.processor = processor + self.handlers = handlers + self.debug = debug def process(self, msg, senders, outgoing_only): @@ -214,7 +214,7 @@ handlers = dict([(name, cls(senders, self.user and get_address(self.user), self.messenger, self.store, self.publisher)) - for name, cls in self.processor.handlers]) + for name, cls in self.handlers]) handled = False for part in msg.walk(): @@ -266,7 +266,7 @@ if fb: parts.append(fb) message = self.messenger.make_outgoing_message(parts, [outgoing_recipient]) - if self.processor.debug: + if self.debug: print >>sys.stderr, "Outgoing parts for %s..." % outgoing_recipient print message else: @@ -297,20 +297,20 @@ messages = [self.messenger.wrap_message(msg, forwarded_parts)] for message in messages: - if self.processor.debug: + if self.debug: print >>sys.stderr, "Forwarded parts..." print message - elif self.processor.lmtp_socket: - self.messenger.sendmail(get_address(self.user), message.as_string(), lmtp_socket=self.processor.lmtp_socket) + elif self.messenger.local_delivery(): + self.messenger.sendmail(get_address(self.user), message.as_string()) # Unhandled messages are delivered as they are. if not handled: - if self.processor.debug: + if self.debug: print >>sys.stderr, "Unhandled parts..." print msg - elif self.processor.lmtp_socket: - self.messenger.sendmail(get_address(self.user), msg.as_string(), lmtp_socket=self.processor.lmtp_socket) + elif self.messenger.local_delivery(): + self.messenger.sendmail(get_address(self.user), msg.as_string()) def can_provide_freebusy(self, handlers): diff -r d75510f99c06 -r ed0f68dfd13d imiptools/mail.py --- a/imiptools/mail.py Sun Jul 26 23:43:26 2015 +0200 +++ b/imiptools/mail.py Mon Jul 27 16:29:40 2015 +0200 @@ -40,27 +40,38 @@ "Sending of outgoing messages." - def __init__(self, sender=None, subject=None, body_text=None, preamble_text=None): + def __init__(self, lmtp_socket=None, sender=None, subject=None, body_text=None, preamble_text=None): + + """ + Deliver to a local mail system using LMTP if 'lmtp_socket' is provided. + """ + + self.lmtp_socket = lmtp_socket self.sender = sender or MESSAGE_SENDER self.subject = subject or MESSAGE_SUBJECT self.body_text = body_text or MESSAGE_TEXT self.preamble_text = preamble_text or PREAMBLE_TEXT + def local_delivery(self): + + "Return whether local delivery is performed using this messenger." + + return self.lmtp_socket is not None + def sendmail(self, recipients, data, sender=None, outgoing_bcc=None, lmtp_socket=None): """ Send a mail to the given 'recipients' consisting of the given 'data', using the given 'sender' identity if indicated, indicating an - 'outgoing_bcc' identity if indicated, delivering to a local mail system - using LMTP if 'lmtp_socket' is provided. + 'outgoing_bcc' identity if indicated. The 'outgoing_bcc' argument is required when sending on behalf of a user from the calendar@domain address, since this will not be detected as a valid participant and handled using the outgoing transport. """ - if lmtp_socket: - smtp = LMTP(lmtp_socket) + if self.lmtp_socket: + smtp = LMTP(self.lmtp_socket) else: smtp = SMTP("localhost")