4.1 --- a/imiptools/__init__.py Mon Oct 12 23:53:38 2015 +0200
4.2 +++ b/imiptools/__init__.py Tue Oct 13 16:27:19 2015 +0200
4.3 @@ -51,8 +51,9 @@
4.4
4.5 "The processing framework."
4.6
4.7 - def __init__(self, handlers):
4.8 + def __init__(self, handlers, outgoing_only=False):
4.9 self.handlers = handlers
4.10 + self.outgoing_only = outgoing_only
4.11 self.messenger = None
4.12 self.lmtp_socket = None
4.13 self.store_dir = None
4.14 @@ -66,7 +67,7 @@
4.15 def get_publisher(self):
4.16 return self.publishing_dir and imip_store.FilePublisher(self.publishing_dir) or None
4.17
4.18 - def process(self, f, original_recipients, outgoing_only):
4.19 + def process(self, f, original_recipients):
4.20
4.21 """
4.22 Process content from the stream 'f' accompanied by the given
4.23 @@ -75,6 +76,7 @@
4.24
4.25 msg = message_from_file(f)
4.26 senders = get_addresses(get_all_values(msg, "Reply-To") or get_all_values(msg, "From") or [])
4.27 + sender = (get_all_values(msg, "From") or [None])[0]
4.28
4.29 messenger = self.messenger
4.30 store = self.get_store()
4.31 @@ -85,16 +87,18 @@
4.32 # Typically, the details of recipients are of interest in handling
4.33 # messages.
4.34
4.35 - if not outgoing_only:
4.36 + if not self.outgoing_only:
4.37 original_recipients = original_recipients or get_addresses(get_all_values(msg, "To") or [])
4.38 for recipient in original_recipients:
4.39 - Recipient(get_uri(recipient), messenger, store, publisher, preferences_dir, self.handlers, self.debug).process(msg, senders, outgoing_only)
4.40 + Recipient(get_uri(recipient), messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
4.41 + ).process(msg, senders)
4.42
4.43 # However, outgoing messages do not usually presume anything about the
4.44 - # eventual recipients.
4.45 + # eventual recipients and focus on the sender instead.
4.46
4.47 else:
4.48 - Recipient(None, messenger, store, publisher, preferences_dir, self.handlers, self.debug).process(msg, senders, outgoing_only)
4.49 + Recipient(get_uri(sender), messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
4.50 + ).process(msg, senders)
4.51
4.52 def process_args(self, args, stream):
4.53
4.54 @@ -113,20 +117,14 @@
4.55 publishing_dir = []
4.56 preferences_dir = []
4.57 local_smtp = False
4.58 - outgoing_only = False
4.59
4.60 l = []
4.61
4.62 for arg in args:
4.63
4.64 - # Detect outgoing processing mode.
4.65 -
4.66 - if arg == "-O":
4.67 - outgoing_only = True
4.68 -
4.69 # Switch to collecting recipients.
4.70
4.71 - elif arg == "-o":
4.72 + if arg == "-o":
4.73 l = original_recipients
4.74
4.75 # Switch to collecting senders.
4.76 @@ -170,7 +168,7 @@
4.77 self.store_dir = store_dir and store_dir[0] or None
4.78 self.publishing_dir = publishing_dir and publishing_dir[0] or None
4.79 self.preferences_dir = preferences_dir and preferences_dir[0] or None
4.80 - self.process(stream, original_recipients, outgoing_only)
4.81 + self.process(stream, original_recipients)
4.82
4.83 def __call__(self):
4.84
4.85 @@ -207,22 +205,24 @@
4.86
4.87 "A processor acting as a client on behalf of a recipient."
4.88
4.89 - def __init__(self, user, messenger, store, publisher, preferences_dir, handlers, debug):
4.90 + def __init__(self, user, messenger, store, publisher, preferences_dir, handlers, outgoing_only, debug):
4.91
4.92 """
4.93 Initialise the recipient with the given 'user' identity, 'messenger',
4.94 - 'store', 'publisher', 'preferences_dir', 'handlers' and 'debug' status.
4.95 + 'store', 'publisher', 'preferences_dir', 'handlers', 'outgoing_only' and
4.96 + 'debug' status.
4.97 """
4.98
4.99 Client.__init__(self, user, messenger, store, publisher, preferences_dir)
4.100 self.handlers = handlers
4.101 + self.outgoing_only = outgoing_only
4.102 self.debug = debug
4.103
4.104 - def process(self, msg, senders, outgoing_only):
4.105 + def process(self, msg, senders):
4.106
4.107 """
4.108 Process the given 'msg' for a single recipient, having the given
4.109 - 'senders', and with the given 'outgoing_only' status.
4.110 + 'senders'.
4.111
4.112 Processing individually means that contributions to resulting messages
4.113 may be constructed according to individual preferences.
4.114 @@ -237,11 +237,7 @@
4.115 # Check for participating recipients. Non-participating recipients will
4.116 # have their messages left as being unhandled.
4.117
4.118 - # Note that no user is set for outgoing messages, and so a check for
4.119 - # their participation must be done in an outgoing handler once they are
4.120 - # identified.
4.121 -
4.122 - if outgoing_only or self.is_participating():
4.123 + if self.is_participating():
4.124
4.125 # Check for returned messages.
4.126
4.127 @@ -259,7 +255,7 @@
4.128 # When processing outgoing messages, no replies or deliveries are
4.129 # performed.
4.130
4.131 - if outgoing_only:
4.132 + if self.outgoing_only:
4.133 return
4.134
4.135 # Get responses from the handlers.