# HG changeset patch # User Paul Boddie # Date 1508188283 -7200 # Node ID 66c8a5c98b25da1a171a7b517625d0fa65582179 # Parent f276b162de500e428b2ad6863e9a50436a4b0a77 Tidied up slightly, making use of existing functions where appropriate. diff -r f276b162de50 -r 66c8a5c98b25 imiptools/client.py --- a/imiptools/client.py Mon Oct 16 22:09:15 2017 +0200 +++ b/imiptools/client.py Mon Oct 16 23:11:23 2017 +0200 @@ -21,7 +21,8 @@ from datetime import datetime, timedelta from imiptools.config import settings -from imiptools.data import Object, check_delegation, get_address, get_uri, \ +from imiptools.data import Object, check_delegation, get_address, \ + get_sender_identities, get_uri, \ get_window_end, is_new_object, make_freebusy, \ make_uid, to_part, uri_dict, uri_item, uri_items, \ uri_parts, uri_values @@ -469,12 +470,21 @@ # Search for the sender of the message or the calendar system address. - senders = self.senders or self.messenger and [self.messenger.sender] or [] + senders = set(uri_values(self.senders or self.messenger and [self.messenger.sender] or [])) + + if senders: + + # Obtain a mapping from sender URI to attendee URI, where the sender + # is taken from the SENT-BY attribute if present, or from the + # attendee value otherwise. - for attendee, attendee_attr in uri_items(self.obj.get_items("ATTENDEE")): - if get_address(attendee) in senders or \ - get_address(attendee_attr.get("SENT-BY")) in senders: - return get_uri(attendee) + sent_by = get_sender_identities(uri_dict(self.obj.get_value_map("ATTENDEE"))) + + # Obtain the attendee for the first sender matching the SENT-BY or + # attendee value. + + for sender in senders.intersection(sent_by.keys()): + return sent_by[sender][0] return None diff -r f276b162de50 -r 66c8a5c98b25 imiptools/data.py --- a/imiptools/data.py Mon Oct 16 22:09:15 2017 +0200 +++ b/imiptools/data.py Mon Oct 16 23:11:23 2017 +0200 @@ -1168,7 +1168,8 @@ """ Return a mapping from actual senders to the identities for which they have provided data, extracting this information from the given - 'mapping'. + 'mapping'. The SENT-BY attribute provides sender information in preference + to the property values given as the mapping keys. """ senders = {} diff -r f276b162de50 -r 66c8a5c98b25 imiptools/handlers/__init__.py --- a/imiptools/handlers/__init__.py Mon Oct 16 22:09:15 2017 +0200 +++ b/imiptools/handlers/__init__.py Mon Oct 16 23:11:23 2017 +0200 @@ -145,7 +145,13 @@ # Return the true identities. - return reduce(lambda a, b: a + b, [identities[get_uri(address)] for address in valid], []) + attendees = [] + for address in valid: + attendees += identities[get_uri(address)] + return attendees + + # Rely on the mapping keys being accessible as a sequence. + else: return mapping @@ -159,6 +165,9 @@ if self.recipient: addresses = set(map(get_address, mapping)) return map(get_uri, addresses.intersection([self.recipient])) + + # Rely on the mapping keys being accessible as a sequence. + else: return mapping