summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-03-20 15:21:20 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-03-20 15:21:20 (GMT)
commit6f526b71a5cadd9ea99d1ed28fd62faf72b1d9df (patch)
tree44dec47b9f35b9757e87f9d0e7570880326dc446
parent9e55e39d63b81446d1039cdad94330e7ad4c1bf3 (diff)
downloadiRony-6f526b71a5cadd9ea99d1ed28fd62faf72b1d9df.tar.gz
List calendar attachments as URIs and deliver contents on request
-rw-r--r--lib/Kolab/CalDAV/CalendarBackend.php41
-rw-r--r--lib/Kolab/Utils/DAVBackend.php29
2 files changed, 63 insertions, 7 deletions
diff --git a/lib/Kolab/CalDAV/CalendarBackend.php b/lib/Kolab/CalDAV/CalendarBackend.php
index c8b8416..085a5c0 100644
--- a/lib/Kolab/CalDAV/CalendarBackend.php
+++ b/lib/Kolab/CalDAV/CalendarBackend.php
@@ -146,8 +146,8 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
$calendars = array();
foreach ($this->calendars as $id => $cal) {
- $cal['principaluri'] = $principalUri;
- $calendars[] = $cal;
+ $this->calendars[$id]['principaluri'] = $principalUri;
+ $calendars[] = $this->calendars[$id];
}
return $calendars;
@@ -384,13 +384,38 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
$uid = basename($objectUri, '.ics');
$storage = $this->get_storage_folder($calendarId);
+ // attachment content is requested
+ if (preg_match('!^(.+).ics:attachment:(\w+)$!', $objectUri, $m)) {
+ $uid = $m[1]; $part = $m[2];
+ }
+
if ($storage && ($event = $storage->get_object($uid))) {
+ // deliver attachment content directly
+ if ($part && !empty($event['_attachments'])) {
+ foreach ($event['_attachments'] as $attachment) {
+ if ($attachment['id'] == $part) {
+ header('Content-Type: ' . $attachment['mimetype']);
+ header('Content-Disposition: inline; filename="' . $attachment['name'] . '"');
+ $storage->get_attachment($uid, $part, null, true);
+ exit;
+ }
+ }
+ }
+
+ $base_uri = DAVBackend::abs_url(array(
+ CalDAV\Plugin::CALENDAR_ROOT,
+ preg_replace('!principals/!', '', $this->calendars[$calendarId]['principaluri']),
+ $calendarId,
+ $event['uid'] . '.ics',
+ ));
+
+ // default response
return array(
'id' => $event['uid'],
'uri' => $event['uid'] . '.ics',
'lastmodified' => $event['changed']->format('U'),
'calendarid' => $calendarId,
- 'calendardata' => $this->_to_ical($event),
+ 'calendardata' => $this->_to_ical($event, $base_uri),
'etag' => self::_get_etag($event),
);
}
@@ -835,12 +860,13 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
* Build a valid iCal format block from the given event
*
* @param array Hash array with event properties from libkolab
+ * @param string Absolute URI referenceing this event object
* @param object RECURRENCE-ID property when serializing a recurrence exception
* @return mixed VCALENDAR string containing the VEVENT data
* or VObject\VEvent object with a recurrence exception instance
* @TODO: move this to libcalendaring for common use
*/
- private function _to_ical($event, $recurrence_id = null)
+ private function _to_ical($event, $base_uri, $recurrence_id = null)
{
$ve = VObject\Component::create('VEVENT');
$ve->add('UID', $event['uid']);
@@ -924,6 +950,11 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
$ve->add('ATTENDEE', 'mailto:' . $attendee['email'], VObjectUtils::map_keys($attendee, $this->attendee_keymap));
}
+ // list attachments as absolute URIs
+ foreach ((array)$event['_attachments'] as $attachment) {
+ $ve->add('ATTACH', $base_uri . ':attachment:' . $attachment['id']);
+ }
+
foreach ((array)$event['links'] as $uri) {
$ve->add('ATTACH', $uri);
}
@@ -952,7 +983,7 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
$recurrence_id = VObjectUtils::datetime_prop('RECURRENCE-ID', $exdate);
// if ($ex['thisandfuture']) // not supported by any client :-(
// $recurrence_id->add('RANGE', 'THISANDFUTURE');
- $vcal->add($this->_to_ical($ex, $recurrence_id));
+ $vcal->add($this->_to_ical($ex, $base_uri, $recurrence_id));
}
}
diff --git a/lib/Kolab/Utils/DAVBackend.php b/lib/Kolab/Utils/DAVBackend.php
index 822437b..3a1708c 100644
--- a/lib/Kolab/Utils/DAVBackend.php
+++ b/lib/Kolab/Utils/DAVBackend.php
@@ -24,6 +24,7 @@
namespace Kolab\Utils;
use \kolab_storage;
+use \rcube_utils;
/**
*
@@ -86,5 +87,29 @@ class DAVBackend
return $success;
}
-
-} \ No newline at end of file
+
+ /**
+ * Build an absolute URL with the given parameters
+ */
+ public static function abs_url($parts = array())
+ {
+ $schema = 'http';
+ $default_port = 80;
+ if (rcube_utils::https_check()) {
+ $schema = 'https';
+ $default_port = 443;
+ }
+ $url = $schema . '://' . $_SERVER['HTTP_HOST'];
+
+ if ($_SERVER['SERVER_PORT'] != $default_port)
+ $url .= ':' . $_SERVER['SERVER_PORT'];
+
+ if (dirname($_SERVER['SCRIPT_NAME']))
+ $url .= dirname($_SERVER['SCRIPT_NAME']);
+
+ $url .= join('/', array_map('urlencode', $parts));
+
+ return $url;
+ }
+
+}