1.1 --- a/imiptools/__init__.py Sun Jul 26 23:43:26 2015 +0200
1.2 +++ b/imiptools/__init__.py Mon Jul 27 16:29:40 2015 +0200
1.3 @@ -50,9 +50,9 @@
1.4
1.5 "The processing framework."
1.6
1.7 - def __init__(self, handlers, messenger=None):
1.8 + def __init__(self, handlers):
1.9 self.handlers = handlers
1.10 - self.messenger = messenger or Messenger()
1.11 + self.messenger = None
1.12 self.lmtp_socket = None
1.13 self.store_dir = None
1.14 self.publishing_dir = None
1.15 @@ -85,13 +85,13 @@
1.16 if not outgoing_only:
1.17 original_recipients = original_recipients or get_addresses(get_all_values(msg, "To") or [])
1.18 for recipient in original_recipients:
1.19 - Recipient(get_uri(recipient), messenger, store, publisher, self).process(msg, senders, outgoing_only)
1.20 + Recipient(get_uri(recipient), messenger, store, publisher, self.handlers, self.debug).process(msg, senders, outgoing_only)
1.21
1.22 # However, outgoing messages do not usually presume anything about the
1.23 # eventual recipients.
1.24
1.25 else:
1.26 - Recipient(None, messenger, store, publisher, self).process(msg, senders, outgoing_only)
1.27 + Recipient(None, messenger, store, publisher, self.handlers, self.debug).process(msg, senders, outgoing_only)
1.28
1.29 def process_args(self, args, stream):
1.30
1.31 @@ -151,8 +151,7 @@
1.32 else:
1.33 l.append(arg)
1.34
1.35 - self.messenger.sender = senders and senders[0] or self.messenger.sender
1.36 - self.lmtp_socket = lmtp and lmtp[0] or None
1.37 + self.messenger = Messenger(lmtp_socket=lmtp and lmtp[0] or None, sender=senders and senders[0] or None)
1.38 self.store_dir = store_dir and store_dir[0] or None
1.39 self.publishing_dir = publishing_dir and publishing_dir[0] or None
1.40 self.process(stream, original_recipients, outgoing_only)
1.41 @@ -192,15 +191,16 @@
1.42
1.43 "A processor acting as a client on behalf of a recipient."
1.44
1.45 - def __init__(self, user, messenger, store, publisher, processor):
1.46 + def __init__(self, user, messenger, store, publisher, handlers, debug):
1.47
1.48 """
1.49 Initialise the recipient with the given 'user' identity, 'messenger',
1.50 - 'store', 'publisher' and 'processor'.
1.51 + 'store', 'publisher' and 'debug' status.
1.52 """
1.53
1.54 Client.__init__(self, user, messenger, store, publisher)
1.55 - self.processor = processor
1.56 + self.handlers = handlers
1.57 + self.debug = debug
1.58
1.59 def process(self, msg, senders, outgoing_only):
1.60
1.61 @@ -214,7 +214,7 @@
1.62
1.63 handlers = dict([(name, cls(senders, self.user and get_address(self.user),
1.64 self.messenger, self.store, self.publisher))
1.65 - for name, cls in self.processor.handlers])
1.66 + for name, cls in self.handlers])
1.67 handled = False
1.68
1.69 for part in msg.walk():
1.70 @@ -266,7 +266,7 @@
1.71 if fb: parts.append(fb)
1.72 message = self.messenger.make_outgoing_message(parts, [outgoing_recipient])
1.73
1.74 - if self.processor.debug:
1.75 + if self.debug:
1.76 print >>sys.stderr, "Outgoing parts for %s..." % outgoing_recipient
1.77 print message
1.78 else:
1.79 @@ -297,20 +297,20 @@
1.80 messages = [self.messenger.wrap_message(msg, forwarded_parts)]
1.81
1.82 for message in messages:
1.83 - if self.processor.debug:
1.84 + if self.debug:
1.85 print >>sys.stderr, "Forwarded parts..."
1.86 print message
1.87 - elif self.processor.lmtp_socket:
1.88 - self.messenger.sendmail(get_address(self.user), message.as_string(), lmtp_socket=self.processor.lmtp_socket)
1.89 + elif self.messenger.local_delivery():
1.90 + self.messenger.sendmail(get_address(self.user), message.as_string())
1.91
1.92 # Unhandled messages are delivered as they are.
1.93
1.94 if not handled:
1.95 - if self.processor.debug:
1.96 + if self.debug:
1.97 print >>sys.stderr, "Unhandled parts..."
1.98 print msg
1.99 - elif self.processor.lmtp_socket:
1.100 - self.messenger.sendmail(get_address(self.user), msg.as_string(), lmtp_socket=self.processor.lmtp_socket)
1.101 + elif self.messenger.local_delivery():
1.102 + self.messenger.sendmail(get_address(self.user), msg.as_string())
1.103
1.104 def can_provide_freebusy(self, handlers):
1.105
2.1 --- a/imiptools/mail.py Sun Jul 26 23:43:26 2015 +0200
2.2 +++ b/imiptools/mail.py Mon Jul 27 16:29:40 2015 +0200
2.3 @@ -40,27 +40,38 @@
2.4
2.5 "Sending of outgoing messages."
2.6
2.7 - def __init__(self, sender=None, subject=None, body_text=None, preamble_text=None):
2.8 + def __init__(self, lmtp_socket=None, sender=None, subject=None, body_text=None, preamble_text=None):
2.9 +
2.10 + """
2.11 + Deliver to a local mail system using LMTP if 'lmtp_socket' is provided.
2.12 + """
2.13 +
2.14 + self.lmtp_socket = lmtp_socket
2.15 self.sender = sender or MESSAGE_SENDER
2.16 self.subject = subject or MESSAGE_SUBJECT
2.17 self.body_text = body_text or MESSAGE_TEXT
2.18 self.preamble_text = preamble_text or PREAMBLE_TEXT
2.19
2.20 + def local_delivery(self):
2.21 +
2.22 + "Return whether local delivery is performed using this messenger."
2.23 +
2.24 + return self.lmtp_socket is not None
2.25 +
2.26 def sendmail(self, recipients, data, sender=None, outgoing_bcc=None, lmtp_socket=None):
2.27
2.28 """
2.29 Send a mail to the given 'recipients' consisting of the given 'data',
2.30 using the given 'sender' identity if indicated, indicating an
2.31 - 'outgoing_bcc' identity if indicated, delivering to a local mail system
2.32 - using LMTP if 'lmtp_socket' is provided.
2.33 + 'outgoing_bcc' identity if indicated.
2.34
2.35 The 'outgoing_bcc' argument is required when sending on behalf of a user
2.36 from the calendar@domain address, since this will not be detected as a
2.37 valid participant and handled using the outgoing transport.
2.38 """
2.39
2.40 - if lmtp_socket:
2.41 - smtp = LMTP(lmtp_socket)
2.42 + if self.lmtp_socket:
2.43 + smtp = LMTP(self.lmtp_socket)
2.44 else:
2.45 smtp = SMTP("localhost")
2.46