/**
  * Helper function to build a Mail_mime object to send an iTip message
  *
  * @param array   Event object to send
  * @param string  iTip method (REQUEST|REPLY|CANCEL)
  * @param boolean Request RSVP
  * @return object Mail_mime object with message data
  */
 public function compose_itip_message($event, $method, $rsvp = true)
 {
     $from = rcube_utils::idn_to_ascii($this->sender['email']);
     $from_utf = rcube_utils::idn_to_utf8($from);
     $sender = format_email_recipient($from, $this->sender['name']);
     // truncate list attendees down to the recipient of the iTip Reply.
     // constraints for a METHOD:REPLY according to RFC 5546
     if ($method == 'REPLY') {
         $replying_attendee = null;
         $reply_attendees = array();
         foreach ($event['attendees'] as $attendee) {
             if ($attendee['role'] == 'ORGANIZER') {
                 $reply_attendees[] = $attendee;
             } else {
                 if (strcasecmp($attendee['email'], $from) == 0 || strcasecmp($attendee['email'], $from_utf) == 0) {
                     $replying_attendee = $attendee;
                     if ($attendee['status'] != 'DELEGATED') {
                         unset($replying_attendee['rsvp']);
                         // unset the RSVP attribute
                     }
                 } else {
                     if (!empty($attendee['delegated-to']) && (strcasecmp($attendee['delegated-to'], $from) == 0 || strcasecmp($attendee['delegated-to'], $from_utf) == 0) || !empty($attendee['delegated-from']) && (strcasecmp($attendee['delegated-from'], $from) == 0 || strcasecmp($attendee['delegated-from'], $from_utf) == 0)) {
                         $reply_attendees[] = $attendee;
                     }
                 }
             }
         }
         if ($replying_attendee) {
             array_unshift($reply_attendees, $replying_attendee);
             $event['attendees'] = $reply_attendees;
         }
         if ($event['recurrence']) {
             unset($event['recurrence']['EXCEPTIONS']);
         }
     } else {
         if ($method == 'REQUEST') {
             foreach ($event['attendees'] as $i => $attendee) {
                 if (($rsvp || !isset($attendee['rsvp'])) && ($attendee['status'] != 'DELEGATED' && $attendee['role'] != 'NON-PARTICIPANT')) {
                     $event['attendees'][$i]['rsvp'] = (bool) $rsvp;
                 }
             }
         } else {
             if ($method == 'CANCEL') {
                 if ($event['recurrence']) {
                     unset($event['recurrence']['EXCEPTIONS']);
                 }
             }
         }
     }
     // compose multipart message using PEAR:Mail_Mime
     $message = new Mail_mime("\r\n");
     $message->setParam('text_encoding', 'quoted-printable');
     $message->setParam('head_encoding', 'quoted-printable');
     $message->setParam('head_charset', RCUBE_CHARSET);
     $message->setParam('text_charset', RCUBE_CHARSET . ";\r\n format=flowed");
     $message->setContentType('multipart/alternative');
     // compose common headers array
     $headers = array('From' => $sender, 'Date' => $this->rc->user_date(), 'Message-ID' => $this->rc->gen_message_id(), 'X-Sender' => $from);
     if ($agent = $this->rc->config->get('useragent')) {
         $headers['User-Agent'] = $agent;
     }
     $message->headers($headers);
     // attach ics file for this event
     $ical = libcalendaring::get_ical();
     $ics = $ical->export(array($event), $method, false, $method == 'REQUEST' && $this->plugin->driver ? array($this->plugin->driver, 'get_attachment_body') : false);
     $filename = $event['_type'] == 'task' ? 'todo.ics' : 'event.ics';
     $message->addAttachment($ics, 'text/calendar', $filename, false, '8bit', '', RCUBE_CHARSET . "; method=" . $method);
     return $message;
 }
Exemplo n.º 2
0
 /**
  * Helper function to build a Mail_mime object to send an iTip message
  *
  * @param array   Event object to send
  * @param string  iTip method (REQUEST|REPLY|CANCEL)
  * @return object Mail_mime object with message data
  */
 public function compose_itip_message($event, $method)
 {
     $from = rcube_idn_to_ascii($this->sender['email']);
     $from_utf = rcube_idn_to_utf8($from);
     $sender = format_email_recipient($from, $this->sender['name']);
     // truncate list attendees down to the recipient of the iTip Reply.
     // constraints for a METHOD:REPLY according to RFC 5546
     if ($method == 'REPLY') {
         $replying_attendee = null;
         $reply_attendees = array();
         foreach ($event['attendees'] as $attendee) {
             if ($attendee['role'] == 'ORGANIZER') {
                 $reply_attendees[] = $attendee;
             } else {
                 if (strcasecmp($attedee['email'], $from) == 0 || strcasecmp($attendee['email'], $from_utf) == 0) {
                     $replying_attendee = $attendee;
                 }
             }
         }
         if ($replying_attendee) {
             $reply_attendees[] = $replying_attendee;
             $event['attendees'] = $reply_attendees;
         }
     }
     // compose multipart message using PEAR:Mail_Mime
     $message = new Mail_mime("\r\n");
     $message->setParam('text_encoding', 'quoted-printable');
     $message->setParam('head_encoding', 'quoted-printable');
     $message->setParam('head_charset', RCMAIL_CHARSET);
     $message->setParam('text_charset', RCMAIL_CHARSET . ";\r\n format=flowed");
     $message->setContentType('multipart/alternative');
     // compose common headers array
     $headers = array('From' => $sender, 'Date' => $this->rc->user_date(), 'Message-ID' => $this->rc->gen_message_id(), 'X-Sender' => $from);
     if ($agent = $this->rc->config->get('useragent')) {
         $headers['User-Agent'] = $agent;
     }
     $message->headers($headers);
     // attach ics file for this event
     $ical = $this->cal->get_ical();
     $ics = $ical->export(array($event), $method, false, $method == 'REQUEST' ? array($this->cal->driver, 'get_attachment_body') : false);
     $message->addAttachment($ics, 'text/calendar', 'event.ics', false, '8bit', '', RCMAIL_CHARSET . "; method=" . $method);
     return $message;
 }