/**
  * Send an iTip mail message
  *
  * @param array   Event object to send
  * @param string  iTip method (REQUEST|REPLY|CANCEL)
  * @param array   Hash array with recipient data (name, email)
  * @param string  Mail subject
  * @param string  Mail body text label
  * @param object  Mail_mime object with message data
  * @return boolean True on success, false on failure
  */
 public function send_itip_message($event, $method, $recipient, $subject, $bodytext, $message = null)
 {
     if (!$this->sender['name']) {
         $this->sender['name'] = $this->sender['email'];
     }
     if (!$message) {
         $message = $this->compose_itip_message($event, $method);
     }
     $mailto = rcube_idn_to_ascii($recipient['email']);
     $headers = $message->headers();
     $headers['To'] = format_email_recipient($mailto, $recipient['name']);
     $headers['Subject'] = $this->cal->gettext(array('name' => $subject, 'vars' => array('title' => $event['title'], 'name' => $this->sender['name'])));
     // compose a list of all event attendees
     $attendees_list = array();
     foreach ((array) $event['attendees'] as $attendee) {
         $attendees_list[] = $attendee['name'] && $attendee['email'] ? $attendee['name'] . ' <' . $attendee['email'] . '>' : ($attendee['name'] ? $attendee['name'] : $attendee['email']);
     }
     $mailbody = $this->cal->gettext(array('name' => $bodytext, 'vars' => array('title' => $event['title'], 'date' => $this->cal->lib->event_date_text($event, true), 'attendees' => join(', ', $attendees_list), 'sender' => $this->sender['name'], 'organizer' => $this->sender['name'])));
     // append links for direct invitation replies
     if ($method == 'REQUEST' && ($token = $this->store_invitation($event, $recipient['email']))) {
         $mailbody .= "\n\n" . $this->cal->gettext(array('name' => 'invitationattendlinks', 'vars' => array('url' => $this->cal->get_url(array('action' => 'attend', 't' => $token)))));
     } else {
         if ($method == 'CANCEL') {
             $this->cancel_itip_invitation($event);
         }
     }
     $message->headers($headers, true);
     $message->setTXTBody(rcube_mime::format_flowed($mailbody, 79));
     // finally send the message
     $this->itip_send = true;
     $sent = $this->rc->deliver_message($message, $headers['X-Sender'], $mailto, $smtp_error);
     $this->itip_send = false;
     return $sent;
 }
 public static function format_flowed($text, $length = 72)
 {
     return rcube_mime::format_flowed($text, $length);
 }
Beispiel #3
0
 /**
  * Test format=flowed unfolding
  */
 function test_format_flowed()
 {
     $raw = file_get_contents(TESTS_DIR . 'src/format-flowed-unfolded.txt');
     $flowed = file_get_contents(TESTS_DIR . 'src/format-flowed.txt');
     $this->assertEquals($flowed, rcube_mime::format_flowed($raw, 80), "Test correct folding and space-stuffing");
 }
 /**
  * Send an iTip mail message
  *
  * @param array   Event object to send
  * @param string  iTip method (REQUEST|REPLY|CANCEL)
  * @param array   Hash array with recipient data (name, email)
  * @param string  Mail subject
  * @param string  Mail body text label
  * @param object  Mail_mime object with message data
  * @param boolean Request RSVP
  * @return boolean True on success, false on failure
  */
 public function send_itip_message($event, $method, $recipient, $subject, $bodytext, $message = null, $rsvp = true)
 {
     if (!$this->sender['name']) {
         $this->sender['name'] = $this->sender['email'];
     }
     if (!$message) {
         libcalendaring::identify_recurrence_instance($event);
         $message = $this->compose_itip_message($event, $method, $rsvp);
     }
     $mailto = rcube_utils::idn_to_ascii($recipient['email']);
     $headers = $message->headers();
     $headers['To'] = format_email_recipient($mailto, $recipient['name']);
     $headers['Subject'] = $this->gettext(array('name' => $subject, 'vars' => array('title' => $event['title'], 'name' => $this->sender['name'])));
     // compose a list of all event attendees
     $attendees_list = array();
     foreach ((array) $event['attendees'] as $attendee) {
         $attendees_list[] = $attendee['name'] && $attendee['email'] ? $attendee['name'] . ' <' . $attendee['email'] . '>' : ($attendee['name'] ? $attendee['name'] : $attendee['email']);
     }
     $recurrence_info = '';
     if (!empty($event['recurrence_id'])) {
         $recurrence_info = "\n\n** " . $this->gettext($event['thisandfuture'] ? 'itipmessagefutureoccurrence' : 'itipmessagesingleoccurrence') . ' **';
     } else {
         if (!empty($event['recurrence'])) {
             $recurrence_info = sprintf("\n%s: %s", $this->gettext('recurring'), $this->lib->recurrence_text($event['recurrence']));
         }
     }
     $mailbody = $this->gettext(array('name' => $bodytext, 'vars' => array('title' => $event['title'], 'date' => $this->lib->event_date_text($event, true) . $recurrence_info, 'attendees' => join(",\n ", $attendees_list), 'sender' => $this->sender['name'], 'organizer' => $this->sender['name'])));
     // if (!empty($event['comment'])) {
     //     $mailbody .= "\n\n" . $this->gettext('itipsendercomment') . $event['comment'];
     // }
     // append links for direct invitation replies
     if ($method == 'REQUEST' && $rsvp && ($token = $this->store_invitation($event, $recipient['email']))) {
         $mailbody .= "\n\n" . $this->gettext(array('name' => 'invitationattendlinks', 'vars' => array('url' => $this->plugin->get_url(array('action' => 'attend', 't' => $token)))));
     } else {
         if ($method == 'CANCEL' && $event['cancelled']) {
             $this->cancel_itip_invitation($event);
         }
     }
     $message->headers($headers, true);
     $message->setTXTBody(rcube_mime::format_flowed($mailbody, 79));
     if ($this->rc->config->get('libcalendaring_itip_debug', false)) {
         rcmail::console('iTip ' . $method, $message->txtHeaders() . "\n\r" . $message->get());
     }
     // finally send the message
     $this->itip_send = true;
     $sent = $this->rc->deliver_message($message, $headers['X-Sender'], $mailto, $smtp_error);
     $this->itip_send = false;
     return $sent;
 }