# HG changeset patch # User Paul Boddie # Date 1509490051 -3600 # Node ID 14b719dc5cbf11f92ad633a1dced29743891896e # Parent b4136058710415045a6257c8e5abca186646f760 Added mechanisms for handling calendar object data not encoded as message parts. diff -r b41360587104 -r 14b719dc5cbf imiptools/content.py --- a/imiptools/content.py Tue Oct 31 23:46:20 2017 +0100 +++ b/imiptools/content.py Tue Oct 31 23:47:31 2017 +0100 @@ -129,32 +129,56 @@ """ itip = parse_itip_part(part) + if itip: + handle_calendar_data(itip, handlers) + + return not not itip + +def handle_calendar_data(itip, handlers): + + """ + Handle the calendar data provided by 'itip' using the given 'handlers' + dictionary. Responses are set in each handler used to handle a message. + Return all handled objects. + """ + method = itip and get_value(itip, "METHOD") + handled = [] for obj in get_objects_from_itip(itip, handlers): + handle_calendar_object(obj, handlers, method) + handled.append(obj) - # Get a handler for the given object type. + return handled + +def handle_calendar_object(obj, handlers, method): - handler = handlers.get(obj.objtype) - if not handler: - continue + """ + Handle the calendar data provided by 'obj' using the given 'handlers' + dictionary and 'method' information. Responses are set in each handler used + to handle a message. + """ - # Dispatch to a handler and obtain any response. - - handler.set_object(obj) - handler.set_identity(method) + # Get a handler for the given object type. - if handler.is_usable(method): + handler = handlers.get(obj.objtype) + if not handler: + return - # Perform the method in a critical section. + # Dispatch to a handler and obtain any response. + + handler.set_object(obj) + handler.set_identity(method) - handler.acquire_lock() - try: - methods[method](handler)() - finally: - handler.release_lock() + if handler.is_usable(method): + + # Perform the method in a critical section. - return not not itip + handler.acquire_lock() + try: + methods[method](handler)() + finally: + handler.release_lock() # Handler registry.