summaryrefslogtreecommitdiff
path: root/lib/Kolab/CardDAV/Plugin.php
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-03-14 16:48:10 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-03-14 16:48:10 (GMT)
commit5515a4b398f4ccc2b6f32d810d4fb7eed47c3efa (patch)
tree48700a1f304ebe736d70d5a8889d619f4204579a /lib/Kolab/CardDAV/Plugin.php
parent5ec426a349db1bf8720228b4df4d08388a59b8ab (diff)
downloadiRony-5515a4b398f4ccc2b6f32d810d4fb7eed47c3efa.tar.gz
- Use UIDs from IMAP annoations for collection IDs
- Implement CardDAV/AddressBook classes for proper ACL/sharing support - Enable Free-Busy queries to CalDAV
Diffstat (limited to 'lib/Kolab/CardDAV/Plugin.php')
-rw-r--r--lib/Kolab/CardDAV/Plugin.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/Kolab/CardDAV/Plugin.php b/lib/Kolab/CardDAV/Plugin.php
new file mode 100644
index 0000000..6268989
--- /dev/null
+++ b/lib/Kolab/CardDAV/Plugin.php
@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * Extended CardDAV plugin 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\CardDAV;
+
+use Sabre\DAV;
+use Sabre\CardDAV;
+use Sabre\VObject;
+
+
+/**
+ * Extended CardDAV plugin to tweak data validation
+ */
+class Plugin extends CardDAV\Plugin
+{
+ // make already parsed vcard blocks available for later use
+ public static $parsed_vcard;
+
+
+ /**
+ * Checks if the submitted iCalendar data is in fact, valid.
+ *
+ * An exception is thrown if it's not.
+ *
+ * @param resource|string $data
+ * @return void
+ */
+ protected function validateVCard(&$data)
+ {
+ // If it's a stream, we convert it to a string first.
+ if (is_resource($data)) {
+ $data = stream_get_contents($data);
+ }
+
+ // Converting the data to unicode, if needed.
+ $data = DAV\StringUtil::ensureUTF8($data);
+
+ try {
+ $vobj = VObject\Reader::read($data, VObject\Reader::OPTION_FORGIVING | VObject\Reader::OPTION_IGNORE_INVALID_LINES);
+
+ if ($vobj->name == 'VCARD')
+ $this->parsed_vcard = $vobj;
+ }
+ catch (VObject\ParseException $e) {
+ throw new DAV\Exception\UnsupportedMediaType('This resource only supports valid vcard data. Parse error: ' . $e->getMessage());
+ }
+
+ if ($vobj->name !== 'VCARD') {
+ throw new DAV\Exception\UnsupportedMediaType('This collection can only support vcard objects.');
+ }
+
+ if (!isset($vobj->UID)) {
+ throw new DAV\Exception\BadRequest('Every vcard must have a UID.');
+ }
+ }
+
+} \ No newline at end of file