1.1 --- a/imip_store.py Tue Nov 25 21:59:42 2014 +0100
1.2 +++ b/imip_store.py Tue Nov 25 22:08:44 2014 +0100
1.3 @@ -131,6 +131,24 @@
1.4
1.5 return True
1.6
1.7 + def set_freebusy_for_other(self, user, freebusy, other):
1.8 +
1.9 + "For the given 'user', set 'freebusy' details for the 'other' user."
1.10 +
1.11 + filename = self.get_object_in_store(user, "freebusy-other", other)
1.12 + if not filename:
1.13 + return False
1.14 +
1.15 + f = open(filename, "w")
1.16 + try:
1.17 + for item in freebusy:
1.18 + f.write("\t".join(item) + "\n")
1.19 + finally:
1.20 + f.close()
1.21 + fix_permissions(filename)
1.22 +
1.23 + return True
1.24 +
1.25 def get_requests(self, user):
1.26
1.27 "Get requests for the given 'user'."
2.1 --- a/imiptools/handlers/person.py Tue Nov 25 21:59:42 2014 +0100
2.2 +++ b/imiptools/handlers/person.py Tue Nov 25 22:08:44 2014 +0100
2.3 @@ -6,7 +6,7 @@
2.4
2.5 from email.mime.text import MIMEText
2.6 from imiptools.config import MANAGER_PATH, MANAGER_URL
2.7 -from imiptools.content import Handler, to_part
2.8 +from imiptools.content import Handler, get_uri, to_part
2.9 from imiptools.handlers.common import CommonFreebusy
2.10 from socket import gethostname
2.11 from vCalendar import to_node
2.12 @@ -32,9 +32,12 @@
2.13 if not self.validate_identities(from_organiser and [organiser_item] or attendees.items()):
2.14 return False
2.15
2.16 - # Process each attendee separately.
2.17 + # Handle notifications and invitations.
2.18
2.19 if from_organiser:
2.20 +
2.21 + # Process each attendee separately.
2.22 +
2.23 for attendee, attendee_attr in attendees.items():
2.24
2.25 if not self.have_new_object(attendee, objtype):
2.26 @@ -73,6 +76,25 @@
2.27
2.28 return True
2.29
2.30 + def _record_freebusy(self, from_organiser=True):
2.31 +
2.32 + "Record free/busy information for the received information."
2.33 +
2.34 + freebusy = []
2.35 + for value in self.get_values("FREEBUSY"):
2.36 + if not isinstance(value, list):
2.37 + value = [value]
2.38 + for v in value:
2.39 + try:
2.40 + start, end = v.split("/", 1)
2.41 + freebusy.append((start, end))
2.42 + except ValueError:
2.43 + pass
2.44 +
2.45 + for sender, sender_attr in self.get_items(from_organiser and "ORGANIZER" or "ATTENDEE"):
2.46 + for recipient in self.recipients:
2.47 + self.store.set_freebusy_for_other(get_uri(recipient), freebusy, sender)
2.48 +
2.49 def reply(self):
2.50
2.51 "Wrap any valid message and pass it on to the recipient."
2.52 @@ -157,7 +179,9 @@
2.53
2.54 def publish(self):
2.55
2.56 - # NOTE: Register free/busy information.
2.57 + "Register free/busy information."
2.58 +
2.59 + self._record_freebusy(from_organiser=True)
2.60
2.61 # The message is now wrapped and passed on to the recipient.
2.62
2.63 @@ -167,7 +191,7 @@
2.64
2.65 "Record replies and notify the recipient."
2.66
2.67 - self._record_and_deliver("VFREEBUSY", from_organiser=False, queue=False)
2.68 + self._record_freebusy(from_organiser=False)
2.69 return PersonHandler.reply(self)
2.70
2.71 def request(self):