1.1 --- a/imiptools/__init__.py Mon Oct 12 23:53:38 2015 +0200
1.2 +++ b/imiptools/__init__.py Tue Oct 13 16:27:19 2015 +0200
1.3 @@ -51,8 +51,9 @@
1.4
1.5 "The processing framework."
1.6
1.7 - def __init__(self, handlers):
1.8 + def __init__(self, handlers, outgoing_only=False):
1.9 self.handlers = handlers
1.10 + self.outgoing_only = outgoing_only
1.11 self.messenger = None
1.12 self.lmtp_socket = None
1.13 self.store_dir = None
1.14 @@ -66,7 +67,7 @@
1.15 def get_publisher(self):
1.16 return self.publishing_dir and imip_store.FilePublisher(self.publishing_dir) or None
1.17
1.18 - def process(self, f, original_recipients, outgoing_only):
1.19 + def process(self, f, original_recipients):
1.20
1.21 """
1.22 Process content from the stream 'f' accompanied by the given
1.23 @@ -75,6 +76,7 @@
1.24
1.25 msg = message_from_file(f)
1.26 senders = get_addresses(get_all_values(msg, "Reply-To") or get_all_values(msg, "From") or [])
1.27 + sender = (get_all_values(msg, "From") or [None])[0]
1.28
1.29 messenger = self.messenger
1.30 store = self.get_store()
1.31 @@ -85,16 +87,18 @@
1.32 # Typically, the details of recipients are of interest in handling
1.33 # messages.
1.34
1.35 - if not outgoing_only:
1.36 + if not self.outgoing_only:
1.37 original_recipients = original_recipients or get_addresses(get_all_values(msg, "To") or [])
1.38 for recipient in original_recipients:
1.39 - Recipient(get_uri(recipient), messenger, store, publisher, preferences_dir, self.handlers, self.debug).process(msg, senders, outgoing_only)
1.40 + Recipient(get_uri(recipient), messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
1.41 + ).process(msg, senders)
1.42
1.43 # However, outgoing messages do not usually presume anything about the
1.44 - # eventual recipients.
1.45 + # eventual recipients and focus on the sender instead.
1.46
1.47 else:
1.48 - Recipient(None, messenger, store, publisher, preferences_dir, self.handlers, self.debug).process(msg, senders, outgoing_only)
1.49 + Recipient(get_uri(sender), messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
1.50 + ).process(msg, senders)
1.51
1.52 def process_args(self, args, stream):
1.53
1.54 @@ -113,20 +117,14 @@
1.55 publishing_dir = []
1.56 preferences_dir = []
1.57 local_smtp = False
1.58 - outgoing_only = False
1.59
1.60 l = []
1.61
1.62 for arg in args:
1.63
1.64 - # Detect outgoing processing mode.
1.65 -
1.66 - if arg == "-O":
1.67 - outgoing_only = True
1.68 -
1.69 # Switch to collecting recipients.
1.70
1.71 - elif arg == "-o":
1.72 + if arg == "-o":
1.73 l = original_recipients
1.74
1.75 # Switch to collecting senders.
1.76 @@ -170,7 +168,7 @@
1.77 self.store_dir = store_dir and store_dir[0] or None
1.78 self.publishing_dir = publishing_dir and publishing_dir[0] or None
1.79 self.preferences_dir = preferences_dir and preferences_dir[0] or None
1.80 - self.process(stream, original_recipients, outgoing_only)
1.81 + self.process(stream, original_recipients)
1.82
1.83 def __call__(self):
1.84
1.85 @@ -207,22 +205,24 @@
1.86
1.87 "A processor acting as a client on behalf of a recipient."
1.88
1.89 - def __init__(self, user, messenger, store, publisher, preferences_dir, handlers, debug):
1.90 + def __init__(self, user, messenger, store, publisher, preferences_dir, handlers, outgoing_only, debug):
1.91
1.92 """
1.93 Initialise the recipient with the given 'user' identity, 'messenger',
1.94 - 'store', 'publisher', 'preferences_dir', 'handlers' and 'debug' status.
1.95 + 'store', 'publisher', 'preferences_dir', 'handlers', 'outgoing_only' and
1.96 + 'debug' status.
1.97 """
1.98
1.99 Client.__init__(self, user, messenger, store, publisher, preferences_dir)
1.100 self.handlers = handlers
1.101 + self.outgoing_only = outgoing_only
1.102 self.debug = debug
1.103
1.104 - def process(self, msg, senders, outgoing_only):
1.105 + def process(self, msg, senders):
1.106
1.107 """
1.108 Process the given 'msg' for a single recipient, having the given
1.109 - 'senders', and with the given 'outgoing_only' status.
1.110 + 'senders'.
1.111
1.112 Processing individually means that contributions to resulting messages
1.113 may be constructed according to individual preferences.
1.114 @@ -237,11 +237,7 @@
1.115 # Check for participating recipients. Non-participating recipients will
1.116 # have their messages left as being unhandled.
1.117
1.118 - # Note that no user is set for outgoing messages, and so a check for
1.119 - # their participation must be done in an outgoing handler once they are
1.120 - # identified.
1.121 -
1.122 - if outgoing_only or self.is_participating():
1.123 + if self.is_participating():
1.124
1.125 # Check for returned messages.
1.126
1.127 @@ -259,7 +255,7 @@
1.128 # When processing outgoing messages, no replies or deliveries are
1.129 # performed.
1.130
1.131 - if outgoing_only:
1.132 + if self.outgoing_only:
1.133 return
1.134
1.135 # Get responses from the handlers.