1.1 --- a/imipweb/resource.py Sat Oct 17 19:08:30 2015 +0200
1.2 +++ b/imipweb/resource.py Sat Oct 17 19:15:22 2015 +0200
1.3 @@ -219,7 +219,7 @@
1.4
1.5 # Communication methods.
1.6
1.7 - def send_message(self, parts, sender, from_organiser):
1.8 + def send_message(self, parts, sender, from_organiser, bcc_sender):
1.9
1.10 """
1.11 Send the given 'parts' to the appropriate recipients, also sending a
1.12 @@ -254,19 +254,23 @@
1.13 if part:
1.14 parts.append(part)
1.15
1.16 - self._send_message(sender, recipients, parts)
1.17 + self._send_message(sender, recipients, parts, bcc_sender)
1.18
1.19 - def _send_message(self, sender, recipients, parts):
1.20 + def _send_message(self, sender, recipients, parts, bcc_sender):
1.21
1.22 """
1.23 Send a message, explicitly specifying the 'sender' as an outgoing BCC
1.24 recipient since the generic calendar user will be the actual sender.
1.25 """
1.26
1.27 - message = self.messenger.make_outgoing_message(parts, recipients, outgoing_bcc=sender)
1.28 - self.messenger.sendmail(recipients, message.as_string(), outgoing_bcc=sender)
1.29 + if bcc_sender:
1.30 + message = self.messenger.make_outgoing_message(parts, recipients)
1.31 + self.messenger.sendmail(recipients, message.as_string())
1.32 + else:
1.33 + message = self.messenger.make_outgoing_message(parts, recipients, outgoing_bcc=sender)
1.34 + self.messenger.sendmail(recipients, message.as_string(), outgoing_bcc=sender)
1.35
1.36 - def _send_message_to_self(self, parts):
1.37 + def send_message_to_self(self, parts):
1.38
1.39 "Send a message composed of the given 'parts' to the given user."
1.40
1.41 @@ -290,7 +294,7 @@
1.42 self.update_senders(obj=obj)
1.43 obj.update_dtstamp()
1.44 obj.update_sequence(False)
1.45 - self._send_message(get_address(self.user), [get_address(attendee)], parts=[obj.to_part(method)])
1.46 + self._send_message(get_address(self.user), [get_address(attendee)], [obj.to_part(method)], True)
1.47 return True
1.48
1.49 def process_received_request(self, changed=False):
1.50 @@ -316,7 +320,7 @@
1.51
1.52 self.update_dtstamp()
1.53 self.update_sequence(False)
1.54 - self.send_message([self.obj.to_part(changed and "COUNTER" or "REPLY")], get_address(self.user), from_organiser=False)
1.55 + self.send_message([self.obj.to_part(changed and "COUNTER" or "REPLY")], get_address(self.user), False, True)
1.56 return True
1.57
1.58 def process_created_request(self, method, to_cancel=None, to_unschedule=None):
1.59 @@ -341,42 +345,43 @@
1.60 self.update_dtstamp()
1.61 self.update_sequence(True)
1.62
1.63 - parts = [self.obj.to_part(method)]
1.64 + if method == "REQUEST":
1.65 + methods, parts = self.get_message_parts(self.obj, "REQUEST")
1.66
1.67 - # Add message parts with cancelled occurrence information.
1.68 - # NOTE: This could probably be merged with the updated event message.
1.69 + # Add message parts with cancelled occurrence information.
1.70
1.71 - if to_unschedule:
1.72 - obj = self.obj.copy()
1.73 - obj.remove_all(["RRULE", "RDATE", "DTSTART", "DTEND", "DURATION"])
1.74 + unscheduled_parts = self.get_unscheduled_parts(to_unschedule)
1.75
1.76 - for p in to_unschedule:
1.77 - if not p.origin:
1.78 - continue
1.79 - obj["RECURRENCE-ID"] = [(format_datetime(p.get_start()), p.get_start_attr())]
1.80 - parts.append(obj.to_part("CANCEL"))
1.81 + # Send the updated event, along with a cancellation for each of the
1.82 + # unscheduled occurrences.
1.83 +
1.84 + self.send_message(parts + unscheduled_parts, get_address(organiser), True, False)
1.85
1.86 - # Send the updated event, along with a cancellation for each of the
1.87 - # unscheduled occurrences.
1.88 + # Since the organiser can update the SEQUENCE but this can leave any
1.89 + # mail/calendar client lagging, issue a PUBLISH message to the
1.90 + # user's address.
1.91
1.92 - self.send_message(parts, get_address(organiser), from_organiser=True)
1.93 + methods, parts = self.get_message_parts(self.obj, "PUBLISH")
1.94 + self.send_message_to_self(parts + unscheduled_parts)
1.95
1.96 # When cancelling, replace the attendees with those for whom the event
1.97 # is now cancelled.
1.98
1.99 - if to_cancel:
1.100 - obj = self.obj.copy()
1.101 - obj["ATTENDEE"] = to_cancel
1.102 + if method == "CANCEL" or to_cancel:
1.103 + if to_cancel:
1.104 + obj = self.obj.copy()
1.105 + obj["ATTENDEE"] = to_cancel
1.106 + else:
1.107 + obj = self.obj
1.108
1.109 # Send a cancellation to all uninvited attendees.
1.110
1.111 - self.send_message([self.obj.to_part("CANCEL")], get_address(organiser), from_organiser=True)
1.112 + parts = [obj.to_part("CANCEL")]
1.113 + self.send_message(parts, get_address(organiser), True, False)
1.114
1.115 - # Since the organiser can update the SEQUENCE but this can leave any
1.116 - # mail/calendar client lagging, issue a PUBLISH message to the user's
1.117 - # address.
1.118 + # Issue a CANCEL message to the user's address.
1.119
1.120 - self._send_message_to_self([self.obj.to_part("PUBLISH")])
1.121 + self.send_message_to_self(parts)
1.122
1.123 return True
1.124