# HG changeset patch # User Paul Boddie # Date 1416949724 -3600 # Node ID d6346960ab826e5c5c845ab36042e7aca649d0d7 # Parent 31ffa69ab1a3903956d55d775d7dad5766a5ad1a Introduced recording of other free/busy information for local scheduling. diff -r 31ffa69ab1a3 -r d6346960ab82 imip_store.py --- a/imip_store.py Tue Nov 25 21:59:42 2014 +0100 +++ b/imip_store.py Tue Nov 25 22:08:44 2014 +0100 @@ -131,6 +131,24 @@ return True + def set_freebusy_for_other(self, user, freebusy, other): + + "For the given 'user', set 'freebusy' details for the 'other' user." + + filename = self.get_object_in_store(user, "freebusy-other", other) + if not filename: + return False + + f = open(filename, "w") + try: + for item in freebusy: + f.write("\t".join(item) + "\n") + finally: + f.close() + fix_permissions(filename) + + return True + def get_requests(self, user): "Get requests for the given 'user'." diff -r 31ffa69ab1a3 -r d6346960ab82 imiptools/handlers/person.py --- a/imiptools/handlers/person.py Tue Nov 25 21:59:42 2014 +0100 +++ b/imiptools/handlers/person.py Tue Nov 25 22:08:44 2014 +0100 @@ -6,7 +6,7 @@ from email.mime.text import MIMEText from imiptools.config import MANAGER_PATH, MANAGER_URL -from imiptools.content import Handler, to_part +from imiptools.content import Handler, get_uri, to_part from imiptools.handlers.common import CommonFreebusy from socket import gethostname from vCalendar import to_node @@ -32,9 +32,12 @@ if not self.validate_identities(from_organiser and [organiser_item] or attendees.items()): return False - # Process each attendee separately. + # Handle notifications and invitations. if from_organiser: + + # Process each attendee separately. + for attendee, attendee_attr in attendees.items(): if not self.have_new_object(attendee, objtype): @@ -73,6 +76,25 @@ return True + def _record_freebusy(self, from_organiser=True): + + "Record free/busy information for the received information." + + freebusy = [] + for value in self.get_values("FREEBUSY"): + if not isinstance(value, list): + value = [value] + for v in value: + try: + start, end = v.split("/", 1) + freebusy.append((start, end)) + except ValueError: + pass + + for sender, sender_attr in self.get_items(from_organiser and "ORGANIZER" or "ATTENDEE"): + for recipient in self.recipients: + self.store.set_freebusy_for_other(get_uri(recipient), freebusy, sender) + def reply(self): "Wrap any valid message and pass it on to the recipient." @@ -157,7 +179,9 @@ def publish(self): - # NOTE: Register free/busy information. + "Register free/busy information." + + self._record_freebusy(from_organiser=True) # The message is now wrapped and passed on to the recipient. @@ -167,7 +191,7 @@ "Record replies and notify the recipient." - self._record_and_deliver("VFREEBUSY", from_organiser=False, queue=False) + self._record_freebusy(from_organiser=False) return PersonHandler.reply(self) def request(self):