summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-05-16 15:16:35 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-05-16 15:16:35 (GMT)
commit505413660949104a8fea51b0f36f5074999ac38c (patch)
tree8f934a3d197c1a91d249698d53b117d4c28d6202
parent14f169e961894f1574fe2ae7dfacecacb677925b (diff)
downloadiRony-505413660949104a8fea51b0f36f5074999ac38c.tar.gz
Send iTIP messages if commanded from iCal
-rw-r--r--lib/Kolab/CalDAV/CalendarBackend.php5
-rw-r--r--lib/Kolab/CalDAV/IMip.php141
-rw-r--r--lib/Kolab/CalDAV/UserCalendars.php5
-rw-r--r--lib/Kolab/DAV/Auth/HTTPBasic.php2
-rw-r--r--public_html/index.php14
5 files changed, 162 insertions, 5 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);
diff --git a/lib/Kolab/DAV/Auth/HTTPBasic.php b/lib/Kolab/DAV/Auth/HTTPBasic.php
index 3b551ab..3095119 100644
--- a/lib/Kolab/DAV/Auth/HTTPBasic.php
+++ b/lib/Kolab/DAV/Auth/HTTPBasic.php
@@ -88,7 +88,7 @@ class HTTPBasic extends \Sabre\DAV\Auth\Backend\AbstractBasic
if ($success) {
self::$current_user = $auth['user'];
- self::$current_pass = $password;
+ self::$current_pass = $rcube->password = $password;
if (!$auth_user) {
$cache->set($user, $auth['user']);
}
diff --git a/public_html/index.php b/public_html/index.php
index fa59084..9f36579 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -74,9 +74,10 @@ if ($debug = $rcube->config->get('kolab_dav_debug')) {
$http_headers .= "$hdr: $value\n";
}
// read HTTP request body (with our own file handle)
- #$in = fopen('php://input', 'r');
- #while (!feof($in)) $http_body .= fread($in, 1024);
- #fclose($in);
+# $in = fopen('php://input', 'r');
+# $http_body = stream_get_contents($in);
+# fseek($in, 0);
+# fclose($in);
$rcube->write_log('davdebug', $http_headers . "\n" . $http_body . "\n");
ob_start(); // turn on output buffering
@@ -115,8 +116,13 @@ $server->setBaseUri($base_uri);
// register some plugins
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($auth_backend, 'KolabDAV'));
$server->addPlugin(new \Sabre\DAVACL\Plugin());
-$server->addPlugin(new \Kolab\CalDAV\Plugin());
$server->addPlugin(new \Kolab\CardDAV\Plugin());
+
+$caldav_plugin = new \Kolab\CalDAV\Plugin();
+$caldav_plugin->setIMipHandler(new \Kolab\CalDAV\IMip());
+$server->addPlugin($caldav_plugin);
+
+// HTML UI for browser-based access (recommended only for development)
$server->addPlugin(new \Sabre\DAV\Browser\Plugin());
// finally, process the request