diff options
author | Thomas Bruederli <bruederli@kolabsys.com> | 2013-05-16 15:16:35 (GMT) |
---|---|---|
committer | Thomas Bruederli <bruederli@kolabsys.com> | 2013-05-16 15:16:35 (GMT) |
commit | 505413660949104a8fea51b0f36f5074999ac38c (patch) | |
tree | 8f934a3d197c1a91d249698d53b117d4c28d6202 /lib/Kolab/CalDAV | |
parent | 14f169e961894f1574fe2ae7dfacecacb677925b (diff) | |
download | iRony-505413660949104a8fea51b0f36f5074999ac38c.tar.gz |
Send iTIP messages if commanded from iCal
Diffstat (limited to 'lib/Kolab/CalDAV')
-rw-r--r-- | lib/Kolab/CalDAV/CalendarBackend.php | 5 | ||||
-rw-r--r-- | lib/Kolab/CalDAV/IMip.php | 141 | ||||
-rw-r--r-- | lib/Kolab/CalDAV/UserCalendars.php | 5 |
3 files changed, 151 insertions, 0 deletions
diff --git a/lib/Kolab/CalDAV/CalendarBackend.php b/lib/Kolab/CalDAV/CalendarBackend.php index 04b1935..17fe833 100644 --- a/lib/Kolab/CalDAV/CalendarBackend.php +++ b/lib/Kolab/CalDAV/CalendarBackend.php @@ -790,6 +790,7 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend case 'DESCRIPTION': case 'LOCATION': + case 'URL': $event[strtolower($prop->name)] = $prop->value; break; @@ -988,6 +989,10 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend } } + foreach ((array)$event['url'] as $url) { + $ve->add('URL', $url); + } + foreach ((array)$event['links'] as $uri) { $ve->add('ATTACH', $uri); } diff --git a/lib/Kolab/CalDAV/IMip.php b/lib/Kolab/CalDAV/IMip.php new file mode 100644 index 0000000..a846f92 --- /dev/null +++ b/lib/Kolab/CalDAV/IMip.php @@ -0,0 +1,141 @@ +<?php + +/** + * Extended CalDAV IMip handler for the Kolab DAV server + * + * @author Thomas Bruederli <bruederli@kolabsys.com> + * + * Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +namespace Kolab\CalDAV; + +use \rcube; +use \rcube_utils; +use \Mail_mime; + +use Sabre\VObject; +use Sabre\CalDAV; +use Sabre\DAV; + +/** + * iMIP handler. + * + * This class is responsible for sending out iMIP messages. iMIP is the + * email-based transport for iTIP. iTIP deals with scheduling operations for + * iCalendar objects. + * + * If you want to customize the email that gets sent out, you can do so by + * extending this class and overriding the sendMessage method. + * + * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class IMip extends CalDAV\Schedule\IMip +{ + public function __construct() + { + + } + + /** + * Sends one or more iTip messages through email. + * + * @param string $originator Originator Email + * @param array $recipients Array of email addresses + * @param VObject\Component $vObject + * @param string $principal Principal Url of the originator + * @return void + */ + public function sendMessage($originator, array $recipients, VObject\Component $vObject, $principal) + { + $ics = $vObject->serialize(); + console(__METHOD__, $originator, $recipients, $principal, $ics); + + $rcube = rcube::get_instance(); + $sender = $rcube->user->get_identity(); + $sender_email = $sender['email'] ?: $rcube->get_user_email(); + $sender_name = $sender['name'] ?: $rcube->get_user_name(); + + foreach($recipients as $recipient) { + $subject = 'KolabDAV iTIP message'; + switch (strtoupper($vObject->METHOD)) { + case 'REPLY' : + $subject = 'Response for: ' . $vObject->VEVENT->SUMMARY; + break; + case 'REQUEST' : + $subject = 'Invitation for: ' .$vObject->VEVENT->SUMMARY; + break; + case 'CANCEL' : + $subject = 'Cancelled event: ' . $vObject->VEVENT->SUMMARY; + break; + } + + $sender = rcube_utils::idn_to_ascii($sender_email); + $from = format_email_recipient($sender, $sender_name); + $mailto = rcube_utils::idn_to_ascii($recipient); + + // 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"); + + // compose common headers array + $headers = array( + 'To' => $mailto, + 'From' => $from, + 'Date' => date('r'), + 'Reply-To' => $originator, + 'Message-ID' => $rcube->gen_message_id(), + 'X-Sender' => $sender, + 'Subject' => $subject, + ); + if ($agent = $rcube->config->get('useragent')) + $headers['User-Agent'] = $agent; + + $message->headers($headers); + $message->setContentType('text/calendar', array('method' => strval($vObject->method), 'charset' => RCMAIL_CHARSET)); + $message->setTXTBody($ics); + + // send message through Roundcube's SMTP feature + if (!$rcube->deliver_message($message, $sender, $mailto, $smtp_error)) { + rcube::raise_error(array( + 'code' => 600, 'type' => 'php', + 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Failed to send iTIP message to " . $mailto), + true, false); + } + } + } + + /** + * This function is reponsible for sending the actual email. + * + * @param string $to Recipient email address + * @param string $subject Subject of the email + * @param string $body iCalendar body + * @param array $headers List of headers + * @return void + */ + protected function mail($to, $subject, $body, array $headers) + { + //mail($to, $subject, $body, implode("\r\n", $headers)); + } + +} diff --git a/lib/Kolab/CalDAV/UserCalendars.php b/lib/Kolab/CalDAV/UserCalendars.php index ab39185..dcd2aff 100644 --- a/lib/Kolab/CalDAV/UserCalendars.php +++ b/lib/Kolab/CalDAV/UserCalendars.php @@ -35,6 +35,8 @@ use Kolab\CalDAV\Calendar; */ class UserCalendars extends \Sabre\CalDAV\UserCalendars implements DAV\IExtendedCollection, DAVACL\IACL { + private $outbox; + /** * Returns a list of calendars * @@ -78,6 +80,9 @@ class UserCalendars extends \Sabre\CalDAV\UserCalendars implements DAV\IExtended */ public function getChild($name) { + if ($name == 'outbox') { + return new Schedule\Outbox($this->principalInfo['uri']); + } if ($calendar = $this->caldavBackend->getCalendarByName($name)) { $calendar['principaluri'] = $this->principalInfo['uri']; return new Calendar($this->caldavBackend, $calendar); |