1.1 --- a/imiptools/content.py Thu Jan 22 17:50:54 2015 +0100
1.2 +++ b/imiptools/content.py Thu Jan 22 18:41:06 2015 +0100
1.3 @@ -107,6 +107,28 @@
1.4 def uri_items(items):
1.5 return [(get_uri(value), attr) for value, attr in items]
1.6
1.7 +def is_new_object(old_sequence, new_sequence, old_dtstamp, new_dtstamp, partstat_set):
1.8 +
1.9 + """
1.10 + Return for the given 'old_sequence' and 'new_sequence', 'old_dtstamp' and
1.11 + 'new_dtstamp', and the 'partstat_set' indication, whether the object
1.12 + providing the new information is really newer than the object providing the
1.13 + old information.
1.14 + """
1.15 +
1.16 + have_sequence = old_sequence is not None and new_sequence is not None
1.17 + is_same_sequence = have_sequence and int(new_sequence) == int(old_sequence)
1.18 +
1.19 + have_dtstamp = old_dtstamp and new_dtstamp
1.20 + is_old_dtstamp = have_dtstamp and new_dtstamp < old_dtstamp or old_dtstamp and not new_dtstamp
1.21 +
1.22 + is_old_sequence = have_sequence and (
1.23 + int(new_sequence) < int(old_sequence) or
1.24 + is_same_sequence and is_old_dtstamp
1.25 + )
1.26 +
1.27 + return is_same_sequence and partstat_set or not is_old_sequence
1.28 +
1.29 # NOTE: Need to expose the 100 day window for recurring events in the
1.30 # NOTE: configuration.
1.31
1.32 @@ -426,19 +448,22 @@
1.33 sequence = get_value(obj, "SEQUENCE")
1.34 dtstamp = get_value(obj, "DTSTAMP")
1.35
1.36 + # NOTE: Some clients like Claws Mail erase time information from DTSTAMP
1.37 + # NOTE: and make it invalid. Thus, attendance information may also be
1.38 + # NOTE: checked.
1.39 +
1.40 + _attendee, old_attr = get_item(obj, "ATTENDEE")
1.41 + _attendee, new_attr = self.get_item("ATTENDEE")
1.42 + old_partstat = old_attr.get("PARTSTAT")
1.43 + new_partstat = new_attr.get("PARTSTAT")
1.44 +
1.45 + partstat_set = old_partstat == "NEEDS-ACTION" and new_partstat and \
1.46 + new_partstat != old_partstat
1.47 +
1.48 # If the request refers to an older version of the object, ignore
1.49 # it.
1.50
1.51 - old_dtstamp = self.dtstamp < dtstamp
1.52 -
1.53 - have_sequence = sequence is not None and self.sequence is not None
1.54 -
1.55 - if have_sequence and (
1.56 - int(self.sequence) < int(sequence) or
1.57 - int(self.sequence) == int(sequence) and old_dtstamp
1.58 - ) or not have_sequence and old_dtstamp:
1.59 -
1.60 - return False
1.61 + return is_new_object(sequence, self.sequence, dtstamp, self.dtstamp, partstat_set)
1.62
1.63 return True
1.64