Fix handling of RSVP flags

This commit is contained in:
Thomas Bruederli 2014-11-06 17:09:49 +01:00
parent 7294ef8be0
commit c6f5a8233b
5 changed files with 55 additions and 16 deletions

View file

@ -1642,7 +1642,9 @@ class calendar extends rcube_plugin
foreach ((array)$event['attendees'] as $i => $attendee) { foreach ((array)$event['attendees'] as $i => $attendee) {
if ($attendee['role'] == 'ORGANIZER') { if ($attendee['role'] == 'ORGANIZER') {
$organizer = $attendee; $organizer = $attendee;
break; }
if ($attendee['status'] == 'DELEGATED' && $attendee['rsvp'] == false) {
$event['attendees'][$i]['noreply'] = true;
} }
} }
@ -1895,7 +1897,7 @@ class calendar extends rcube_plugin
// compose multipart message using PEAR:Mail_Mime // compose multipart message using PEAR:Mail_Mime
$method = $action == 'remove' ? 'CANCEL' : 'REQUEST'; $method = $action == 'remove' ? 'CANCEL' : 'REQUEST';
$message = $itip->compose_itip_message($event, $method); $message = $itip->compose_itip_message($event, $method, $event['sequence'] > $old['sequence']);
// list existing attendees from $old event // list existing attendees from $old event
$old_attendees = array(); $old_attendees = array();
@ -1916,6 +1918,10 @@ class calendar extends rcube_plugin
if ($attendee['noreply'] && $itip_notify & 2) if ($attendee['noreply'] && $itip_notify & 2)
continue; continue;
// skip if this attendee has delegated and set RSVP=FALSE
if ($attendee['status'] == 'DELEGATED' && $attendee['rsvp'] === false)
continue;
// which template to use for mail text // which template to use for mail text
$is_new = !in_array($attendee['email'], $old_attendees); $is_new = !in_array($attendee['email'], $old_attendees);
$is_rsvp = $is_new || $event['sequence'] > $old['sequence']; $is_rsvp = $is_new || $event['sequence'] > $old['sequence'];
@ -2639,7 +2645,8 @@ class calendar extends rcube_plugin
else if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) { else if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) {
$event['attendees'][$i]['status'] = strtoupper($status); $event['attendees'][$i]['status'] = strtoupper($status);
if (!in_array($event['attendees'][$i]['status'], array('NEEDS-ACTION','DELEGATED'))) if (!in_array($event['attendees'][$i]['status'], array('NEEDS-ACTION','DELEGATED')))
unset($event['attendees'][$i]['rsvp']); // remove RSVP attribute $event['attendees'][$i]['rsvp'] = false; // unset RSVP attribute
$metadata['attendee'] = $attendee['email']; $metadata['attendee'] = $attendee['email'];
$metadata['rsvp'] = $attendee['role'] != 'NON-PARTICIPANT'; $metadata['rsvp'] = $attendee['role'] != 'NON-PARTICIPANT';
$reply_sender = $attendee['email']; $reply_sender = $attendee['email'];
@ -2697,6 +2704,16 @@ class calendar extends rcube_plugin
} }
} }
// if delegatee has declined, set delegator's RSVP=True
if ($event_attendee && $event_attendee['status'] == 'DECLINED' && $event_attendee['delegated-from']) {
foreach ($existing['attendees'] as $i => $attendee) {
if ($attendee['email'] == $event_attendee['delegated-from']) {
$existing['attendees'][$i]['rsvp'] = true;
break;
}
}
}
// found matching attendee entry in both existing and new events // found matching attendee entry in both existing and new events
if ($existing_attendee >= 0 && $event_attendee) { if ($existing_attendee >= 0 && $event_attendee) {
$existing['attendees'][$existing_attendee] = $event_attendee; $existing['attendees'][$existing_attendee] = $event_attendee;

View file

@ -90,6 +90,7 @@ class libcalendaring_itip
* @param string Mail subject * @param string Mail subject
* @param string Mail body text label * @param string Mail body text label
* @param object Mail_mime object with message data * @param object Mail_mime object with message data
* @param boolean Request RSVP
* @return boolean True on success, false on failure * @return boolean True on success, false on failure
*/ */
public function send_itip_message($event, $method, $recipient, $subject, $bodytext, $message = null, $rsvp = true) public function send_itip_message($event, $method, $recipient, $subject, $bodytext, $message = null, $rsvp = true)
@ -98,7 +99,7 @@ class libcalendaring_itip
$this->sender['name'] = $this->sender['email']; $this->sender['name'] = $this->sender['email'];
if (!$message) if (!$message)
$message = $this->compose_itip_message($event, $method); $message = $this->compose_itip_message($event, $method, $rsvp);
$mailto = rcube_idn_to_ascii($recipient['email']); $mailto = rcube_idn_to_ascii($recipient['email']);
@ -192,9 +193,10 @@ class libcalendaring_itip
* *
* @param array Event object to send * @param array Event object to send
* @param string iTip method (REQUEST|REPLY|CANCEL) * @param string iTip method (REQUEST|REPLY|CANCEL)
* @param boolean Request RSVP
* @return object Mail_mime object with message data * @return object Mail_mime object with message data
*/ */
public function compose_itip_message($event, $method) public function compose_itip_message($event, $method, $rsvp = true)
{ {
$from = rcube_idn_to_ascii($this->sender['email']); $from = rcube_idn_to_ascii($this->sender['email']);
$from_utf = rcube_utils::idn_to_utf8($from); $from_utf = rcube_utils::idn_to_utf8($from);
@ -228,11 +230,11 @@ class libcalendaring_itip
$event['attendees'] = $reply_attendees; $event['attendees'] = $reply_attendees;
} }
} }
// set RSVP=TRUE for every attendee if not set // set RSVP for every attendee
else if ($method == 'REQUEST') { else if ($method == 'REQUEST') {
foreach ($event['attendees'] as $i => $attendee) { foreach ($event['attendees'] as $i => $attendee) {
if (!isset($attendee['rsvp'])) { if ($attendee['status'] != 'DELEGATED') {
$event['attendees'][$i]['rsvp']= true; $event['attendees'][$i]['rsvp']= $rsvp ? true : null;
} }
} }
} }

View file

@ -1072,7 +1072,8 @@ class libvcalendar implements Iterator
$event['organizer'] = $attendee; $event['organizer'] = $attendee;
} }
else if (!empty($attendee['email'])) { else if (!empty($attendee['email'])) {
$attendee['rsvp'] = $attendee['rsvp'] ? 'TRUE' : null; if (isset($attendee['rsvp']))
$attendee['rsvp'] = $attendee['rsvp'] ? 'TRUE' : 'FALSE';
$ve->add('ATTENDEE', 'mailto:' . $attendee['email'], array_filter(self::map_keys($attendee, $this->attendee_keymap))); $ve->add('ATTENDEE', 'mailto:' . $attendee['email'], array_filter(self::map_keys($attendee, $this->attendee_keymap)));
} }
} }

View file

@ -364,14 +364,17 @@ abstract class kolab_format_xcal extends kolab_format
$cr = new ContactReference(ContactReference::EmailReference, $attendee['email']); $cr = new ContactReference(ContactReference::EmailReference, $attendee['email']);
$cr->setName($attendee['name']); $cr->setName($attendee['name']);
// set attendee RSVP if missing
if (!isset($attendee['rsvp'])) {
$object['attendees'][$i]['rsvp'] = $attendee['rsvp'] = true;
}
$att = new Attendee; $att = new Attendee;
$att->setContact($cr); $att->setContact($cr);
$att->setPartStat($this->part_status_map[$attendee['status']]); $att->setPartStat($this->part_status_map[$attendee['status']]);
$att->setRole($this->role_map[$attendee['role']] ? $this->role_map[$attendee['role']] : kolabformat::Required); $att->setRole($this->role_map[$attendee['role']] ? $this->role_map[$attendee['role']] : kolabformat::Required);
$att->setCutype($this->cutype_map[$attendee['cutype']] ? $this->cutype_map[$attendee['cutype']] : kolabformat::CutypeIndividual); $att->setCutype($this->cutype_map[$attendee['cutype']] ? $this->cutype_map[$attendee['cutype']] : kolabformat::CutypeIndividual);
$att->setRSVP((bool)$attendee['rsvp'] || $reschedule); $att->setRSVP((bool)$attendee['rsvp']);
$object['attendees'][$i]['rsvp'] = $attendee['rsvp'] || $reschedule;
if (!empty($attendee['delegated-from'])) { if (!empty($attendee['delegated-from'])) {
$vdelegators = new vectorcontactref; $vdelegators = new vectorcontactref;

View file

@ -757,7 +757,7 @@ class tasklist extends rcube_plugin
// compose multipart message using PEAR:Mail_Mime // compose multipart message using PEAR:Mail_Mime
$method = $action == 'delete' ? 'CANCEL' : 'REQUEST'; $method = $action == 'delete' ? 'CANCEL' : 'REQUEST';
$object = $this->to_libcal($task); $object = $this->to_libcal($task);
$message = $itip->compose_itip_message($object, $method); $message = $itip->compose_itip_message($object, $method, $task['sequence'] > $old['sequence']);
// list existing attendees from the $old task // list existing attendees from the $old task
$old_attendees = array(); $old_attendees = array();
@ -779,6 +779,12 @@ class tasklist extends rcube_plugin
if ($attendee['noreply'] && $itip_notify & 2) { if ($attendee['noreply'] && $itip_notify & 2) {
continue; continue;
} }
// skip if this attendee has delegated and set RSVP=FALSE
if ($attendee['status'] == 'DELEGATED' && $attendee['rsvp'] === false) {
continue;
}
// which template to use for mail text // which template to use for mail text
$is_new = !in_array($attendee['email'], $old_attendees); $is_new = !in_array($attendee['email'], $old_attendees);
$is_rsvp = $is_new || $task['sequence'] > $old['sequence']; $is_rsvp = $is_new || $task['sequence'] > $old['sequence'];
@ -1776,7 +1782,7 @@ class tasklist extends rcube_plugin
$task['attendees'][$i]['status'] = strtoupper($status); $task['attendees'][$i]['status'] = strtoupper($status);
if (!in_array($task['attendees'][$i]['status'], array('NEEDS-ACTION','DELEGATED'))) { if (!in_array($task['attendees'][$i]['status'], array('NEEDS-ACTION','DELEGATED'))) {
unset($task['attendees'][$i]['rsvp']); // remove RSVP attribute $task['attendees'][$i]['rsvp'] = false; // unset RSVP attribute
} }
} }
} }
@ -1833,6 +1839,16 @@ class tasklist extends rcube_plugin
} }
} }
// if delegatee has declined, set delegator's RSVP=True
if ($task_attendee && $task_attendee['status'] == 'DECLINED' && $task_attendee['delegated-from']) {
foreach ($existing['attendees'] as $i => $attendee) {
if ($attendee['email'] == $task_attendee['delegated-from']) {
$existing['attendees'][$i]['rsvp'] = true;
break;
}
}
}
// found matching attendee entry in both existing and new events // found matching attendee entry in both existing and new events
if ($existing_attendee >= 0 && $task_attendee) { if ($existing_attendee >= 0 && $task_attendee) {
$existing['attendees'][$existing_attendee] = $task_attendee; $existing['attendees'][$existing_attendee] = $task_attendee;