1.1 --- a/imiptools/handlers/resource.py Thu May 12 23:05:48 2016 +0200
1.2 +++ b/imiptools/handlers/resource.py Thu May 12 23:15:18 2016 +0200
1.3 @@ -20,7 +20,7 @@
1.4 """
1.5
1.6 from email.mime.text import MIMEText
1.7 -from imiptools.data import get_address, to_part, uri_dict
1.8 +from imiptools.data import get_address, uri_dict
1.9 from imiptools.handlers import Handler
1.10 from imiptools.handlers.common import CommonFreebusy, CommonEvent
1.11 from imiptools.handlers.scheduling import apply_scheduling_functions, \
1.12 @@ -90,6 +90,7 @@
1.13 "Attempt to schedule the current object for the current user."
1.14
1.15 attendee_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[self.user]
1.16 + delegate = None
1.17
1.18 # Attempt to schedule the event.
1.19
1.20 @@ -123,6 +124,19 @@
1.21 if scheduled == "ACCEPTED":
1.22 self.confirm_scheduling()
1.23
1.24 + # For delegated proposals, prepare a request to the delegate in
1.25 + # addition to the usual response.
1.26 +
1.27 + elif scheduled == "DELEGATED":
1.28 + method = "REPLY"
1.29 + attendee_attr = self.update_participation("DELEGATED")
1.30 +
1.31 + # The recipient will have indicated the delegate whose details
1.32 + # will have been added to the object.
1.33 +
1.34 + delegated_to = attendee_attr["DELEGATED-TO"]
1.35 + delegate = delegated_to and delegated_to[0]
1.36 +
1.37 # For countered proposals, record the offer in the resource's
1.38 # free/busy collection.
1.39
1.40 @@ -141,6 +155,8 @@
1.41 finally:
1.42 self.finish_scheduling()
1.43
1.44 + # Determine the recipients of the outgoing messages.
1.45 +
1.46 recipients = map(get_address, self.obj.get_values("ORGANIZER"))
1.47
1.48 # Add any description of the scheduling decision.
1.49 @@ -151,9 +167,35 @@
1.50 # DTSTAMP in the response, and return the object for sending.
1.51
1.52 self.update_sender(attendee_attr)
1.53 - self.obj["ATTENDEE"] = [(self.user, attendee_attr)]
1.54 + attendees = [(self.user, attendee_attr)]
1.55 +
1.56 + # Add the delegate if delegating (RFC 5546 being inconsistent here since
1.57 + # it provides an example reply to the organiser without the delegate).
1.58 +
1.59 + if delegate:
1.60 + delegate_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[delegate]
1.61 + attendees.append((delegate, delegate_attr))
1.62 +
1.63 + # Reply to the delegator in addition to the organiser if replying to a
1.64 + # delegation request.
1.65 +
1.66 + delegator = self.is_delegation()
1.67 + if delegator:
1.68 + delegator_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[delegator]
1.69 + attendees.append((delegator, delegator_attr))
1.70 + recipients.append(get_address(delegator))
1.71 +
1.72 + # Prepare the response for the organiser plus any delegator.
1.73 +
1.74 + self.obj["ATTENDEE"] = attendees
1.75 self.update_dtstamp()
1.76 - self.add_result(method, recipients, to_part(method, [self.obj.to_node()]))
1.77 + self.add_result(method, recipients, self.object_to_part(method, self.obj))
1.78 +
1.79 + # If delegating, send a request to the delegate.
1.80 +
1.81 + if delegate:
1.82 + method = "REQUEST"
1.83 + self.add_result(method, [get_address(delegate)], self.object_to_part(method, self.obj))
1.84
1.85 def _cancel_for_attendee(self):
1.86