Changeset View
Changeset View
Standalone View
Standalone View
plugins/calendar/calendar.php
Show First 20 Lines • Show All 3,425 Lines • ▼ Show 20 Lines | public function mail_import_itip() | ||||
if ($existing) { | if ($existing) { | ||||
$calendar = $calendars[$existing['calendar']]; | $calendar = $calendars[$existing['calendar']]; | ||||
// forward savemode for correct updates of recurring events | // forward savemode for correct updates of recurring events | ||||
$existing['_savemode'] = $savemode ?: (!empty($event['_savemode']) ? $event['_savemode'] : null); | $existing['_savemode'] = $savemode ?: (!empty($event['_savemode']) ? $event['_savemode'] : null); | ||||
// only update attendee status | // only update attendee status | ||||
if ($event['_method'] == 'REPLY') { | if ($event['_method'] == 'REPLY') { | ||||
// try to identify the attendee using the email sender address | $existing_attendee_index = -1; | ||||
$existing_attendee = -1; | |||||
$existing_attendee_emails = []; | |||||
foreach ($existing['attendees'] as $i => $attendee) { | |||||
$existing_attendee_emails[] = $attendee['email']; | |||||
if ($this->itip->compare_email($attendee['email'], $event['_sender'], $event['_sender_utf'])) { | |||||
$existing_attendee = $i; | |||||
} | |||||
} | |||||
$event_attendee = null; | $event_attendee = null; | ||||
$update_attendees = []; | $update_attendees = []; | ||||
foreach ($event['attendees'] as $attendee) { | if ($attendee = $this->itip->find_reply_attendee($event)) { | ||||
if ($this->itip->compare_email($attendee['email'], $event['_sender'], $event['_sender_utf'])) { | |||||
$event_attendee = $attendee; | $event_attendee = $attendee; | ||||
$update_attendees[] = $attendee; | $update_attendees[] = $attendee; | ||||
$metadata['fallback'] = $attendee['status']; | $metadata['fallback'] = $attendee['status']; | ||||
$metadata['attendee'] = $attendee['email']; | $metadata['attendee'] = $attendee['email']; | ||||
$metadata['rsvp'] = !empty($attendee['rsvp']) || $attendee['role'] != 'NON-PARTICIPANT'; | $metadata['rsvp'] = !empty($attendee['rsvp']) || $attendee['role'] != 'NON-PARTICIPANT'; | ||||
if ($attendee['status'] != 'DELEGATED') { | $existing_attendee_emails = []; | ||||
break; | |||||
// Find the attendee to update | |||||
foreach ($existing['attendees'] as $i => $existing_attendee) { | |||||
$existing_attendee_emails[] = $existing_attendee['email']; | |||||
if ($this->itip->compare_email($existing_attendee['email'], $attendee['email'])) { | |||||
$existing_attendee_index = $i; | |||||
} | } | ||||
} | } | ||||
// also copy delegate attendee | |||||
else if (!empty($attendee['delegated-from']) | if ($attendee['status'] == 'DELEGATED') { | ||||
&& $this->itip->compare_email($attendee['delegated-from'], $event['_sender'], $event['_sender_utf']) | //Also find and copy the delegatee | ||||
) { | $delegatee_email = $attendee['email']; | ||||
$update_attendees[] = $attendee; | $delegatees = array_filter($event['attendees'], function($attendee) use ($delegatee_email){ return $attendee['role'] != 'ORGANIZER' && $this->itip->compare_email($attendee['delegated-from'], $delegatee_email); }); | ||||
if (!in_array_nocase($attendee['email'], $existing_attendee_emails)) { | |||||
$existing['attendees'][] = $attendee; | if ($delegatee = $this->itip->find_attendee_by_email($event['attendees'], 'delegated-from', $attendee['email'])) { | ||||
$update_attendees[] = $delegatee; | |||||
if (!in_array_nocase($delegatee['email'], $existing_attendee_emails)) { | |||||
$existing['attendees'][] = $delegated_attendee; | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// if delegatee has declined, set delegator's RSVP=True | // if delegatee has declined, set delegator's RSVP=True | ||||
if ($event_attendee | if ($event_attendee | ||||
&& $event_attendee['status'] == 'DECLINED' | && $event_attendee['status'] == 'DECLINED' | ||||
&& !empty($event_attendee['delegated-from']) | && !empty($event_attendee['delegated-from']) | ||||
) { | ) { | ||||
foreach ($existing['attendees'] as $i => $attendee) { | foreach ($existing['attendees'] as $i => $attendee) { | ||||
if ($attendee['email'] == $event_attendee['delegated-from']) { | if ($attendee['email'] == $event_attendee['delegated-from']) { | ||||
$existing['attendees'][$i]['rsvp'] = true; | $existing['attendees'][$i]['rsvp'] = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Accept sender as a new participant (different email in From: and the iTip) | |||||
// Use ATTENDEE entry from the iTip with replaced email address | |||||
if (!$event_attendee) { | |||||
// remove the organizer | |||||
$itip_attendees = array_filter( | |||||
$event['attendees'], | |||||
function($item) { return $item['role'] != 'ORGANIZER'; } | |||||
); | |||||
// there must be only one attendee | |||||
if (is_array($itip_attendees) && count($itip_attendees) == 1) { | |||||
$event_attendee = $itip_attendees[key($itip_attendees)]; | |||||
$event_attendee['email'] = $event['_sender']; | |||||
$update_attendees[] = $event_attendee; | |||||
$metadata['fallback'] = $event_attendee['status']; | |||||
$metadata['attendee'] = $event_attendee['email']; | |||||
$metadata['rsvp'] = !empty($event_attendee['rsvp']) || $event_attendee['role'] != 'NON-PARTICIPANT'; | |||||
} | |||||
} | |||||
// 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_index >= 0 && $event_attendee) { | ||||
$existing['attendees'][$existing_attendee] = $event_attendee; | $existing['attendees'][$existing_attendee_index] = $event_attendee; | ||||
$success = $this->driver->update_attendees($existing, $update_attendees); | $success = $this->driver->update_attendees($existing, $update_attendees); | ||||
} | } | ||||
// update the entire attendees block | // update the entire attendees block | ||||
else if ( | else if ( | ||||
($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) | ($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) | ||||
&& $event_attendee | && $event_attendee | ||||
) { | ) { | ||||
$existing['attendees'][] = $event_attendee; | $existing['attendees'][] = $event_attendee; | ||||
▲ Show 20 Lines • Show All 482 Lines • Show Last 20 Lines |