# HG changeset patch # User Paul Boddie # Date 1422833945 -3600 # Node ID d175f3581bd780d430eba4b805a5d7b80e5c7b64 # Parent a24c32fa9ae1c6a3d66096a3e28074d78e5b0af2 Moved handler instantiation into the top level processing, making a new handler instance for each recipient, rather than making one for each part (as processed for each recipient). diff -r a24c32fa9ae1 -r d175f3581bd7 imip_manager.py --- a/imip_manager.py Mon Feb 02 00:12:53 2015 +0100 +++ b/imip_manager.py Mon Feb 02 00:39:05 2015 +0100 @@ -115,7 +115,8 @@ """ def __init__(self, obj, user, messenger): - Handler.__init__(self, obj, messenger=messenger) + Handler.__init__(self, messenger=messenger) + self.set_object(obj) self.user = user self.organiser = self.obj.get_value("ORGANIZER") diff -r a24c32fa9ae1 -r d175f3581bd7 imiptools/__init__.py --- a/imiptools/__init__.py Mon Feb 02 00:12:53 2015 +0100 +++ b/imiptools/__init__.py Mon Feb 02 00:39:05 2015 +0100 @@ -83,11 +83,13 @@ all_responses = [] handled = False + handlers = [(name, cls(senders, recipient, self.messenger)) for name, cls in handlers] + for part in msg.walk(): if part.get_content_type() in itip_content_types and \ part.get_param("method"): - all_responses += handle_itip_part(part, senders, recipient, self.handlers, self.messenger) + all_responses += handle_itip_part(part, handlers) handled = True # When processing outgoing messages, no replies or deliveries are diff -r a24c32fa9ae1 -r d175f3581bd7 imiptools/content.py --- a/imiptools/content.py Mon Feb 02 00:12:53 2015 +0100 +++ b/imiptools/content.py Mon Feb 02 00:39:05 2015 +0100 @@ -133,13 +133,13 @@ # Handler mechanism objects. -def handle_itip_part(part, senders, recipient, handlers, messenger): +def handle_itip_part(part, handlers): """ - Handle the given iTIP 'part' from the given 'senders' for the given - 'recipient' using the given 'handlers' and information provided by the - given 'messenger'. Return a list of responses, each response being a tuple - of the form (outgoing-recipients, message-part). + Handle the given iTIP 'part' using the given 'handlers'. + + Return a list of responses, each response being a tuple of the form + (outgoing-recipients, message-part). """ method = part.get_param("method") @@ -163,12 +163,12 @@ all_results = [] - for name, cls in handlers: + for name, handler in handlers: for fragment in get_fragments(itip, name): # Dispatch to a handler and obtain any response. - handler = cls(Object(fragment), senders, recipient, messenger) + handler.set_object(Object(fragment)) results = methods[method](handler)() # Aggregate responses for a single message. @@ -195,14 +195,14 @@ "General handler support." - def __init__(self, obj, senders=None, recipient=None, messenger=None): + def __init__(self, senders=None, recipient=None, messenger=None): """ Initialise the handler with the calendar 'obj' and the 'senders' and 'recipient' of the object (if specifically indicated). """ - self.obj = obj + self.obj = None self.senders = senders and set(map(get_address, senders)) self.recipient = recipient and get_address(recipient) self.messenger = messenger @@ -218,6 +218,9 @@ except OSError: self.publisher = None + def set_object(self, obj): + self.obj = obj + def wrap(self, text, link=True): "Wrap any valid message for passing to the recipient."