1.1 --- a/imiptools/client.py Mon Oct 16 22:09:15 2017 +0200
1.2 +++ b/imiptools/client.py Mon Oct 16 23:11:23 2017 +0200
1.3 @@ -21,7 +21,8 @@
1.4
1.5 from datetime import datetime, timedelta
1.6 from imiptools.config import settings
1.7 -from imiptools.data import Object, check_delegation, get_address, get_uri, \
1.8 +from imiptools.data import Object, check_delegation, get_address, \
1.9 + get_sender_identities, get_uri, \
1.10 get_window_end, is_new_object, make_freebusy, \
1.11 make_uid, to_part, uri_dict, uri_item, uri_items, \
1.12 uri_parts, uri_values
1.13 @@ -469,12 +470,21 @@
1.14
1.15 # Search for the sender of the message or the calendar system address.
1.16
1.17 - senders = self.senders or self.messenger and [self.messenger.sender] or []
1.18 + senders = set(uri_values(self.senders or self.messenger and [self.messenger.sender] or []))
1.19 +
1.20 + if senders:
1.21 +
1.22 + # Obtain a mapping from sender URI to attendee URI, where the sender
1.23 + # is taken from the SENT-BY attribute if present, or from the
1.24 + # attendee value otherwise.
1.25
1.26 - for attendee, attendee_attr in uri_items(self.obj.get_items("ATTENDEE")):
1.27 - if get_address(attendee) in senders or \
1.28 - get_address(attendee_attr.get("SENT-BY")) in senders:
1.29 - return get_uri(attendee)
1.30 + sent_by = get_sender_identities(uri_dict(self.obj.get_value_map("ATTENDEE")))
1.31 +
1.32 + # Obtain the attendee for the first sender matching the SENT-BY or
1.33 + # attendee value.
1.34 +
1.35 + for sender in senders.intersection(sent_by.keys()):
1.36 + return sent_by[sender][0]
1.37
1.38 return None
1.39
2.1 --- a/imiptools/data.py Mon Oct 16 22:09:15 2017 +0200
2.2 +++ b/imiptools/data.py Mon Oct 16 23:11:23 2017 +0200
2.3 @@ -1168,7 +1168,8 @@
2.4 """
2.5 Return a mapping from actual senders to the identities for which they
2.6 have provided data, extracting this information from the given
2.7 - 'mapping'.
2.8 + 'mapping'. The SENT-BY attribute provides sender information in preference
2.9 + to the property values given as the mapping keys.
2.10 """
2.11
2.12 senders = {}
3.1 --- a/imiptools/handlers/__init__.py Mon Oct 16 22:09:15 2017 +0200
3.2 +++ b/imiptools/handlers/__init__.py Mon Oct 16 23:11:23 2017 +0200
3.3 @@ -145,7 +145,13 @@
3.4
3.5 # Return the true identities.
3.6
3.7 - return reduce(lambda a, b: a + b, [identities[get_uri(address)] for address in valid], [])
3.8 + attendees = []
3.9 + for address in valid:
3.10 + attendees += identities[get_uri(address)]
3.11 + return attendees
3.12 +
3.13 + # Rely on the mapping keys being accessible as a sequence.
3.14 +
3.15 else:
3.16 return mapping
3.17
3.18 @@ -159,6 +165,9 @@
3.19 if self.recipient:
3.20 addresses = set(map(get_address, mapping))
3.21 return map(get_uri, addresses.intersection([self.recipient]))
3.22 +
3.23 + # Rely on the mapping keys being accessible as a sequence.
3.24 +
3.25 else:
3.26 return mapping
3.27