1.1 --- a/imiptools/__init__.py Tue Oct 13 17:09:11 2015 +0200
1.2 +++ b/imiptools/__init__.py Tue Oct 13 17:10:40 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 @@ -85,16 +86,18 @@
1.24 # Typically, the details of recipients are of interest in handling
1.25 # messages.
1.26
1.27 - if not outgoing_only:
1.28 + if not self.outgoing_only:
1.29 original_recipients = original_recipients or get_addresses(get_all_values(msg, "To") or [])
1.30 for recipient in original_recipients:
1.31 - Recipient(get_uri(recipient), messenger, store, publisher, preferences_dir, self.handlers, self.debug).process(msg, senders, outgoing_only)
1.32 + Recipient(get_uri(recipient), messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
1.33 + ).process(msg, senders)
1.34
1.35 # However, outgoing messages do not usually presume anything about the
1.36 - # eventual recipients.
1.37 + # eventual recipients and focus on the sender instead.
1.38
1.39 else:
1.40 - Recipient(None, messenger, store, publisher, preferences_dir, self.handlers, self.debug).process(msg, senders, outgoing_only)
1.41 + Recipient(None, messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
1.42 + ).process(msg, senders)
1.43
1.44 def process_args(self, args, stream):
1.45
1.46 @@ -113,20 +116,14 @@
1.47 publishing_dir = []
1.48 preferences_dir = []
1.49 local_smtp = False
1.50 - outgoing_only = False
1.51
1.52 l = []
1.53
1.54 for arg in args:
1.55
1.56 - # Detect outgoing processing mode.
1.57 -
1.58 - if arg == "-O":
1.59 - outgoing_only = True
1.60 -
1.61 # Switch to collecting recipients.
1.62
1.63 - elif arg == "-o":
1.64 + if arg == "-o":
1.65 l = original_recipients
1.66
1.67 # Switch to collecting senders.
1.68 @@ -170,7 +167,7 @@
1.69 self.store_dir = store_dir and store_dir[0] or None
1.70 self.publishing_dir = publishing_dir and publishing_dir[0] or None
1.71 self.preferences_dir = preferences_dir and preferences_dir[0] or None
1.72 - self.process(stream, original_recipients, outgoing_only)
1.73 + self.process(stream, original_recipients)
1.74
1.75 def __call__(self):
1.76
1.77 @@ -207,22 +204,24 @@
1.78
1.79 "A processor acting as a client on behalf of a recipient."
1.80
1.81 - def __init__(self, user, messenger, store, publisher, preferences_dir, handlers, debug):
1.82 + def __init__(self, user, messenger, store, publisher, preferences_dir, handlers, outgoing_only, debug):
1.83
1.84 """
1.85 Initialise the recipient with the given 'user' identity, 'messenger',
1.86 - 'store', 'publisher', 'preferences_dir', 'handlers' and 'debug' status.
1.87 + 'store', 'publisher', 'preferences_dir', 'handlers', 'outgoing_only' and
1.88 + 'debug' status.
1.89 """
1.90
1.91 Client.__init__(self, user, messenger, store, publisher, preferences_dir)
1.92 self.handlers = handlers
1.93 + self.outgoing_only = outgoing_only
1.94 self.debug = debug
1.95
1.96 - def process(self, msg, senders, outgoing_only):
1.97 + def process(self, msg, senders):
1.98
1.99 """
1.100 Process the given 'msg' for a single recipient, having the given
1.101 - 'senders', and with the given 'outgoing_only' status.
1.102 + 'senders'.
1.103
1.104 Processing individually means that contributions to resulting messages
1.105 may be constructed according to individual preferences.
1.106 @@ -237,11 +236,7 @@
1.107 # Check for participating recipients. Non-participating recipients will
1.108 # have their messages left as being unhandled.
1.109
1.110 - # Note that no user is set for outgoing messages, and so a check for
1.111 - # their participation must be done in an outgoing handler once they are
1.112 - # identified.
1.113 -
1.114 - if outgoing_only or self.is_participating():
1.115 + if self.outgoing_only or self.is_participating():
1.116
1.117 # Check for returned messages.
1.118
1.119 @@ -259,7 +254,7 @@
1.120 # When processing outgoing messages, no replies or deliveries are
1.121 # performed.
1.122
1.123 - if outgoing_only:
1.124 + if self.outgoing_only:
1.125 return
1.126
1.127 # Get responses from the handlers.