5 commits - lib/ext lib/kolab_sync_data_calendar.php lib/kolab_sync_data_email.php lib/kolab_sync_data.php lib/kolab_sync_data_tasks.php lib/kolab_sync.php lib/plugins tests/data.php
Aleksander Machniak
machniak at kolabsys.com
Thu Mar 28 18:14:48 CET 2013
lib/ext/Roundcube/html.php | 30
lib/ext/Roundcube/rcube.php | 7
lib/ext/Roundcube/rcube_addressbook.php | 16
lib/ext/Roundcube/rcube_base_replacer.php | 2
lib/ext/Roundcube/rcube_browser.php | 2
lib/ext/Roundcube/rcube_content_filter.php | 2
lib/ext/Roundcube/rcube_db.php | 37
lib/ext/Roundcube/rcube_db_mssql.php | 28
lib/ext/Roundcube/rcube_db_sqlsrv.php | 28
lib/ext/Roundcube/rcube_html2text.php | 94 +
lib/ext/Roundcube/rcube_image.php | 23
lib/ext/Roundcube/rcube_imap.php | 43
lib/ext/Roundcube/rcube_imap_cache.php | 2
lib/ext/Roundcube/rcube_imap_generic.php | 52 -
lib/ext/Roundcube/rcube_ldap.php | 184 +--
lib/ext/Roundcube/rcube_message.php | 105 +-
lib/ext/Roundcube/rcube_mime.php | 30
lib/ext/Roundcube/rcube_plugin.php | 2
lib/ext/Roundcube/rcube_plugin_api.php | 4
lib/ext/Roundcube/rcube_result_set.php | 47
lib/ext/Roundcube/rcube_session.php | 58 +
lib/ext/Roundcube/rcube_spellchecker.php | 2
lib/ext/Roundcube/rcube_storage.php | 5
lib/ext/Roundcube/rcube_utils.php | 2
lib/ext/Roundcube/rcube_vcard.php | 2
lib/ext/Roundcube/rcube_washtml.php | 3
lib/ext/Syncroton/Model/Event.php | 35
lib/ext/Syncroton/Model/EventException.php | 3
lib/ext/tnef_decoder.php | 11
lib/kolab_sync.php | 7
lib/kolab_sync_data.php | 112 +-
lib/kolab_sync_data_calendar.php | 77 -
lib/kolab_sync_data_email.php | 2
lib/kolab_sync_data_tasks.php | 11
lib/plugins/kolab_auth/config.inc.php.dist | 5
lib/plugins/kolab_auth/kolab_auth.php | 103 +-
lib/plugins/kolab_auth/localization/es_ES.inc | 5
lib/plugins/kolab_auth/localization/et_EE.inc | 5
lib/plugins/kolab_auth/localization/fr_FR.inc | 5
lib/plugins/kolab_auth/localization/ja_JP.inc | 5
lib/plugins/kolab_auth/localization/nl_NL.inc | 5
lib/plugins/kolab_auth/localization/ru_RU.inc | 5
lib/plugins/kolab_auth/package.xml | 4
lib/plugins/kolab_folders/config.inc.php.dist | 4
lib/plugins/kolab_folders/kolab_folders.php | 109 --
lib/plugins/kolab_folders/localization/en_US.inc | 2
lib/plugins/kolab_folders/localization/es_ES.inc | 26
lib/plugins/kolab_folders/localization/et_EE.inc | 26
lib/plugins/kolab_folders/localization/fr_FR.inc | 26
lib/plugins/kolab_folders/localization/ja_JP.inc | 26
lib/plugins/kolab_folders/localization/nl_NL.inc | 26
lib/plugins/kolab_folders/localization/pl_PL.inc | 2
lib/plugins/kolab_folders/localization/ru_RU.inc | 26
lib/plugins/kolab_folders/package.xml | 4
lib/plugins/libkolab/LICENSE | 661 +++++++++++++
lib/plugins/libkolab/README | 21
lib/plugins/libkolab/SQL/mysql.initial.sql | 27
lib/plugins/libkolab/SQL/mysql.sql | 25
lib/plugins/libkolab/SQL/mysql/2013011000.sql | 1
lib/plugins/libkolab/UPGRADING | 9
lib/plugins/libkolab/config.inc.php.dist | 21
lib/plugins/libkolab/lib/kolab_date_recurrence.php | 109 --
lib/plugins/libkolab/lib/kolab_format.php | 176 +++
lib/plugins/libkolab/lib/kolab_format_configuration.php | 33
lib/plugins/libkolab/lib/kolab_format_contact.php | 136 --
lib/plugins/libkolab/lib/kolab_format_distributionlist.php | 58 -
lib/plugins/libkolab/lib/kolab_format_event.php | 256 ++---
lib/plugins/libkolab/lib/kolab_format_file.php | 162 +++
lib/plugins/libkolab/lib/kolab_format_journal.php | 52 -
lib/plugins/libkolab/lib/kolab_format_note.php | 51 -
lib/plugins/libkolab/lib/kolab_format_task.php | 34
lib/plugins/libkolab/lib/kolab_format_xcal.php | 40
lib/plugins/libkolab/lib/kolab_storage.php | 222 ++++
lib/plugins/libkolab/lib/kolab_storage_cache.php | 21
lib/plugins/libkolab/lib/kolab_storage_folder.php | 413 ++++++--
lib/plugins/libkolab/libkolab.php | 15
lib/plugins/libkolab/package.xml | 100 +
tests/data.php | 12
78 files changed, 2911 insertions(+), 1231 deletions(-)
New commits:
commit 502e6ee8414494fd47d3cc72538b9df196e4f555
Author: Aleksander Machniak <alec at alec.pl>
Date: Thu Mar 28 18:14:12 2013 +0100
Support recurrence exceptions (Bug #1498)
diff --git a/lib/ext/Syncroton/Model/Event.php b/lib/ext/Syncroton/Model/Event.php
index 84fec18..08dc9c5 100644
--- a/lib/ext/Syncroton/Model/Event.php
+++ b/lib/ext/Syncroton/Model/Event.php
@@ -98,15 +98,30 @@ class Syncroton_Model_Event extends Syncroton_Model_AXMLEntry
if ($exception->deleted == 1) {
continue;
}
-
- $parentFields = array('allDayEvent', 'attendees', 'busyStatus', 'meetingStatus', 'sensitivity', 'subject');
-
- foreach ($parentFields as $field) {
- if (!isset($exception->$field) && isset($this->_elements[$field])) {
- $exception->$field = $this->_elements[$field];
- }
- }
- }
- }
+
+ $parentFields = array(
+ 'allDayEvent',
+ 'attendees',
+ 'busyStatus',
+ 'meetingStatus',
+ 'sensitivity',
+ 'subject',
+ 'body',
+ 'location',
+ 'reminder'
+ );
+
+ foreach ($parentFields as $field) {
+ if (isset($this->_elements[$field])) {
+ if (!isset($exception->$field)) {
+ $exception->$field = $this->_elements[$field];
+ }
+ else if ($exception->$field == $this->_elements[$field]) {
+ unset($exception->$field);
+ }
+ }
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/lib/ext/Syncroton/Model/EventException.php b/lib/ext/Syncroton/Model/EventException.php
index 0dab808..4c6361c 100644
--- a/lib/ext/Syncroton/Model/EventException.php
+++ b/lib/ext/Syncroton/Model/EventException.php
@@ -27,6 +27,9 @@ class Syncroton_Model_EventException extends Syncroton_Model_AXMLEntry
protected $_dateTimeFormat = "Ymd\THis\Z";
protected $_properties = array(
+ 'AirSyncBase' => array(
+ 'body' => array('type' => 'container', 'class' => 'Syncroton_Model_EmailBody')
+ ),
'Calendar' => array(
'allDayEvent' => array('type' => 'number'),
'appointmentReplyTime' => array('type' => 'datetime'),
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index f70b19a..c9ccdc9 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -43,7 +43,7 @@ class kolab_sync extends rcube
public $user;
const CHARSET = 'UTF-8';
- const VERSION = "2.1";
+ const VERSION = "2.2";
/**
diff --git a/lib/kolab_sync_data.php b/lib/kolab_sync_data.php
index 43371bc..96ab79e 100644
--- a/lib/kolab_sync_data.php
+++ b/lib/kolab_sync_data.php
@@ -728,6 +728,9 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
$folder = $this->getFolderObject($object['_mailbox']);
return $folder && $folder->delete($entryid);
}
+
+ // object doesn't exist, confirm deletion
+ return true;
}
/**
@@ -1043,10 +1046,10 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
/**
* Convert Kolab event/task recurrence into ActiveSync
*/
- protected function recurrence_from_kolab($data, $type = 'Event')
+ protected function recurrence_from_kolab($collection, $data, &$result, $type = 'Event')
{
if (empty($data['recurrence'])) {
- return null;
+ return;
}
$recurrence = array();
@@ -1114,7 +1117,7 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
$recurrence['interval'] = $r['INTERVAL'] ? $r['INTERVAL'] : 1;
if (!empty($r['UNTIL'])) {
- $recurrence['until'] = $this->date_from_kolab($r['UNTIL']);
+ $recurrence['until'] = self::date_from_kolab($r['UNTIL']);
}
else if (!empty($r['COUNT'])) {
$recurrence['occurrences'] = $r['COUNT'];
@@ -1122,19 +1125,25 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
$class = 'Syncroton_Model_' . $type . 'Recurrence';
- return new $class($recurrence);
+ $result['recurrence'] = new $class($recurrence);
+
+ // Tasks do not support exceptions
+ if ($type == 'Event') {
+ $result['exceptions'] = $this->exceptions_from_kolab($collection, $data, $result);
+ }
}
/**
* Convert ActiveSync event/task recurrence into Kolab
*/
- protected function recurrence_to_kolab($recurrence, $timezone = null)
+ protected function recurrence_to_kolab($data, $folderid, $timezone = null)
{
- if (!($recurrence instanceof Syncroton_Model_EventRecurrence) || !isset($recurrence->type)) {
+ if (!($data->recurrence instanceof Syncroton_Model_EventRecurrence) || !isset($data->recurrence->type)) {
return null;
}
- $type = $recurrence->type;
+ $recurrence = $data->recurrence;
+ $type = $recurrence->type;
switch ($type) {
case self::RECUR_TYPE_DAILY:
@@ -1187,72 +1196,95 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
$rrule['COUNT'] = $recurrence->occurrences;
}
+ // recurrence exceptions (not supported by Tasks)
+ if ($data instanceof Syncroton_Model_Event) {
+ $this->exceptions_to_kolab($data, $rrule, $folderid, $timezone);
+ }
+
return $rrule;
}
/**
* Convert Kolab event recurrence exceptions into ActiveSync
*/
- protected function exceptions_from_kolab($data, $start_date)
+ protected function exceptions_from_kolab($collection, $data, $result)
{
- if (empty($data['recurrence'])) {
+ if (empty($data['recurrence']['EXCEPTIONS']) && empty($data['recurrence']['EXDATE'])) {
return null;
}
- $rex = (array) $data['recurrence']['EXDATE'];
- $exceptions = array();
+ $ex_list = array();
+
+ // exceptions (modified occurences)
+ foreach ((array)$data['recurrence']['EXCEPTIONS'] as $exception) {
+ $exception['_mailbox'] = $data['_mailbox'];
+ $ex = $this->getEntry($collection, $exception, true);
+
+ $ex['exceptionStartTime'] = clone $ex['startTime'];
+
+ // remove fields not supported by Syncroton_Model_EventException
+ unset($ex['uID']);
+
+ // @TODO: 'thisandfuture=true' is not supported in Activesync
+ // we'd need to slit the event into two separate events
- foreach ($rex as $ex_date) {
- if (!($ex_date instanceof DateTime)) {
+ $ex_list[] = new Syncroton_Model_EventException($ex);
+ }
+
+ // exdate (deleted occurences)
+ foreach ((array)$data['recurrence']['EXDATE'] as $exception) {
+ if (!($exception instanceof DateTime)) {
continue;
}
- $start = clone $ex_date;
- $end = clone $ex_date;
-
- $start->setTime(0, 0, 0);
- $end->setTime(0, 0, 0);
- $end->modify('+1 day');
+ // set event start time to exception date
+ // that can't be any time, tested with Android
+ $hour = $data['_start']->format('H');
+ $minute = $data['_start']->format('i');
+ $second = $data['_start']->format('s');
+ $exception->setTime($hour, $minute, $second);
$ex = array(
- 'exceptionStartTime' => $start_date,
- 'startTime' => self::date_from_kolab($start),
- 'endTime' => self::date_from_kolab($end),
'deleted' => 1,
+ 'exceptionStartTime' => self::date_from_kolab($exception),
);
- if ($data['allday']) {
- $ex['allDayEvent'] = 1;
- }
-
- $exceptions[] = new Syncroton_Model_EventException($ex);
+ $ex_list[] = new Syncroton_Model_EventException($ex);
}
- return $exceptions;
+ return $ex_list;
}
/**
* Convert ActiveSync event recurrence exceptions into Kolab
*/
- protected function exceptions_to_kolab($exceptions, $timezone = null)
+ protected function exceptions_to_kolab($data, &$rrule, $folderid, $timezone = null)
{
- $exdates = array();
+ $rrule['EXDATE'] = array();
+ $rrule['EXCEPTIONS'] = array();
+
// handle exceptions from recurrence
- if (!empty($exceptions)) {
- foreach ($exceptions as $exception) {
- if ($exception->deleted && $exception->startTime) {
- $date = clone $exception->startTime;
- $date->setTimezone($timezone);
+ if (!empty($data->exceptions)) {
+ foreach ($data->exceptions as $exception) {
+ if ($exception->deleted) {
+ $date = clone $exception->exceptionStartTime;
+ if ($timezone) {
+ $date->setTimezone($timezone);
+ }
$date->setTime(0, 0, 0);
- $exdates[] = $date;
+ $rrule['EXDATE'][] = $date;
}
- else {
- // @TODO: handle modification exceptions (that doesn't delete) ?
+ else if (!$exception->deleted) {
+ $ex = $this->toKolab($exception, $folderid, null, $timezone);
+
+ if ($data->allDayEvent) {
+ $ex['allday'] = 1;
+ }
+
+ $rrule['EXCEPTIONS'][] = $ex;
}
}
}
-
- return !empty($exdates) ? $exdates : null;
}
/**
diff --git a/lib/kolab_sync_data_calendar.php b/lib/kolab_sync_data_calendar.php
index f93a91d..e5682d1 100644
--- a/lib/kolab_sync_data_calendar.php
+++ b/lib/kolab_sync_data_calendar.php
@@ -173,8 +173,11 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
*
* @param Syncroton_Model_SyncCollection $collection Collection data
* @param string $serverId Local entry identifier
+ * @param boolean $as_array Return entry as array
+ *
+ * @return array|Syncroton_Model_Event|array Event object
*/
- public function getEntry(Syncroton_Model_SyncCollection $collection, $serverId)
+ public function getEntry(Syncroton_Model_SyncCollection $collection, $serverId, $as_array = false)
{
$event = is_array($serverId) ? $serverId : $this->getObject($collection->collectionId, $serverId);
$config = $this->getFolderConfig($event['_mailbox']);
@@ -217,6 +220,11 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
}
}
+ // set this date for use in exceptions handling
+ if ($name == 'start') {
+ $event['_start'] = $date;
+ }
+
$value = self::date_from_kolab($date);
}
@@ -247,6 +255,9 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
$result['reminder'] = $minutes;
}
+ $result['categories'] = array();
+ $result['attendees'] = array();
+
// Categories, Roundcube Calendar plugin supports only one category at a time
if (!empty($event['categories'])) {
$result['categories'] = (array) $event['categories'];
@@ -272,8 +283,6 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
// Attendees
if (!empty($event['attendees'])) {
- $result['attendees'] = array();
-
foreach ($event['attendees'] as $idx => $attendee) {
$att = array();
@@ -294,26 +303,15 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
$result['attendees'][] = new Syncroton_Model_EventAttendee($att);
}
-/*
- // set own status
- if (($ownAttendee = Calendar_Model_Attender::getOwnAttender($event->attendee)) !== null
- && ($busyType = array_search($ownAttendee->status, $this->_busyStatusMapping)) !== false
- ) {
- $result['BusyStatus'] = $busyType;
- }
-*/
}
// Event meeting status
$result['meetingStatus'] = intval(!empty($result['attendees']));
- // Recurrence
- $result['recurrence'] = $this->recurrence_from_kolab($event);
-
- // Recurrence exceptions
- $result['exceptions'] = $this->exceptions_from_kolab($event, $result['startTime']);
+ // Recurrence (and exceptions)
+ $this->recurrence_from_kolab($collection, $event, $result);
- return new Syncroton_Model_Event($result);
+ return $as_array ? $result : new Syncroton_Model_Event($result);
}
/**
@@ -322,19 +320,21 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
* @param Syncroton_Model_IEntry $data Contact to convert
* @param string $folderid Folder identifier
* @param array $entry Existing entry
+ * @param DateTimeZone $timezone Timezone of the event
*
* @return array
*/
- public function toKolab(Syncroton_Model_IEntry $data, $folderid, $entry = null)
+ public function toKolab(Syncroton_Model_IEntry $data, $folderid, $entry = null, $timezone = null)
{
- $foldername = $this->backend->folder_id2name($folderid, $this->device->deviceid);
- $event = !empty($entry) ? $entry : array();
- $config = $this->getFolderConfig($foldername);
+ $foldername = $this->backend->folder_id2name($folderid, $this->device->deviceid);
+ $event = !empty($entry) ? $entry : array();
+ $config = $this->getFolderConfig($foldername);
+ $is_exception = $data instanceof Syncroton_Model_EventException;
$event['allday'] = 0;
// Timezone
- if (isset($data->timezone)) {
+ if (!$timezone && isset($data->timezone)) {
$tzc = kolab_sync_timezone_converter::getInstance();
$expected = kolab_format::$timezone->getName();
@@ -356,6 +356,12 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
// Calendar namespace fields
foreach ($this->mapping as $key => $name) {
+ // skip UID field, unsupported in event exceptions
+ // we need to do this here, because the next line (data getter) will throw an exception
+ if ($is_exception && $key == 'uID') {
+ continue;
+ }
+
$value = $data->$key;
switch ($name) {
@@ -432,14 +438,16 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
}
// Organizer
- $name = $data->organizerName;
- $email = $data->organizerEmail;
- if ($name || $email) {
- $event['attendees'][] = array(
- 'role' => 'ORGANIZER',
- 'name' => $name,
- 'email' => $email,
- );
+ if (!$is_exception) {
+ $name = $data->organizerName;
+ $email = $data->organizerEmail;
+ if ($name || $email) {
+ $event['attendees'][] = array(
+ 'role' => 'ORGANIZER',
+ 'name' => $name,
+ 'email' => $email,
+ );
+ }
}
// Attendees
@@ -463,12 +471,9 @@ class kolab_sync_data_calendar extends kolab_sync_data implements Syncroton_Data
}
}
- // recurrence
- $event['recurrence'] = $this->recurrence_to_kolab($data->recurrence, $timezone);
-
- // recurrence exceptions
- if ($exdate = $this->exceptions_to_kolab($data->exceptions, $timezone)) {
- $event['recurrence']['EXDATE'] = $exdate;
+ // recurrence (and exceptions)
+ if (!$is_exception) {
+ $event['recurrence'] = $this->recurrence_to_kolab($data, $folderid, $timezone);
}
return $event;
diff --git a/lib/kolab_sync_data_tasks.php b/lib/kolab_sync_data_tasks.php
index 1635545..608c808 100644
--- a/lib/kolab_sync_data_tasks.php
+++ b/lib/kolab_sync_data_tasks.php
@@ -102,8 +102,11 @@ class kolab_sync_data_tasks extends kolab_sync_data
*
* @param Syncroton_Model_SyncCollection $collection Collection data
* @param string $serverId Local entry identifier
+ * @param boolean $as_array Return entry as an array
+ *
+ * @return array|Syncroton_Model_Task|array Task object
*/
- public function getEntry(Syncroton_Model_SyncCollection $collection, $serverId)
+ public function getEntry(Syncroton_Model_SyncCollection $collection, $serverId, $as_array = false)
{
$task = is_array($serverId) ? $serverId : $this->getObject($collection->collectionId, $serverId);
$config = $this->getFolderConfig($task['_mailbox']);
@@ -149,9 +152,9 @@ class kolab_sync_data_tasks extends kolab_sync_data
}
// Recurrence
- $result['recurrence'] = $this->recurrence_from_kolab($task, 'Task');
+ $this->recurrence_from_kolab($collection, $task, $result, 'Task');
- return new Syncroton_Model_Task($result);
+ return $as_array ? $result : new Syncroton_Model_Task($result);
}
/**
@@ -203,7 +206,7 @@ class kolab_sync_data_tasks extends kolab_sync_data
}
// recurrence
- $task['recurrence'] = $this->recurrence_to_kolab($data->recurrence);
+ $task['recurrence'] = $this->recurrence_to_kolab($data, $folderid, null);
return $task;
}
diff --git a/tests/data.php b/tests/data.php
index 38e488a..e837022 100644
--- a/tests/data.php
+++ b/tests/data.php
@@ -22,7 +22,7 @@ class data extends PHPUnit_Framework_TestCase
$event = new Syncroton_Model_Event($xml->ApplicationData);
$data = new kolab_sync_data_test;
- $result = $data->recurrence_to_kolab($event->recurrence);
+ $result = $data->recurrence_to_kolab($event);
$this->assertEquals('DAILY', $result['FREQ']);
$this->assertEquals(1, $result['INTERVAL']);
@@ -42,7 +42,7 @@ class data extends PHPUnit_Framework_TestCase
$xml = new SimpleXMLElement($xml);
$event = new Syncroton_Model_Event($xml->ApplicationData);
- $result = $data->recurrence_to_kolab($event->recurrence);
+ $result = $data->recurrence_to_kolab($event, null);
$this->assertEquals('WEEKLY', $result['FREQ']);
$this->assertEquals(1, $result['INTERVAL']);
@@ -59,16 +59,16 @@ class kolab_sync_data_test extends kolab_sync_data
{
}
- public function recurrence_to_kolab($data, $timezone = null)
+ public function recurrence_to_kolab($data)
{
- return parent::recurrence_to_kolab($data, $timezone);
+ return parent::recurrence_to_kolab($data, null);
}
- function toKolab(Syncroton_Model_IEntry $data, $folderId, $entry = null)
+ function toKolab(Syncroton_Model_IEntry $data, $folderId, $entry = null, $timezone = null)
{
}
- function getEntry(Syncroton_Model_SyncCollection $collection, $serverId)
+ function getEntry(Syncroton_Model_SyncCollection $collection, $serverId, $as_array = false)
{
}
}
commit b759cd4a15b8dfb461c060afce215184f83f34e6
Author: Aleksander Machniak <alec at alec.pl>
Date: Thu Mar 28 14:25:41 2013 +0100
Fix logging PHP errors/warnings to the user log
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index 66e4de6..f70b19a 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -350,6 +350,11 @@ class kolab_sync extends rcube
}
$this->config->set('log_dir', $log_dir);
+
+ // re-set PHP error logging
+ if (($this->config->get('debug_level') & 1) && $this->config->get('log_driver') != 'syslog') {
+ ini_set('error_log', $log_dir . '/errors');
+ }
}
commit bc3aba8969828df412800d44bc37b05d1570e334
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun Mar 17 11:17:20 2013 +0100
Update plugins
diff --git a/lib/plugins/kolab_auth/localization/es_ES.inc b/lib/plugins/kolab_auth/localization/es_ES.inc
new file mode 100644
index 0000000..e1adb3f
--- /dev/null
+++ b/lib/plugins/kolab_auth/localization/es_ES.inc
@@ -0,0 +1,5 @@
+<?php
+
+$labels['loginas'] = 'Login As';
+
+?>
diff --git a/lib/plugins/kolab_auth/localization/et_EE.inc b/lib/plugins/kolab_auth/localization/et_EE.inc
new file mode 100644
index 0000000..e1adb3f
--- /dev/null
+++ b/lib/plugins/kolab_auth/localization/et_EE.inc
@@ -0,0 +1,5 @@
+<?php
+
+$labels['loginas'] = 'Login As';
+
+?>
diff --git a/lib/plugins/kolab_auth/localization/fr_FR.inc b/lib/plugins/kolab_auth/localization/fr_FR.inc
new file mode 100644
index 0000000..a25707f
--- /dev/null
+++ b/lib/plugins/kolab_auth/localization/fr_FR.inc
@@ -0,0 +1,5 @@
+<?php
+
+$labels['loginas'] = 'Se connecter en tant que';
+
+?>
diff --git a/lib/plugins/kolab_auth/localization/ja_JP.inc b/lib/plugins/kolab_auth/localization/ja_JP.inc
new file mode 100644
index 0000000..e1adb3f
--- /dev/null
+++ b/lib/plugins/kolab_auth/localization/ja_JP.inc
@@ -0,0 +1,5 @@
+<?php
+
+$labels['loginas'] = 'Login As';
+
+?>
diff --git a/lib/plugins/kolab_auth/localization/nl_NL.inc b/lib/plugins/kolab_auth/localization/nl_NL.inc
new file mode 100644
index 0000000..935b1cf
--- /dev/null
+++ b/lib/plugins/kolab_auth/localization/nl_NL.inc
@@ -0,0 +1,5 @@
+<?php
+
+$labels['loginas'] = 'Log in als';
+
+?>
diff --git a/lib/plugins/kolab_auth/localization/ru_RU.inc b/lib/plugins/kolab_auth/localization/ru_RU.inc
new file mode 100644
index 0000000..61ebc59
--- /dev/null
+++ b/lib/plugins/kolab_auth/localization/ru_RU.inc
@@ -0,0 +1,5 @@
+<?php
+
+$labels['loginas'] = 'ÐойÑи как';
+
+?>
diff --git a/lib/plugins/kolab_folders/localization/es_ES.inc b/lib/plugins/kolab_folders/localization/es_ES.inc
new file mode 100644
index 0000000..0481d09
--- /dev/null
+++ b/lib/plugins/kolab_folders/localization/es_ES.inc
@@ -0,0 +1,26 @@
+<?php
+
+$labels = array();
+
+$labels['folderctype'] = 'Content type';
+$labels['foldertypemail'] = 'Mail';
+$labels['foldertypeevent'] = 'Calendar'; // Events?
+$labels['foldertypejournal'] = 'Journal';
+$labels['foldertypetask'] = 'Tareas';
+$labels['foldertypenote'] = 'Notas';
+$labels['foldertypecontact'] = 'Contactos';
+$labels['foldertypeconfiguration'] = 'Configuración';
+$labels['foldertypefile'] = 'Files';
+$labels['foldertypefreebusy'] = 'Free-Busy';
+
+$labels['default'] = 'Default';
+$labels['inbox'] = 'Inbox';
+$labels['drafts'] = 'Drafts';
+$labels['sentitems'] = 'Sent';
+$labels['outbox'] = 'Outbox';
+$labels['wastebasket'] = 'Trash';
+$labels['junkemail'] = 'Junk';
+
+$messages['defaultfolderexists'] = 'There is already default folder of specified type';
+
+?>
diff --git a/lib/plugins/kolab_folders/localization/et_EE.inc b/lib/plugins/kolab_folders/localization/et_EE.inc
new file mode 100644
index 0000000..856f59d
--- /dev/null
+++ b/lib/plugins/kolab_folders/localization/et_EE.inc
@@ -0,0 +1,26 @@
+<?php
+
+$labels = array();
+
+$labels['folderctype'] = 'Content type';
+$labels['foldertypemail'] = 'Mail';
+$labels['foldertypeevent'] = 'Calendar'; // Events?
+$labels['foldertypejournal'] = 'Journal';
+$labels['foldertypetask'] = 'Tasks';
+$labels['foldertypenote'] = 'Notes';
+$labels['foldertypecontact'] = 'Contacts';
+$labels['foldertypeconfiguration'] = 'Configuration';
+$labels['foldertypefile'] = 'Files';
+$labels['foldertypefreebusy'] = 'Free-Busy';
+
+$labels['default'] = 'Default';
+$labels['inbox'] = 'Inbox';
+$labels['drafts'] = 'Drafts';
+$labels['sentitems'] = 'Sent';
+$labels['outbox'] = 'Outbox';
+$labels['wastebasket'] = 'Trash';
+$labels['junkemail'] = 'Junk';
+
+$messages['defaultfolderexists'] = 'There is already default folder of specified type';
+
+?>
diff --git a/lib/plugins/kolab_folders/localization/fr_FR.inc b/lib/plugins/kolab_folders/localization/fr_FR.inc
new file mode 100644
index 0000000..19e03e7
--- /dev/null
+++ b/lib/plugins/kolab_folders/localization/fr_FR.inc
@@ -0,0 +1,26 @@
+<?php
+
+$labels = array();
+
+$labels['folderctype'] = 'Type de contenu';
+$labels['foldertypemail'] = 'Courriel';
+$labels['foldertypeevent'] = 'Calendrier'; // Events?
+$labels['foldertypejournal'] = 'Journal';
+$labels['foldertypetask'] = 'Tâches';
+$labels['foldertypenote'] = 'Notes';
+$labels['foldertypecontact'] = 'Contacts';
+$labels['foldertypeconfiguration'] = 'Configuration';
+$labels['foldertypefile'] = 'Fichiers';
+$labels['foldertypefreebusy'] = 'Disponible/Occupé';
+
+$labels['default'] = 'Par Défaut';
+$labels['inbox'] = 'Courrier entrant';
+$labels['drafts'] = 'Brouillons';
+$labels['sentitems'] = 'Envoyés';
+$labels['outbox'] = 'Courrier sortant';
+$labels['wastebasket'] = 'Corbeille';
+$labels['junkemail'] = 'Indésirables';
+
+$messages['defaultfolderexists'] = 'Il existe déjà un répertoire par défaut pour le type spécifié';
+
+?>
diff --git a/lib/plugins/kolab_folders/localization/ja_JP.inc b/lib/plugins/kolab_folders/localization/ja_JP.inc
new file mode 100644
index 0000000..3bba3ed
--- /dev/null
+++ b/lib/plugins/kolab_folders/localization/ja_JP.inc
@@ -0,0 +1,26 @@
+<?php
+
+$labels = array();
+
+$labels['folderctype'] = 'Content type';
+$labels['foldertypemail'] = 'Mail';
+$labels['foldertypeevent'] = 'Calendar'; // Events?
+$labels['foldertypejournal'] = 'Journal';
+$labels['foldertypetask'] = 'Tasks';
+$labels['foldertypenote'] = 'Notes';
+$labels['foldertypecontact'] = 'Contacts';
+$labels['foldertypeconfiguration'] = 'è¨å®';
+$labels['foldertypefile'] = 'Files';
+$labels['foldertypefreebusy'] = 'Free-Busy';
+
+$labels['default'] = 'Default';
+$labels['inbox'] = 'Inbox';
+$labels['drafts'] = 'Drafts';
+$labels['sentitems'] = 'Sent';
+$labels['outbox'] = 'Outbox';
+$labels['wastebasket'] = 'Trash';
+$labels['junkemail'] = 'Junk';
+
+$messages['defaultfolderexists'] = 'There is already default folder of specified type';
+
+?>
diff --git a/lib/plugins/kolab_folders/localization/nl_NL.inc b/lib/plugins/kolab_folders/localization/nl_NL.inc
new file mode 100644
index 0000000..3011279
--- /dev/null
+++ b/lib/plugins/kolab_folders/localization/nl_NL.inc
@@ -0,0 +1,26 @@
+<?php
+
+$labels = array();
+
+$labels['folderctype'] = 'Inhoudstype';
+$labels['foldertypemail'] = 'Mail';
+$labels['foldertypeevent'] = 'Agenda'; // Events?
+$labels['foldertypejournal'] = 'Dagboek';
+$labels['foldertypetask'] = 'Taken';
+$labels['foldertypenote'] = 'Notities';
+$labels['foldertypecontact'] = 'Adresboek';
+$labels['foldertypeconfiguration'] = 'Configuratie';
+$labels['foldertypefile'] = 'Bestanden';
+$labels['foldertypefreebusy'] = 'Free/Busy';
+
+$labels['default'] = 'Standaard';
+$labels['inbox'] = 'Inbox';
+$labels['drafts'] = 'Concepten';
+$labels['sentitems'] = 'Verzonden';
+$labels['outbox'] = 'Te versturen';
+$labels['wastebasket'] = 'Prullenbak';
+$labels['junkemail'] = 'Ongewenst';
+
+$messages['defaultfolderexists'] = 'Er is reeds een standaard map voor dit type inhoud';
+
+?>
diff --git a/lib/plugins/kolab_folders/localization/ru_RU.inc b/lib/plugins/kolab_folders/localization/ru_RU.inc
new file mode 100644
index 0000000..e9878ba
--- /dev/null
+++ b/lib/plugins/kolab_folders/localization/ru_RU.inc
@@ -0,0 +1,26 @@
+<?php
+
+$labels = array();
+
+$labels['folderctype'] = 'Тип ÑÑика';
+$labels['foldertypemail'] = 'ÐоÑÑа';
+$labels['foldertypeevent'] = 'ÐалендаÑÑ'; // Events?
+$labels['foldertypejournal'] = 'ÐÑÑнал';
+$labels['foldertypetask'] = 'ÐадаÑи';
+$labels['foldertypenote'] = 'ÐамеÑки';
+$labels['foldertypecontact'] = 'ÐонÑакÑÑ';
+$labels['foldertypeconfiguration'] = 'ÐаÑÑÑойки';
+$labels['foldertypefile'] = 'ФайлÑ';
+$labels['foldertypefreebusy'] = 'ÐанÑÑ/Свободен';
+
+$labels['default'] = 'Ðо ÑмолÑаниÑ';
+$labels['inbox'] = 'ÐÑ
одÑÑие';
+$labels['drafts'] = 'ЧеÑновики';
+$labels['sentitems'] = 'ÐÑпÑавленнÑе';
+$labels['outbox'] = 'ÐÑÑ
одÑÑие';
+$labels['wastebasket'] = 'ÐоÑзина';
+$labels['junkemail'] = 'Спам';
+
+$messages['defaultfolderexists'] = 'Уже назнаÑен ÑÑик по ÑмолÑÐ°Ð½Ð¸Ñ Ð´Ð»Ñ Ñказанного Ñипа';
+
+?>
diff --git a/lib/plugins/libkolab/LICENSE b/lib/plugins/libkolab/LICENSE
new file mode 100644
index 0000000..dba13ed
--- /dev/null
+++ b/lib/plugins/libkolab/LICENSE
@@ -0,0 +1,661 @@
+ GNU AFFERO GENERAL PUBLIC LICENSE
+ Version 3, 19 November 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU Affero General Public License is a free, copyleft license for
+software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+our General Public Licenses are intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.
+
+ A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate. Many developers of free software are heartened and
+encouraged by the resulting cooperation. However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.
+
+ The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community. It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server. Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.
+
+ An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals. This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU Affero General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Remote Network Interaction; Use with the GNU General Public License.
+
+ Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software. This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the work with which it is combined will remain governed by version
+3 of the GNU General Public License.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time. Such new versions
+will be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU Affero General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU Affero General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source. For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code. There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+<http://www.gnu.org/licenses/>.
diff --git a/lib/plugins/libkolab/SQL/mysql.initial.sql b/lib/plugins/libkolab/SQL/mysql.initial.sql
new file mode 100644
index 0000000..8603bc8
--- /dev/null
+++ b/lib/plugins/libkolab/SQL/mysql.initial.sql
@@ -0,0 +1,27 @@
+/**
+ * libkolab database schema
+ *
+ * @version @package_version@
+ * @author Thomas Bruederli
+ * @licence GNU AGPL
+ **/
+
+DROP TABLE IF EXISTS `kolab_cache`;
+
+CREATE TABLE `kolab_cache` (
+ `resource` VARCHAR(255) CHARACTER SET ascii NOT NULL,
+ `type` VARCHAR(32) CHARACTER SET ascii NOT NULL,
+ `msguid` BIGINT UNSIGNED NOT NULL,
+ `uid` VARCHAR(128) CHARACTER SET ascii NOT NULL,
+ `created` DATETIME DEFAULT NULL,
+ `changed` DATETIME DEFAULT NULL,
+ `data` TEXT NOT NULL,
+ `xml` TEXT NOT NULL,
+ `dtstart` DATETIME,
+ `dtend` DATETIME,
+ `tags` VARCHAR(255) NOT NULL,
+ `words` TEXT NOT NULL,
+ PRIMARY KEY(`resource`,`type`,`msguid`)
+) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
+
+INSERT INTO `system` (`name`, `value`) VALUES ('libkolab-version', '2013011000');
diff --git a/lib/plugins/libkolab/SQL/mysql.sql b/lib/plugins/libkolab/SQL/mysql.sql
deleted file mode 100644
index 244ab3d..0000000
--- a/lib/plugins/libkolab/SQL/mysql.sql
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * libkolab database schema
- *
- * @version @package_version@
- * @author Thomas Bruederli
- * @licence GNU AGPL
- **/
-
-DROP TABLE IF EXISTS `kolab_cache`;
-
-CREATE TABLE `kolab_cache` (
- `resource` VARCHAR(255) CHARACTER SET ascii NOT NULL,
- `type` VARCHAR(32) CHARACTER SET ascii NOT NULL,
- `msguid` BIGINT UNSIGNED NOT NULL,
- `uid` VARCHAR(128) CHARACTER SET ascii NOT NULL,
- `created` DATETIME DEFAULT NULL,
- `changed` DATETIME DEFAULT NULL,
- `data` TEXT NOT NULL,
- `xml` TEXT NOT NULL,
- `dtstart` DATETIME,
- `dtend` DATETIME,
- `tags` VARCHAR(255) NOT NULL,
- `words` TEXT NOT NULL,
- PRIMARY KEY(`resource`,`type`,`msguid`)
-) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
diff --git a/lib/plugins/libkolab/SQL/mysql/2013011000.sql b/lib/plugins/libkolab/SQL/mysql/2013011000.sql
new file mode 100644
index 0000000..fe6741a
--- /dev/null
+++ b/lib/plugins/libkolab/SQL/mysql/2013011000.sql
@@ -0,0 +1 @@
+-- empty
\ No newline at end of file
diff --git a/lib/plugins/libkolab/UPGRADING b/lib/plugins/libkolab/UPGRADING
new file mode 100644
index 0000000..e7f04d8
--- /dev/null
+++ b/lib/plugins/libkolab/UPGRADING
@@ -0,0 +1,9 @@
+UPGRADING instructions
+======================
+
+To update database schema please run in Roundcube bin/ directory:
+
+updatedb.sh --package=libkolab --version=<version> --dir=../plugins/libkolab/SQL
+
+[*] Replace <version> with Roundcube version e.g. 0.7.3
+[*] Roundcube should be upgraded before plugin upgrades
diff --git a/lib/plugins/libkolab/lib/kolab_format_file.php b/lib/plugins/libkolab/lib/kolab_format_file.php
new file mode 100644
index 0000000..191c7fe
--- /dev/null
+++ b/lib/plugins/libkolab/lib/kolab_format_file.php
@@ -0,0 +1,162 @@
+<?php
+
+/**
+ * Kolab File model class
+ *
+ * @version @package_version@
+ * @author Thomas Bruederli <bruederli at kolabsys.com>
+ * @author Aleksander Machniak <machniak at kolabsys.com>
+ *
+ * Copyright (C) 2012, Kolab Systems AG <contact at 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/>.
+ */
+
+class kolab_format_file extends kolab_format
+{
+ public $CTYPE = 'application/x-vnd.kolab.file';
+
+ protected $objclass = 'File';
+ protected $read_func = 'kolabformat::readKolabFile';
+ protected $write_func = 'kolabformat::writeKolabFile';
+
+ protected $sensitivity_map = array(
+ 'public' => kolabformat::ClassPublic,
+ 'private' => kolabformat::ClassPrivate,
+ 'confidential' => kolabformat::ClassConfidential,
+ );
+
+ /**
+ * Set properties to the kolabformat object
+ *
+ * @param array Object data as hash array
+ */
+ public function set(&$object)
+ {
+ // set common object properties
+ parent::set($object);
+
+ $this->obj->setClassification($this->sensitivity_map[$object['sensitivity']]);
+ $this->obj->setCategories(self::array2vector($object['categories']));
+
+ if (isset($object['notes'])) {
+ $this->obj->setNote($object['notes']);
+ }
+
+ // Add file attachment
+ if (!empty($object['_attachments'])) {
+ $cid = key($object['_attachments']);
+ $attach_attr = $object['_attachments'][$cid];
+ $attach = new Attachment;
+
+ $attach->setLabel((string)$attach_attr['name']);
+ $attach->setUri('cid:' . $cid, $attach_attr['mimetype']);
+ $this->obj->setFile($attach);
+
+ // make sure size is set, so object saved in cache contains this info
+ if (!isset($attach_attr['size'])) {
+ if (isset($attach_attr['content'])) {
+ $object['_attachments'][$cid]['size'] = strlen($attach_attr['content']);
+ }
+ else if (isset($attach_attr['path'])) {
+ $object['_attachments'][$cid]['size'] = @filesize($attach_attr['path']);
+ }
+ }
+ }
+
+ // cache this data
+ $this->data = $object;
+ unset($this->data['_formatobj']);
+ }
+
+ /**
+ *
+ */
+ public function is_valid()
+ {
+ return $this->data || (is_object($this->obj) && $this->obj->isValid());
+ }
+
+ /**
+ * Convert the Configuration object into a hash array data structure
+ *
+ * @param array Additional data for merge
+ *
+ * @return array Config object data as hash array
+ */
+ public function to_array($data = array())
+ {
+ // return cached result
+ if (!empty($this->data))
+ return $this->data;
+
+ // read common object props into local data object
+ $object = parent::to_array();
+
+ $sensitivity_map = array_flip($this->sensitivity_map);
+
+ // read object properties
+ $object += array(
+ 'sensitivity' => $sensitivity_map[$this->obj->classification()],
+ 'categories' => self::vector2array($this->obj->categories()),
+ 'notes' => $this->obj->note(),
+ );
+
+ // merge with additional data, e.g. attachments from the message
+ if ($data) {
+ foreach ($data as $idx => $value) {
+ if (is_array($value)) {
+ $object[$idx] = array_merge((array)$object[$idx], $value);
+ }
+ else {
+ $object[$idx] = $value;
+ }
+ }
+ }
+
+ return $this->data = $object;
+ }
+
+ /**
+ * Callback for kolab_storage_cache to get object specific tags to cache
+ *
+ * @return array List of tags to save in cache
+ */
+ public function get_tags()
+ {
+ $tags = array();
+
+ foreach ((array)$this->data['categories'] as $cat) {
+ $tags[] = rcube_utils::normalize_string($cat);
+ }
+
+ return $tags;
+ }
+
+ /**
+ * Callback for kolab_storage_cache to get words to index for fulltext search
+ *
+ * @return array List of words to save in cache
+ */
+ public function get_words()
+ {
+ // Store filename in 'words' for fast access to file by name
+ if (empty($this->data['_attachments'])) {
+ return array();
+ }
+
+ $attachment = array_shift($this->data['_attachments']);
+ return array($attachment['name']);
+ }
+}
diff --git a/lib/plugins/libkolab/package.xml b/lib/plugins/libkolab/package.xml
new file mode 100644
index 0000000..69b2b6f
--- /dev/null
+++ b/lib/plugins/libkolab/package.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.9.0" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+ http://pear.php.net/dtd/tasks-1.0.xsd
+ http://pear.php.net/dtd/package-2.0
+ http://pear.php.net/dtd/package-2.0.xsd">
+ <name>libkolab</name>
+ <uri>http://git.kolab.org/roundcubemail-plugins-kolab/</uri>
+ <summary>Kolab core library</summary>
+ <description>Plugin to setup a basic environment for the interaction with a Kolab server.</description>
+ <lead>
+ <name>Thomas Bruederli</name>
+ <user>bruederli</user>
+ <email>bruederli at kolabsys.com</email>
+ <active>yes</active>
+ </lead>
+ <developer>
+ <name>Alensader Machniak</name>
+ <user>machniak</user>
+ <email>machniak at kolabsys.com</email>
+ <active>yes</active>
+ </developer>
+ <date>2012-11-21</date>
+ <version>
+ <release>0.9-beta</release>
+ <api>0.9-beta</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license uri="http://www.gnu.org/licenses/agpl.html">GNU AGPLv3</license>
+ <notes>-</notes>
+ <contents>
+ <dir baseinstalldir="/" name="/">
+ <file name="libkolab.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format_configuration.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format_contact.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format_distributionlist.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format_event.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format_file.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format_journal.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format_note.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format_task.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_format_xcal.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_storage.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_storage_cache.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_storage_folder.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ <file name="lib/kolab_date_recurrence.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+
+ <file name="bin/modcache.php" role="php"></file>
+
+ <file name="config.inc.php.dist" role="data"></file>
+ <file name="LICENSE" role="data"></file>
+ <file name="README" role="data"></file>
+ </dir>
+ <!-- / -->
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.3.1</min>
+ </php>
+ <pearinstaller>
+ <min>1.7.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease/>
+</package>
commit 564ba16e2b4f92f6b3e8711fc2b623689106df85
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun Mar 17 08:09:37 2013 +0100
Update plugins (with recurrence exceptions support)
diff --git a/lib/plugins/kolab_auth/config.inc.php.dist b/lib/plugins/kolab_auth/config.inc.php.dist
index 6ddfc63..05c610b 100644
--- a/lib/plugins/kolab_auth/config.inc.php.dist
+++ b/lib/plugins/kolab_auth/config.inc.php.dist
@@ -14,8 +14,9 @@ $rcmail_config['kolab_auth_login'] = 'email';
// If the value array contains more than one field, first non-empty will be used
// Note: These aren't LDAP attributes, but field names in config
// Note: If there's more than one email address, as many identities will be created
-$rcmail_config['kolab_auth_name'] = array('name', 'cn');
-$rcmail_config['kolab_auth_email'] = array('email');
+$rcmail_config['kolab_auth_name'] = array('name', 'cn');
+$rcmail_config['kolab_auth_email'] = array('email');
+$rcmail_config['kolab_auth_organization'] = array('organization');
// Login and password of the admin user. Enables "Login As" feature.
$rcmail_config['kolab_auth_admin_login'] = '';
diff --git a/lib/plugins/kolab_auth/kolab_auth.php b/lib/plugins/kolab_auth/kolab_auth.php
index 620def5..719df98 100644
--- a/lib/plugins/kolab_auth/kolab_auth.php
+++ b/lib/plugins/kolab_auth/kolab_auth.php
@@ -12,7 +12,7 @@
* @version @package_version@
* @author Aleksander Machniak <machniak at kolabsys.com>
*
- * Copyright (C) 2011, Kolab Systems AG <contact at kolabsys.com>
+ * Copyright (C) 2011-2012, Kolab Systems AG <contact at 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
@@ -30,7 +30,7 @@
class kolab_auth extends rcube_plugin
{
- private $ldap;
+ static $ldap;
private $data = array();
public function init()
@@ -208,7 +208,19 @@ class kolab_auth extends rcube_plugin
if (!empty($this->data['user_email'])) {
// addresses list is supported
if (array_key_exists('email_list', $args)) {
- $args['email_list'] = array_unique($this->data['user_email']);
+ $email_list = array_unique($this->data['user_email']);
+
+ // add organization to the list
+ if (!empty($this->data['user_organization'])) {
+ foreach ($email_list as $idx => $email) {
+ $email_list[$idx] = array(
+ 'organization' => $this->data['user_organization'],
+ 'email' => $email,
+ );
+ }
+ }
+
+ $args['email_list'] = $email_list;
}
else {
$args['user_email'] = $this->data['user_email'][0];
@@ -256,22 +268,8 @@ class kolab_auth extends rcube_plugin
*/
public function authenticate($args)
{
- $this->load_config();
-
- if (!$this->init_ldap()) {
- $args['abort'] = true;
- return $args;
- }
-
- $rcmail = rcube::get_instance();
- $admin_login = $rcmail->config->get('kolab_auth_admin_login');
- $admin_pass = $rcmail->config->get('kolab_auth_admin_password');
- $login_attr = $rcmail->config->get('kolab_auth_login');
- $name_attr = $rcmail->config->get('kolab_auth_name');
- $email_attr = $rcmail->config->get('kolab_auth_email');
-
// get username and host
- $host = rcube_utils::parse_host($args['host']);
+ $host = $args['host'];
$user = $args['user'];
$pass = $args['pass'];
$loginas = trim(rcube_utils::get_input_value('_loginas', rcube_utils::INPUT_POST));
@@ -281,6 +279,12 @@ class kolab_auth extends rcube_plugin
return $args;
}
+ $ldap = self::ldap();
+ if (!$ldap || !$ldap->ready) {
+ $args['abort'] = true;
+ return $args;
+ }
+
// Find user record in LDAP
$record = $this->get_user_record($user, $host);
@@ -289,7 +293,14 @@ class kolab_auth extends rcube_plugin
return $args;
}
- $role_attr = $rcmail->config->get('kolab_auth_role');
+ $rcmail = rcube::get_instance();
+ $admin_login = $rcmail->config->get('kolab_auth_admin_login');
+ $admin_pass = $rcmail->config->get('kolab_auth_admin_password');
+ $login_attr = $rcmail->config->get('kolab_auth_login');
+ $name_attr = $rcmail->config->get('kolab_auth_name');
+ $email_attr = $rcmail->config->get('kolab_auth_email');
+ $org_attr = $rcmail->config->get('kolab_auth_organization');
+ $role_attr = $rcmail->config->get('kolab_auth_role');
if (!empty($role_attr) && !empty($record[$role_attr])) {
$_SESSION['user_roledns'] = (array)($record[$role_attr]);
@@ -298,10 +309,11 @@ class kolab_auth extends rcube_plugin
// Login As...
if (!empty($loginas) && $admin_login) {
// Authenticate to LDAP
- $dn = $this->ldap->dn_decode($record['ID']);
- $result = $this->ldap->bind($dn, $pass);
+ $dn = rcube_ldap::dn_decode($record['ID']);
+ $result = $ldap->bind($dn, $pass);
if (!$result) {
+ $args['abort'] = true;
return $args;
}
@@ -324,9 +336,9 @@ class kolab_auth extends rcube_plugin
// check group
if (!$isadmin && !empty($group)) {
- $groups = $this->ldap->get_record_groups($record['ID']);
- foreach ($groups as $g) {
- if ($group == $this->ldap->dn_decode($g)) {
+ $groups = $ldap->get_record_groups($record['ID']);
+ foreach ($groups as $g => $prop) {
+ if ($group == rcube_ldap::dn_decode($g)) {
$isadmin = true;
break;
}
@@ -362,8 +374,9 @@ class kolab_auth extends rcube_plugin
$_SESSION['kolab_auth_password'] = $rcmail->encrypt($admin_pass);
}
- // Store UID in session for use by other plugins
+ // Store UID and DN of logged user in session for use by other plugins
$_SESSION['kolab_uid'] = is_array($record['uid']) ? $record['uid'][0] : $record['uid'];
+ $_SESSION['kolab_dn'] = $record['ID']; // encoded
// Set user login
if ($login_attr) {
@@ -388,6 +401,14 @@ class kolab_auth extends rcube_plugin
$this->data['user_email'] = array_merge((array)$this->data['user_email'], (array)$email);
}
}
+ // Organization name for identity (first log in)
+ foreach ((array)$org_attr as $field) {
+ $organization = is_array($record[$field]) ? $record[$field][0] : $record[$field];
+ if (!empty($organization)) {
+ $this->data['user_organization'] = $organization;
+ break;
+ }
+ }
// Log "Login As" usage
if (!empty($origname)) {
@@ -435,14 +456,24 @@ class kolab_auth extends rcube_plugin
/**
* Initializes LDAP object and connects to LDAP server
*/
- private function init_ldap()
+ public static function ldap()
{
- if ($this->ldap) {
- return $this->ldap->ready;
+ if (self::$ldap) {
+ return self::$ldap;
}
$rcmail = rcube::get_instance();
+ // $this->load_config();
+ // we're in static method, load config manually
+ $fpath = $rcmail->plugins->dir . '/kolab_auth/config.inc.php';
+ if (is_file($fpath) && !$rcmail->config->load_from_file($fpath)) {
+ rcube::raise_error(array(
+ 'code' => 527, 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Failed to load config from $fpath"), true, false);
+ }
+
$addressbook = $rcmail->config->get('kolab_auth_addressbook');
if (!is_array($addressbook)) {
@@ -451,16 +482,18 @@ class kolab_auth extends rcube_plugin
}
if (empty($addressbook)) {
- return false;
+ return null;
}
- $this->ldap = new kolab_auth_ldap_backend(
+ self::$ldap = new kolab_auth_ldap_backend(
$addressbook,
$rcmail->config->get('ldap_debug'),
$rcmail->config->mail_domain($_SESSION['imap_host'])
);
- return $this->ldap->ready;
+ $rcmail->add_shutdown_function(array(self::$ldap, 'close'));
+
+ return self::$ldap;
}
/**
@@ -470,15 +503,15 @@ class kolab_auth extends rcube_plugin
{
$rcmail = rcube::get_instance();
$filter = $rcmail->config->get('kolab_auth_filter');
-
$filter = $this->parse_vars($filter, $user, $host);
+ $ldap = self::ldap();
// reset old result
- $this->ldap->reset();
+ $ldap->reset();
// get record
- $this->ldap->set_filter($filter);
- $results = $this->ldap->list_records();
+ $ldap->set_filter($filter);
+ $results = $ldap->list_records();
if (count($results->records) == 1) {
return $results->records[0];
diff --git a/lib/plugins/kolab_auth/package.xml b/lib/plugins/kolab_auth/package.xml
index 6200c4c..2d75d83 100644
--- a/lib/plugins/kolab_auth/package.xml
+++ b/lib/plugins/kolab_auth/package.xml
@@ -18,9 +18,9 @@
<email>machniak at kolabsys.com</email>
<active>yes</active>
</lead>
- <date>2012-10-08</date>
+ <date>2012-12-19</date>
<version>
- <release>0.4</release>
+ <release>0.6</release>
<api>0.1</api>
</version>
<stability>
diff --git a/lib/plugins/kolab_folders/config.inc.php.dist b/lib/plugins/kolab_folders/config.inc.php.dist
index e393684..ffa1e15 100644
--- a/lib/plugins/kolab_folders/config.inc.php.dist
+++ b/lib/plugins/kolab_folders/config.inc.php.dist
@@ -18,6 +18,10 @@ $rcmail_config['kolab_folders_task_default'] = '';
$rcmail_config['kolab_folders_note_default'] = '';
// Default Journal folder
$rcmail_config['kolab_folders_journal_default'] = '';
+// Default Files folder
+$rcmail_config['kolab_folders_file_default'] = '';
+// Default FreeBusy folder
+$rcmail_config['kolab_folders_freebusy_default'] = '';
// INBOX folder
$rcmail_config['kolab_folders_mail_inbox'] = '';
diff --git a/lib/plugins/kolab_folders/kolab_folders.php b/lib/plugins/kolab_folders/kolab_folders.php
index 3688624..a45c108 100644
--- a/lib/plugins/kolab_folders/kolab_folders.php
+++ b/lib/plugins/kolab_folders/kolab_folders.php
@@ -26,7 +26,7 @@ class kolab_folders extends rcube_plugin
{
public $task = '?(?!login).*';
- public $types = array('mail', 'event', 'journal', 'task', 'note', 'contact', 'configuration');
+ public $types = array('mail', 'event', 'journal', 'task', 'note', 'contact', 'configuration', 'file', 'freebusy');
public $mail_types = array('inbox', 'drafts', 'sentitems', 'outbox', 'wastebasket', 'junkemail');
private $rc;
@@ -337,14 +337,7 @@ class kolab_folders extends rcube_plugin
*/
function get_folder_type($folder)
{
- $storage = $this->rc->get_storage();
- $folderdata = $storage->get_metadata($folder, array(kolab_storage::CTYPE_KEY_PRIVATE, kolab_storage::CTYPE_KEY));
-
- if (!($ctype = $folderdata[$folder][kolab_storage::CTYPE_KEY_PRIVATE])) {
- $ctype = $folderdata[$folder][kolab_storage::CTYPE_KEY];
- }
-
- return explode('.', $ctype);
+ return explode('.', (string)kolab_storage::folder_type($folder));
}
/**
@@ -355,7 +348,7 @@ class kolab_folders extends rcube_plugin
*
* @return boolean True on success
*/
- function set_folder_type($folder, $type='mail')
+ function set_folder_type($folder, $type = 'mail')
{
return kolab_storage::set_folder_type($folder, $type);
}
@@ -376,38 +369,11 @@ class kolab_folders extends rcube_plugin
return null;
}
- $type .= '.default';
- $namespace = $storage->get_namespace();
-
// get all folders of specified type
- $folderdata = array_map(array($this, 'folder_select_metadata'), $folderdata);
- $folderdata = array_intersect($folderdata, array($type));
-
- foreach ($folderdata as $folder => $data) {
- // check if folder is in personal namespace
- foreach (array('shared', 'other') as $nskey) {
- if (!empty($namespace[$nskey])) {
- foreach ($namespace[$nskey] as $ns) {
- if ($ns[0] && substr($folder, 0, strlen($ns[0])) == $ns[0]) {
- continue 3;
- }
- }
- }
- }
+ $folderdata = array_map(array('kolab_storage', 'folder_select_metadata'), $folderdata);
+ $folderdata = array_intersect($folderdata, array($type.'.default'));
- // There can be only one default folder of specified type
- return $folder;
- }
-
- return null;
- }
-
- /**
- * Callback for array_map to select the correct annotation value
- */
- private function folder_select_metadata($types)
- {
- return $types[kolab_storage::CTYPE_KEY_PRIVATE] ?: $types[kolab_storage::CTYPE_KEY];
+ return key($folderdata);
}
/**
@@ -438,25 +404,12 @@ class kolab_folders extends rcube_plugin
$namespace = $storage->get_namespace();
$defaults = array();
$need_update = false;
-
- if (!is_array($folderdata)) {
- $folderdata = $storage->get_metadata('*', kolab_storage::CTYPE_KEY);
-
- if (!is_array($folderdata)) {
- return;
- }
-
- // "Flattenize" metadata array to become a name->type hash
- $folderdata = array_map('implode', $folderdata);
- }
+ $prefix = '';
// Find personal namespace prefix
if (is_array($namespace['personal']) && count($namespace['personal']) == 1) {
$prefix = $namespace['personal'][0][0];
}
- else {
- $prefix = '';
- }
$this->load_config();
@@ -477,45 +430,35 @@ class kolab_folders extends rcube_plugin
}
}
- // find default folders
- foreach ($defaults as $type => $foldername) {
- // folder exists, do nothing
- if (!empty($folderdata[$foldername])) {
- continue;
- }
+ if (empty($defaults)) {
+ return;
+ }
- // special case, need to set type only
- if ($foldername == 'INBOX' || $type == 'mail.inbox') {
- $this->set_folder_type($foldername, 'mail.inbox');
- continue;
+ if (!is_array($folderdata)) {
+ $folderdata = $storage->get_metadata('*', array(kolab_storage::CTYPE_KEY_PRIVATE, kolab_storage::CTYPE_KEY));
+
+ if (!is_array($folderdata)) {
+ return;
}
+ $folderdata = array_map(array('kolab_storage', 'folder_select_metadata'), $folderdata);
+ }
+
+ // find default folders
+ foreach ($defaults as $type => $foldername) {
// get all folders of specified type
- $folders = array_intersect($folderdata, array($type));
- unset($folders[0]);
-
- // find folders in personal namespace
- foreach ($folders as $folder) {
- if ($folder) {
- foreach (array('shared', 'other') as $nskey) {
- if (!empty($namespace[$nskey])) {
- foreach ($namespace[$nskey] as $ns) {
- if ($ns[0] && substr($folder, 0, strlen($ns[0])) == $ns[0]) {
- continue 3;
- }
- }
- }
- }
- }
+ $_folders = array_intersect($folderdata, array($type));
- // got folder in personal namespace
- continue 2;
+ // default folder found
+ if (!empty($_folders)) {
+ continue;
}
list($type1, $type2) = explode('.', $type);
+ $exists = !empty($folderdata[$foldername]) || $foldername == 'INBOX';
// create folder
- if ($type1 != 'mail' || !$storage->folder_exists($foldername)) {
+ if (!$exists && !$storage->folder_exists($foldername)) {
$storage->create_folder($foldername, $type1 == 'mail');
}
diff --git a/lib/plugins/kolab_folders/localization/en_US.inc b/lib/plugins/kolab_folders/localization/en_US.inc
index 70867bc..856f59d 100644
--- a/lib/plugins/kolab_folders/localization/en_US.inc
+++ b/lib/plugins/kolab_folders/localization/en_US.inc
@@ -10,6 +10,8 @@ $labels['foldertypetask'] = 'Tasks';
$labels['foldertypenote'] = 'Notes';
$labels['foldertypecontact'] = 'Contacts';
$labels['foldertypeconfiguration'] = 'Configuration';
+$labels['foldertypefile'] = 'Files';
+$labels['foldertypefreebusy'] = 'Free-Busy';
$labels['default'] = 'Default';
$labels['inbox'] = 'Inbox';
diff --git a/lib/plugins/kolab_folders/localization/pl_PL.inc b/lib/plugins/kolab_folders/localization/pl_PL.inc
index 95177cd..4520dac 100644
--- a/lib/plugins/kolab_folders/localization/pl_PL.inc
+++ b/lib/plugins/kolab_folders/localization/pl_PL.inc
@@ -9,6 +9,8 @@ $labels['foldertypetask'] = 'Zadania';
$labels['foldertypenote'] = 'Notatki';
$labels['foldertypecontact'] = 'Kontakty';
$labels['foldertypeconfiguration'] = 'Konfiguracja';
+$labels['foldertypefile'] = 'Pliki';
+$labels['foldertypefreebusy'] = 'Free-Busy';
$labels['default'] = 'DomyÅlny';
$labels['inbox'] = 'Odebrane';
$labels['drafts'] = 'Szkice';
diff --git a/lib/plugins/kolab_folders/package.xml b/lib/plugins/kolab_folders/package.xml
index 875d614..b40acab 100644
--- a/lib/plugins/kolab_folders/package.xml
+++ b/lib/plugins/kolab_folders/package.xml
@@ -21,9 +21,9 @@
<email>machniak at kolabsys.com</email>
<active>yes</active>
</lead>
- <date>2012-05-14</date>
+ <date>2012-10.25</date>
<version>
- <release>2.0</release>
+ <release>2.1</release>
<api>2.0</api>
</version>
<stability>
diff --git a/lib/plugins/libkolab/README b/lib/plugins/libkolab/README
index 0a3c0ce..2f94839 100644
--- a/lib/plugins/libkolab/README
+++ b/lib/plugins/libkolab/README
@@ -15,29 +15,14 @@ REQUIREMENTS
* PEAR: HTTP/Request2
* PEAR: Net/URL2
-* Optional for old format support:
- Horde Kolab_Format package and all of its dependencies
- which are at least Horde_(Browser,DOM,NLS,String,Utils)
-
INSTALLATION
------------
To use local cache you need to create a dedicated table in Roundcube's database.
-To do so, execute the SQL commands in SQL/<yourdatabase>.sql
+To do so, execute the SQL commands in SQL/<yourdatabase>.initial.sql
CONFIGURATION
-------------
-The following options can be configured in Roundcube's main config file
-or a local config file (config.inc.php) located in the plugin folder.
-
-// Enable caching of Kolab objects in local database
-$rcmail_config['kolab_cache'] = true;
-
-// Optional override of the URL to read and trigger Free/Busy information of Kolab users
-// Defaults to https://<imap-server->/freebusy
-$rcmail_config['kolab_freebusy_server'] = 'https://<some-host>/<freebusy-path>';
-
-// Set this option to disable SSL certificate checks when triggering Free/Busy (enabled by default)
-$rcmail_config['kolab_ssl_verify_peer'] = false;
-
+Rename config.inc.php.dist to config.inc.php in the plugin folder.
+For available configuration options see config.inc.php.dist file.
diff --git a/lib/plugins/libkolab/config.inc.php.dist b/lib/plugins/libkolab/config.inc.php.dist
index fedf793..01e1334 100644
--- a/lib/plugins/libkolab/config.inc.php.dist
+++ b/lib/plugins/libkolab/config.inc.php.dist
@@ -1,9 +1,22 @@
<?php
- /* Configuration for libkolab */
- $rcmail_config['kolab_cache'] = true;
+/* Configuration for libkolab */
- $rcmail_config['kolab_freebusy_server'] = 'https://' . $_SESSION['imap_host'] . '/freebusy';
- $rcmail_config['kolab_ssl_verify_peer'] = true;
+// Enable caching of Kolab objects in local database
+$rcmail_config['kolab_cache'] = true;
+
+// Specify format version to write Kolab objects (must be a string value!)
+$rcmail_config['kolab_format_version'] = '3.0';
+
+// Optional override of the URL to read and trigger Free/Busy information of Kolab users
+// Defaults to https://<imap-server->/freebusy
+$rcmail_config['kolab_freebusy_server'] = 'https://<some-host>/<freebusy-path>';
+
+// Set this option to disable SSL certificate checks when triggering Free/Busy (enabled by default)
+$rcmail_config['kolab_ssl_verify_peer'] = false;
+
+// Enables listing of only subscribed folders. This e.g. will limit
+// folders in calendar view or available addressbooks
+$rcmail_config['kolab_use_subscriptions'] = false;
?>
diff --git a/lib/plugins/libkolab/lib/kolab_date_recurrence.php b/lib/plugins/libkolab/lib/kolab_date_recurrence.php
index 427f62a..3aaa399 100644
--- a/lib/plugins/libkolab/lib/kolab_date_recurrence.php
+++ b/lib/plugins/libkolab/lib/kolab_date_recurrence.php
@@ -3,7 +3,8 @@
/**
* Recurrence computation class for xcal-based Kolab format objects
*
- * Uitility class to compute instances of recurring events.
+ * Utility class to compute instances of recurring events.
+ * It requires the libcalendaring PHP module to be installed and loaded.
*
* @version @package_version@
* @author Thomas Bruederli <bruederli at kolabsys.com>
@@ -25,14 +26,12 @@
*/
class kolab_date_recurrence
{
- private $engine;
- private $object;
- private $next;
- private $duration;
- private $tz_offset = 0;
- private $dst_start = 0;
- private $allday = false;
- private $hour = 0;
+ private /* EventCal */ $engine;
+ private /* kolab_format_xcal */ $object;
+ private /* DateTime */ $start;
+ private /* DateTime */ $next;
+ private /* cDateTime */ $cnext;
+ private /* DateInterval */ $duration;
/**
* Default constructor
@@ -41,27 +40,17 @@ class kolab_date_recurrence
*/
function __construct($object)
{
+ $data = $object->to_array();
+
$this->object = $object;
- $this->next = new Horde_Date($object['start'], kolab_format::$timezone->getName());
+ $this->engine = $object->to_libcal();
+ $this->start = $this->next = $data['start'];
+ $this->cnext = kolab_format::get_datetime($this->next);
- if (is_object($object['start']) && is_object($object['end']))
- $this->duration = $object['start']->diff($object['end']);
+ if (is_object($data['start']) && is_object($data['end']))
+ $this->duration = $data['start']->diff($data['end']);
else
- $this->duration = new DateInterval('PT' . ($object['end'] - $object['start']) . 'S');
-
- // use (copied) Horde classes to compute recurring instances
- // TODO: replace with something that has less than 6'000 lines of code
- $this->engine = new Horde_Date_Recurrence($this->next);
- $this->engine->fromRRule20($this->to_rrule($object['recurrence'])); // TODO: get that string directly from libkolabxml
-
- foreach ((array)$object['recurrence']['EXDATE'] as $exdate)
- $this->engine->addException($exdate->format('Y'), $exdate->format('n'), $exdate->format('j'));
-
- $now = new DateTime('now', kolab_format::$timezone);
- $this->tz_offset = $object['allday'] ? $now->getOffset() - date('Z') : 0;
- $this->dst_start = $this->next->format('I');
- $this->allday = $object['allday'];
- $this->hour = $this->next->hour;
+ $this->duration = new DateInterval('PT' . ($data['end'] - $data['start']) . 'S');
}
/**
@@ -73,20 +62,14 @@ class kolab_date_recurrence
public function next_start($timestamp = false)
{
$time = false;
- if ($this->next && ($next = $this->engine->nextActiveRecurrence(array('year' => $this->next->year, 'month' => $this->next->month, 'mday' => $this->next->mday + 1, 'hour' => $this->next->hour, 'min' => $this->next->min, 'sec' => $this->next->sec)))) {
- if ($this->allday) {
- $next->hour = $this->hour; # fix time for all-day events
- $next->min = 0;
- }
- if ($timestamp) {
- # consider difference in daylight saving between base event and recurring instance
- $dst_diff = ($this->dst_start - $next->format('I')) * 3600;
- $time = $next->timestamp() - $this->tz_offset - $dst_diff;
- }
- else {
- $time = $next->toDateTime();
+
+ if ($this->engine && $this->next) {
+ if (($cnext = new cDateTime($this->engine->getNextOccurence($this->cnext))) && $cnext->isValid()) {
+ $next = kolab_format::php_datetime($cnext);
+ $time = $timestamp ? $next->format('U') : $next;
+ $this->cnext = $cnext;
+ $this->next = $next;
}
- $this->next = $next;
}
return $time;
@@ -103,7 +86,7 @@ class kolab_date_recurrence
$next_end = clone $next_start;
$next_end->add($this->duration);
- $next = $this->object;
+ $next = $this->object->to_array();
$next['recurrence_id'] = $next_start->format('Y-m-d');
$next['start'] = $next_start;
$next['end'] = $next_end;
@@ -123,49 +106,11 @@ class kolab_date_recurrence
*/
public function end($limit = 'now +1 year')
{
- if ($this->object['recurrence']['UNTIL'])
- return $this->object['recurrence']['UNTIL']->format('U');
-
- $limit_time = strtotime($limit);
- while ($next_start = $this->next_start(true)) {
- if ($next_start > $limit_time)
- break;
- }
-
- if ($this->next) {
- $next_end = $this->next->toDateTime();
- $next_end->add($this->duration);
- return $next_end->format('U');
+ $limit_dt = new DateTime($limit);
+ if ($this->engine && ($cend = $this->engine->getLastOccurrence()) && ($end_dt = kolab_format::php_datetime(new cDateTime($cend))) && $end_dt < $limit_dt) {
+ return $end_dt->format('U');
}
return false;
}
-
- /**
- * Convert the internal structured data into a vcalendar RRULE 2.0 string
- */
- private function to_rrule($recurrence)
- {
- if (is_string($recurrence))
- return $recurrence;
-
- $rrule = '';
- foreach ((array)$recurrence as $k => $val) {
- $k = strtoupper($k);
- switch ($k) {
- case 'UNTIL':
- $val = $val->format('Ymd\THis');
- break;
- case 'EXDATE':
- foreach ((array)$val as $i => $ex)
- $val[$i] = $ex->format('Ymd\THis');
- $val = join(',', (array)$val);
- break;
- }
- $rrule .= $k . '=' . $val . ';';
- }
-
- return $rrule;
- }
-
}
diff --git a/lib/plugins/libkolab/lib/kolab_format.php b/lib/plugins/libkolab/lib/kolab_format.php
index 23246d3..809fb29 100644
--- a/lib/plugins/libkolab/lib/kolab_format.php
+++ b/lib/plugins/libkolab/lib/kolab_format.php
@@ -30,40 +30,62 @@ abstract class kolab_format
public static $timezone;
public /*abstract*/ $CTYPE;
+ public /*abstract*/ $CTYPEv2;
+ protected /*abstract*/ $objclass;
protected /*abstract*/ $read_func;
protected /*abstract*/ $write_func;
protected $obj;
protected $data;
protected $xmldata;
+ protected $xmlobject;
protected $loaded = false;
+ protected $version = '3.0';
- const VERSION = '3.0';
const KTYPE_PREFIX = 'application/x-vnd.kolab.';
+ const PRODUCT_ID = 'Roundcube-libkolab-0.9';
/**
- * Factory method to instantiate a kolab_format object of the given type
+ * Factory method to instantiate a kolab_format object of the given type and version
*
* @param string Object type to instantiate
+ * @param float Format version
* @param string Cached xml data to initialize with
* @return object kolab_format
*/
- public static function factory($type, $xmldata = null)
+ public static function factory($type, $version = '3.0', $xmldata = null)
{
if (!isset(self::$timezone))
self::$timezone = new DateTimeZone('UTC');
+ if (!self::supports($version))
+ return PEAR::raiseError("No support for Kolab format version " . $version);
+
$type = preg_replace('/configuration\.[a-z.]+$/', 'configuration', $type);
$suffix = preg_replace('/[^a-z]+/', '', $type);
$classname = 'kolab_format_' . $suffix;
if (class_exists($classname))
- return new $classname($xmldata);
+ return new $classname($xmldata, $version);
return PEAR::raiseError("Failed to load Kolab Format wrapper for type " . $type);
}
/**
+ * Determine support for the given format version
+ *
+ * @param float Format version to check
+ * @return boolean True if supported, False otherwise
+ */
+ public static function supports($version)
+ {
+ if ($version == '2.0')
+ return class_exists('kolabobject');
+ // default is version 3
+ return class_exists('kolabformat');
+ }
+
+ /**
* Convert the given date/time value into a cDateTime object
*
* @param mixed Date/Time value either as unix timestamp, date string or PHP DateTime object
@@ -184,6 +206,23 @@ abstract class kolab_format
return preg_replace('/dictionary.[a-z.]+$/', 'dictionary', substr($x_kolab_type, strlen(self::KTYPE_PREFIX)));
}
+
+ /**
+ * Default constructor of all kolab_format_* objects
+ */
+ public function __construct($xmldata = null, $version = null)
+ {
+ $this->obj = new $this->objclass;
+ $this->xmldata = $xmldata;
+
+ if ($version)
+ $this->version = $version;
+
+ // use libkolab module if available
+ if (class_exists('kolabobject'))
+ $this->xmlobject = new XMLObject();
+ }
+
/**
* Check for format errors after calling kolabformat::write*()
*
@@ -211,7 +250,7 @@ abstract class kolab_format
'type' => 'php',
'file' => __FILE__,
'line' => __LINE__,
- 'message' => "kolabformat write $log: " . kolabformat::errorMessage(),
+ 'message' => "kolabformat $log: " . kolabformat::errorMessage(),
), true);
}
@@ -226,7 +265,12 @@ abstract class kolab_format
{
// get generated UID
if (!$this->data['uid']) {
- $this->data['uid'] = kolabformat::getSerializedUID();
+ if ($this->xmlobject) {
+ $this->data['uid'] = $this->xmlobject->getSerializedUID();
+ }
+ if (empty($this->data['uid'])) {
+ $this->data['uid'] = kolabformat::getSerializedUID();
+ }
$this->obj->setUid($this->data['uid']);
}
}
@@ -246,6 +290,39 @@ abstract class kolab_format
}
/**
+ * Get constant value for libkolab's version parameter
+ *
+ * @param float Version value to convert
+ * @return int Constant value of either kolabobject::KolabV2 or kolabobject::KolabV3 or false if kolabobject module isn't available
+ */
+ protected function libversion($v = null)
+ {
+ if (class_exists('kolabobject')) {
+ $version = $v ?: $this->version;
+ if ($version <= '2.0')
+ return kolabobject::KolabV2;
+ else
+ return kolabobject::KolabV3;
+ }
+
+ return false;
+ }
+
+ /**
+ * Determine the correct libkolab(xml) wrapper function for the given call
+ * depending on the available PHP modules
+ */
+ protected function libfunc($func)
+ {
+ if (is_array($func) || strpos($func, '::'))
+ return $func;
+ else if (class_exists('kolabobject'))
+ return array($this->xmlobject, $func);
+ else
+ return 'kolabformat::' . $func;
+ }
+
+ /**
* Direct getter for object properties
*/
public function __get($var)
@@ -257,22 +334,39 @@ abstract class kolab_format
* Load Kolab object data from the given XML block
*
* @param string XML data
+ * @return boolean True on success, False on failure
*/
public function load($xml)
{
- $this->obj = call_user_func($this->read_func, $xml, false);
+ $read_func = $this->libfunc($this->read_func);
+
+ if (is_array($read_func))
+ $r = call_user_func($read_func, $xml, $this->libversion());
+ else
+ $r = call_user_func($read_func, $xml, false);
+
+ if (is_resource($r))
+ $this->obj = new $this->objclass($r);
+ else if (is_a($r, $this->objclass))
+ $this->obj = $r;
+
$this->loaded = !$this->format_errors();
}
/**
* Write object data to XML format
*
+ * @param float Format version to write
* @return string XML data
*/
- public function write()
+ public function write($version = null)
{
$this->init();
- $this->xmldata = call_user_func($this->write_func, $this->obj);
+ $write_func = $this->libfunc($this->write_func);
+ if (is_array($write_func))
+ $this->xmldata = call_user_func($write_func, $this->obj, $this->libversion($version), self::PRODUCT_ID);
+ else
+ $this->xmldata = call_user_func($write_func, $this->obj, self::PRODUCT_ID);
if (!$this->format_errors())
$this->update_uid();
@@ -287,26 +381,70 @@ abstract class kolab_format
*
* @param array Object data as hash array
*/
- abstract public function set(&$object);
+ public function set(&$object)
+ {
+ $this->init();
- /**
- *
- */
- abstract public function is_valid();
+ if (!empty($object['uid']))
+ $this->obj->setUid($object['uid']);
+
+ // set some automatic values if missing
+ if (method_exists($this->obj, 'setCreated') && !$this->obj->created()) {
+ if (empty($object['created']))
+ $object['created'] = new DateTime('now', self::$timezone);
+ $this->obj->setCreated(self::get_datetime($object['created']));
+ }
+
+ $object['changed'] = new DateTime('now', self::$timezone);
+ $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+
+ // Save custom properties of the given object
+ if (!empty($object['x-custom'])) {
+ $vcustom = new vectorcs;
+ foreach ($object['x-custom'] as $cp) {
+ if (is_array($cp))
+ $vcustom->push(new CustomProperty($cp[0], $cp[1]));
+ }
+ $this->obj->setCustomProperties($vcustom);
+ }
+ }
/**
* Convert the Kolab object into a hash array data structure
*
+ * @param array Additional data for merge
+ *
* @return array Kolab object data as hash array
*/
- abstract public function to_array();
+ public function to_array($data = array())
+ {
+ $this->init();
+
+ // read object properties into local data object
+ $object = array(
+ 'uid' => $this->obj->uid(),
+ 'changed' => self::php_datetime($this->obj->lastModified()),
+ );
+
+ // not all container support the created property
+ if (method_exists($this->obj, 'created')) {
+ $object['created'] = self::php_datetime($this->obj->created());
+ }
+
+ // read custom properties
+ $vcustom = $this->obj->customProperties();
+ for ($i=0; $i < $vcustom->size(); $i++) {
+ $cp = $vcustom->get($i);
+ $object['x-custom'][] = array($cp->identifier, $cp->value);
+ }
+
+ return $object;
+ }
/**
- * Load object data from Kolab2 format
- *
- * @param array Hash array with object properties (produced by Horde Kolab_Format classes)
+ * Object validation method to be implemented by derived classes
*/
- abstract public function fromkolab2($object);
+ abstract public function is_valid();
/**
* Callback for kolab_storage_cache to get object specific tags to cache
diff --git a/lib/plugins/libkolab/lib/kolab_format_configuration.php b/lib/plugins/libkolab/lib/kolab_format_configuration.php
index 974fc45..5e64e30 100644
--- a/lib/plugins/libkolab/lib/kolab_format_configuration.php
+++ b/lib/plugins/libkolab/lib/kolab_format_configuration.php
@@ -25,9 +25,11 @@
class kolab_format_configuration extends kolab_format
{
public $CTYPE = 'application/x-vnd.kolab.configuration';
+ public $CTYPEv2 = 'application/x-vnd.kolab.configuration';
- protected $read_func = 'kolabformat::readConfiguration';
- protected $write_func = 'kolabformat::writeConfiguration';
+ protected $objclass = 'Configuration';
+ protected $read_func = 'readConfiguration';
+ protected $write_func = 'writeConfiguration';
private $type_map = array(
'dictionary' => Configuration::TypeDictionary,
@@ -35,12 +37,6 @@ class kolab_format_configuration extends kolab_format
);
- function __construct($xmldata = null)
- {
- $this->obj = new Configuration;
- $this->xmldata = $xmldata;
- }
-
/**
* Set properties to the kolabformat object
*
@@ -74,7 +70,7 @@ class kolab_format_configuration extends kolab_format
$this->obj->setCreated(self::get_datetime($object['created']));
// adjust content-type string
- $this->CTYPE = 'application/x-vnd.kolab.configuration.' . $object['type'];
+ $this->CTYPE = $this->CTYPEv2 = 'application/x-vnd.kolab.configuration.' . $object['type'];
// cache this data
$this->data = $object;
@@ -92,9 +88,11 @@ class kolab_format_configuration extends kolab_format
/**
* Convert the Configuration object into a hash array data structure
*
+ * @param array Additional data for merge
+ *
* @return array Config object data as hash array
*/
- public function to_array()
+ public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
@@ -126,26 +124,13 @@ class kolab_format_configuration extends kolab_format
// adjust content-type string
if ($object['type'])
- $this->CTYPE = 'application/x-vnd.kolab.configuration.' . $object['type'];
+ $this->CTYPE = $this->CTYPEv2 = 'application/x-vnd.kolab.configuration.' . $object['type'];
$this->data = $object;
return $this->data;
}
/**
- * Load data from old Kolab2 format
- */
- public function fromkolab2($record)
- {
- $object = array(
- 'uid' => $record['uid'],
- 'changed' => $record['last-modification-date'],
- );
-
- $this->data = $object + $record;
- }
-
- /**
* Callback for kolab_storage_cache to get object specific tags to cache
*
* @return array List of tags to save in cache
diff --git a/lib/plugins/libkolab/lib/kolab_format_contact.php b/lib/plugins/libkolab/lib/kolab_format_contact.php
index ffef059..cde0288 100644
--- a/lib/plugins/libkolab/lib/kolab_format_contact.php
+++ b/lib/plugins/libkolab/lib/kolab_format_contact.php
@@ -25,9 +25,11 @@
class kolab_format_contact extends kolab_format
{
public $CTYPE = 'application/vcard+xml';
+ public $CTYPEv2 = 'application/x-vnd.kolab.contact';
- protected $read_func = 'kolabformat::readContact';
- protected $write_func = 'kolabformat::writeContact';
+ protected $objclass = 'Contact';
+ protected $read_func = 'readContact';
+ protected $write_func = 'writeContact';
public static $fulltext_cols = array('name', 'firstname', 'surname', 'middlename', 'email');
@@ -63,53 +65,13 @@ class kolab_format_contact extends kolab_format
'children' => Related::Child,
);
- // old Kolab 2 format field map
- private $kolab2_fieldmap = array(
- // kolab => roundcube
- 'full-name' => 'name',
- 'given-name' => 'firstname',
- 'middle-names' => 'middlename',
- 'last-name' => 'surname',
- 'prefix' => 'prefix',
- 'suffix' => 'suffix',
- 'nick-name' => 'nickname',
- 'organization' => 'organization',
- 'department' => 'department',
- 'job-title' => 'jobtitle',
- 'birthday' => 'birthday',
- 'anniversary' => 'anniversary',
- 'phone' => 'phone',
- 'im-address' => 'im',
- 'web-page' => 'website',
- 'profession' => 'profession',
- 'manager-name' => 'manager',
- 'assistant' => 'assistant',
- 'spouse-name' => 'spouse',
- 'children' => 'children',
- 'body' => 'notes',
- 'pgp-publickey' => 'pgppublickey',
- 'free-busy-url' => 'freebusyurl',
- 'picture' => 'photo',
- );
- private $kolab2_phonetypes = array(
- 'home1' => 'home',
- 'business1' => 'work',
- 'business2' => 'work',
- 'businessfax' => 'workfax',
- );
- private $kolab2_addresstypes = array(
- 'business' => 'work'
- );
- private $kolab2_gender = array(0 => 'male', 1 => 'female');
-
/**
* Default constructor
*/
- function __construct($xmldata = null)
+ function __construct($xmldata = null, $version = 3.0)
{
- $this->obj = new Contact;
- $this->xmldata = $xmldata;
+ parent::__construct($xmldata, $version);
// complete phone types
$this->phonetypes['homefax'] |= Telephone::Home;
@@ -123,20 +85,8 @@ class kolab_format_contact extends kolab_format
*/
public function set(&$object)
{
- $this->init();
-
- // set some automatic values if missing
- if (false && !$this->obj->created()) {
- if (!empty($object['created']))
- $object['created'] = new DateTime('now', self::$timezone);
- $this->obj->setCreated(self::get_datetime($object['created']));
- }
-
- if (!empty($object['uid']))
- $this->obj->setUid($object['uid']);
-
- $object['changed'] = new DateTime('now', self::$timezone);
- $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+ // set common object properties
+ parent::set($object);
// do the hard work of setting object values
$nc = new NameComponents;
@@ -147,6 +97,7 @@ class kolab_format_contact extends kolab_format
$nc->setSuffixes(self::array2vector($object['suffix']));
$this->obj->setNameComponents($nc);
$this->obj->setName($object['name']);
+ $this->obj->setCategories(self::array2vector($object['categories']));
if (isset($object['nickname']))
$this->obj->setNickNames(self::array2vector($object['nickname']));
@@ -304,22 +255,20 @@ class kolab_format_contact extends kolab_format
/**
* Convert the Contact object into a hash array data structure
*
+ * @param array Additional data for merge
+ *
* @return array Contact data as hash array
*/
- public function to_array()
+ public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
return $this->data;
- $this->init();
+ // read common object props into local data object
+ $object = parent::to_array();
- // read object properties into local data object
- $object = array(
- 'uid' => $this->obj->uid(),
- 'name' => $this->obj->name(),
- 'changed' => self::php_datetime($this->obj->lastModified()),
- );
+ $object['name'] = $this->obj->name();
$nc = $this->obj->nameComponents();
$object['surname'] = join(' ', self::vector2array($nc->surnames()));
@@ -329,6 +278,7 @@ class kolab_format_contact extends kolab_format
$object['suffix'] = join(' ', self::vector2array($nc->suffixes()));
$object['nickname'] = join(' ', self::vector2array($this->obj->nickNames()));
$object['profession'] = join(' ', self::vector2array($this->obj->titles()));
+ $object['categories'] = self::vector2array($this->obj->categories());
// organisation related properties (affiliation)
$orgs = $this->obj->affiliations();
@@ -378,6 +328,8 @@ class kolab_format_contact extends kolab_format
if ($this->obj->photoMimetype())
$object['photo'] = $this->obj->photo();
+ else if ($this->xmlobject && ($photo_name = $this->xmlobject->pictureAttachmentName()))
+ $object['photo'] = $photo_name;
// relateds -> spouse, children
$this->read_relateds($this->obj->relateds(), $object);
@@ -414,58 +366,6 @@ class kolab_format_contact extends kolab_format
}
/**
- * Load data from old Kolab2 format
- *
- * @param array Hash array with object properties
- */
- public function fromkolab2($record)
- {
- $object = array(
- 'uid' => $record['uid'],
- 'email' => array(),
- 'phone' => array(),
- );
-
- foreach ($this->kolab2_fieldmap as $kolab => $rcube) {
- if (is_array($record[$kolab]) || strlen($record[$kolab]))
- $object[$rcube] = $record[$kolab];
- }
-
- if (isset($record['gender']))
- $object['gender'] = $this->kolab2_gender[$record['gender']];
-
- foreach ((array)$record['email'] as $i => $email)
- $object['email'][] = $email['smtp-address'];
-
- if (!$record['email'] && $record['emails'])
- $object['email'] = preg_split('/,\s*/', $record['emails']);
-
- if (is_array($record['address'])) {
- foreach ($record['address'] as $i => $adr) {
- $object['address'][] = array(
- 'type' => $this->kolab2_addresstypes[$adr['type']] ? $this->kolab2_addresstypes[$adr['type']] : $adr['type'],
- 'street' => $adr['street'],
- 'locality' => $adr['locality'],
- 'code' => $adr['postal-code'],
- 'region' => $adr['region'],
- 'country' => $adr['country'],
- );
- }
- }
-
- // office location goes into an address block
- if ($record['office-location'])
- $object['address'][] = array('type' => 'office', 'locality' => $record['office-location']);
-
- // merge initials into nickname
- if ($record['initials'])
- $object['nickname'] = trim($object['nickname'] . ', ' . $record['initials'], ', ');
-
- // remove empty fields
- $this->data = array_filter($object);
- }
-
- /**
* Helper method to copy contents of an Address vector to the contact data object
*/
private function read_addresses($addresses, &$object, $type = null)
diff --git a/lib/plugins/libkolab/lib/kolab_format_distributionlist.php b/lib/plugins/libkolab/lib/kolab_format_distributionlist.php
index fcb94c1..d25bd47 100644
--- a/lib/plugins/libkolab/lib/kolab_format_distributionlist.php
+++ b/lib/plugins/libkolab/lib/kolab_format_distributionlist.php
@@ -25,17 +25,13 @@
class kolab_format_distributionlist extends kolab_format
{
public $CTYPE = 'application/vcard+xml';
+ public $CTYPEv2 = 'application/x-vnd.kolab.distribution-list';
- protected $read_func = 'kolabformat::readDistlist';
- protected $write_func = 'kolabformat::writeDistlist';
+ protected $objclass = 'DistList';
+ protected $read_func = 'readDistlist';
+ protected $write_func = 'writeDistlist';
- function __construct($xmldata = null)
- {
- $this->obj = new DistList;
- $this->xmldata = $xmldata;
- }
-
/**
* Set properties to the kolabformat object
*
@@ -43,14 +39,8 @@ class kolab_format_distributionlist extends kolab_format
*/
public function set(&$object)
{
- $this->init();
-
- // set some automatic values if missing
- if (!empty($object['uid']))
- $this->obj->setUid($object['uid']);
-
- $object['changed'] = new DateTime('now', self::$timezone);
- $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+ // set common object properties
+ parent::set($object);
$this->obj->setName($object['name']);
@@ -85,45 +75,23 @@ class kolab_format_distributionlist extends kolab_format
}
/**
- * Load data from old Kolab2 format
- */
- public function fromkolab2($record)
- {
- $object = array(
- 'uid' => $record['uid'],
- 'changed' => $record['last-modification-date'],
- 'name' => $record['last-name'],
- 'member' => array(),
- );
-
- foreach ((array)$record['member'] as $member) {
- $object['member'][] = array(
- 'email' => $member['smtp-address'],
- 'name' => $member['display-name'],
- 'uid' => $member['uid'],
- );
- }
-
- $this->data = $object;
- }
-
- /**
* Convert the Distlist object into a hash array data structure
*
+ * @param array Additional data for merge
+ *
* @return array Distribution list data as hash array
*/
- public function to_array()
+ public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
return $this->data;
- $this->init();
+ // read common object props into local data object
+ $object = parent::to_array();
- // read object properties
- $object = array(
- 'uid' => $this->obj->uid(),
- 'changed' => self::php_datetime($this->obj->lastModified()),
+ // add object properties
+ $object += array(
'name' => $this->obj->name(),
'member' => array(),
'_type' => 'distribution-list',
diff --git a/lib/plugins/libkolab/lib/kolab_format_event.php b/lib/plugins/libkolab/lib/kolab_format_event.php
index 33ed5af..ec97767 100644
--- a/lib/plugins/libkolab/lib/kolab_format_event.php
+++ b/lib/plugins/libkolab/lib/kolab_format_event.php
@@ -24,31 +24,47 @@
class kolab_format_event extends kolab_format_xcal
{
- protected $read_func = 'kolabformat::readEvent';
- protected $write_func = 'kolabformat::writeEvent';
-
- private $kolab2_rolemap = array(
- 'required' => 'REQ-PARTICIPANT',
- 'optional' => 'OPT-PARTICIPANT',
- 'resource' => 'CHAIR',
- );
- private $kolab2_statusmap = array(
- 'none' => 'NEEDS-ACTION',
- 'tentative' => 'TENTATIVE',
- 'accepted' => 'CONFIRMED',
- 'accepted' => 'ACCEPTED',
- 'declined' => 'DECLINED',
- );
- private $kolab2_monthmap = array('', 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december');
+ public $CTYPEv2 = 'application/x-vnd.kolab.event';
+ protected $objclass = 'Event';
+ protected $read_func = 'readEvent';
+ protected $write_func = 'writeEvent';
/**
* Default constructor
*/
- function __construct($xmldata = null)
+ function __construct($data = null, $version = 3.0)
{
- $this->obj = new Event;
- $this->xmldata = $xmldata;
+ parent::__construct(is_string($data) ? $data : null, $version);
+
+ // got an Event object as argument
+ if (is_object($data) && is_a($data, $this->objclass)) {
+ $this->obj = $data;
+ $this->loaded = true;
+ }
+ }
+
+ /**
+ * Clones into an instance of libcalendaring's extended EventCal class
+ *
+ * @return mixed EventCal object or false on failure
+ */
+ public function to_libcal()
+ {
+ static $error_logged = false;
+
+ if (class_exists('kolabcalendaring')) {
+ return new EventCal($this->obj);
+ }
+ else if (!$error_logged) {
+ $error_logged = true;
+ rcube::raise_error(array(
+ 'code' => 900, 'type' => 'php',
+ 'message' => "required kolabcalendaring module not found"
+ ), true);
+ }
+
+ return false;
}
/**
@@ -58,8 +74,6 @@ class kolab_format_event extends kolab_format_xcal
*/
public function set(&$object)
{
- $this->init();
-
// set common xcal properties
parent::set($object);
@@ -85,8 +99,27 @@ class kolab_format_event extends kolab_format_xcal
$attach->setUri('cid:' . $cid, $attr['mimetype']);
$vattach->push($attach);
}
+
+ foreach ((array)$object['links'] as $link) {
+ $attach = new Attachment;
+ $attach->setUri($link, null);
+ $vattach->push($attach);
+ }
+
$this->obj->setAttachments($vattach);
+ // save recurrence exceptions
+ if ($object['recurrence']['EXCEPTIONS']) {
+ $vexceptions = new vectorevent;
+ foreach((array)$object['recurrence']['EXCEPTIONS'] as $exception) {
+ $exevent = new kolab_format_event;
+ $exevent->set($this->compact_exception($exception, $object)); // only save differing values
+ $exevent->obj->setRecurrenceID(self::get_datetime($exception['start'], null, true), (bool)$exception['thisandfuture']);
+ $vexceptions->push($exevent->obj);
+ }
+ $this->obj->setExceptions($vexceptions);
+ }
+
// cache this data
$this->data = $object;
unset($this->data['_formatobj']);
@@ -103,16 +136,16 @@ class kolab_format_event extends kolab_format_xcal
/**
* Convert the Event object into a hash array data structure
*
+ * @param array Additional data for merge
+ *
* @return array Event data as hash array
*/
- public function to_array()
+ public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
return $this->data;
- $this->init();
-
// read common xcal props
$object = parent::to_array();
@@ -143,20 +176,50 @@ class kolab_format_event extends kolab_format_xcal
$attach = $vattach->get($i);
// skip cid: attachments which are mime message parts handled by kolab_storage_folder
- if (substr($attach->uri(), 0, 4) != 'cid') {
+ if (substr($attach->uri(), 0, 4) != 'cid:' && $attach->label()) {
$name = $attach->label();
$data = $attach->data();
$object['_attachments'][$name] = array(
- 'name' => $name,
+ 'name' => $name,
'mimetype' => $attach->mimetype(),
- 'size' => strlen($data),
- 'content' => $data,
+ 'size' => strlen($data),
+ 'content' => $data,
);
}
+ else if (substr($attach->uri(), 0, 4) == 'http') {
+ $object['links'][] = $attach->uri();
+ }
}
- $this->data = $object;
- return $this->data;
+ // read exception event objects
+ if (($exceptions = $this->obj->exceptions()) && is_object($exceptions) && $exceptions->size()) {
+ for ($i=0; $i < $exceptions->size(); $i++) {
+ if (($exobj = $exceptions->get($i))) {
+ $exception = new kolab_format_event($exobj);
+ if ($exception->is_valid()) {
+ $object['recurrence']['EXCEPTIONS'][] = $this->expand_exception($exception->to_array(), $object);
+ }
+ }
+ }
+ }
+ // this is an exception object
+ else if ($this->obj->recurrenceID()->isValid()) {
+ $object['thisandfuture'] = $this->obj->thisAndFuture();
+ }
+
+ // merge with additional data, e.g. attachments from the message
+ if ($data) {
+ foreach ($data as $idx => $value) {
+ if (is_array($value)) {
+ $object[$idx] = array_merge((array)$object[$idx], $value);
+ }
+ else {
+ $object[$idx] = $value;
+ }
+ }
+ }
+
+ return $this->data = $object;
}
/**
@@ -180,124 +243,33 @@ class kolab_format_event extends kolab_format_xcal
}
/**
- * Load data from old Kolab2 format
+ * Remove some attributes from the exception container
*/
- public function fromkolab2($rec)
+ private function compact_exception($exception, $master)
{
- if (PEAR::isError($rec))
- return;
-
- $start_time = date('H:i:s', $rec['start-date']);
- $allday = $rec['_is_all_day'] || ($start_time == '00:00:00' && $start_time == date('H:i:s', $rec['end-date']));
-
- // in Roundcube all-day events go from 12:00 to 13:00
- if ($allday) {
- $now = new DateTime('now', self::$timezone);
- $gmt_offset = $now->getOffset();
-
- $rec['start-date'] += 12 * 3600;
- $rec['end-date'] -= 11 * 3600;
- $rec['end-date'] -= $gmt_offset - date('Z', $rec['end-date']); // shift times from server's timezone to user's timezone
- $rec['start-date'] -= $gmt_offset - date('Z', $rec['start-date']); // because generated with mktime() in Horde_Kolab_Format_Date::decodeDate()
- // sanity check
- if ($rec['end-date'] <= $rec['start-date'])
- $rec['end-date'] += 86400;
- }
+ static $forbidden = array('recurrence','organizer','attendees','sequence');
- // convert alarm time into internal format
- if ($rec['alarm']) {
- $alarm_value = $rec['alarm'];
- $alarm_unit = 'M';
- if ($rec['alarm'] % 1440 == 0) {
- $alarm_value /= 1440;
- $alarm_unit = 'D';
- }
- else if ($rec['alarm'] % 60 == 0) {
- $alarm_value /= 60;
- $alarm_unit = 'H';
- }
- $alarm_value *= -1;
+ $out = $exception;
+ foreach ($exception as $prop => $val) {
+ if (in_array($prop, $forbidden)) {
+ unset($out[$prop]);
}
+ }
- // convert recurrence rules into internal pseudo-vcalendar format
- if ($recurrence = $rec['recurrence']) {
- $rrule = array(
- 'FREQ' => strtoupper($recurrence['cycle']),
- 'INTERVAL' => intval($recurrence['interval']),
- );
-
- if ($recurrence['range-type'] == 'number')
- $rrule['COUNT'] = intval($recurrence['range']);
- else if ($recurrence['range-type'] == 'date')
- $rrule['UNTIL'] = date_create('@'.$recurrence['range']);
-
- if ($recurrence['day']) {
- $byday = array();
- $prefix = ($rrule['FREQ'] == 'MONTHLY' || $rrule['FREQ'] == 'YEARLY') ? intval($recurrence['daynumber'] ? $recurrence['daynumber'] : 1) : '';
- foreach ($recurrence['day'] as $day)
- $byday[] = $prefix . substr(strtoupper($day), 0, 2);
- $rrule['BYDAY'] = join(',', $byday);
- }
- if ($recurrence['daynumber']) {
- if ($recurrence['type'] == 'monthday' || $recurrence['type'] == 'daynumber')
- $rrule['BYMONTHDAY'] = $recurrence['daynumber'];
- else if ($recurrence['type'] == 'yearday')
- $rrule['BYYEARDAY'] = $recurrence['daynumber'];
- }
- if ($recurrence['month']) {
- $monthmap = array_flip($this->kolab2_monthmap);
- $rrule['BYMONTH'] = strtolower($monthmap[$recurrence['month']]);
- }
-
- if ($recurrence['exclusion']) {
- foreach ((array)$recurrence['exclusion'] as $excl)
- $rrule['EXDATE'][] = date_create($excl . date(' H:i:s', $rec['start-date'])); // use time of event start
- }
- }
-
- $attendees = array();
- if ($rec['organizer']) {
- $attendees[] = array(
- 'role' => 'ORGANIZER',
- 'name' => $rec['organizer']['display-name'],
- 'email' => $rec['organizer']['smtp-address'],
- 'status' => 'ACCEPTED',
- );
- $_attendees .= $rec['organizer']['display-name'] . ' ' . $rec['organizer']['smtp-address'] . ' ';
- }
-
- foreach ((array)$rec['attendee'] as $attendee) {
- $attendees[] = array(
- 'role' => $this->kolab2_rolemap[$attendee['role']],
- 'name' => $attendee['display-name'],
- 'email' => $attendee['smtp-address'],
- 'status' => $this->kolab2_statusmap[$attendee['status']],
- 'rsvp' => $attendee['request-response'],
- );
- $_attendees .= $rec['organizer']['display-name'] . ' ' . $rec['organizer']['smtp-address'] . ' ';
- }
+ return $out;
+ }
- $this->data = array(
- 'uid' => $rec['uid'],
- 'title' => $rec['summary'],
- 'location' => $rec['location'],
- 'description' => $rec['body'],
- 'start' => new DateTime('@'.$rec['start-date']),
- 'end' => new DateTime('@'.$rec['end-date']),
- 'allday' => $allday,
- 'recurrence' => $rrule,
- 'alarms' => $alarm_value . $alarm_unit,
- 'categories' => explode(',', $rec['categories']),
- 'attachments' => $attachments,
- 'attendees' => $attendees,
- 'free_busy' => $rec['show-time-as'],
- 'priority' => $rec['priority'],
- 'sensitivity' => $rec['sensitivity'],
- 'changed' => $rec['last-modification-date'],
- );
+ /**
+ * Copy attributes not specified by the exception from the master event
+ */
+ private function expand_exception($exception, $master)
+ {
+ foreach ($master as $prop => $value) {
+ if (empty($exception[$prop]) && !empty($value))
+ $exception[$prop] = $value;
+ }
- // assign current timezone to event start/end
- $this->data['start']->setTimezone(self::$timezone);
- $this->data['end']->setTimezone(self::$timezone);
+ return $exception;
}
+
}
diff --git a/lib/plugins/libkolab/lib/kolab_format_journal.php b/lib/plugins/libkolab/lib/kolab_format_journal.php
index 5869af0..3528d16 100644
--- a/lib/plugins/libkolab/lib/kolab_format_journal.php
+++ b/lib/plugins/libkolab/lib/kolab_format_journal.php
@@ -25,17 +25,13 @@
class kolab_format_journal extends kolab_format
{
public $CTYPE = 'application/calendar+xml';
+ public $CTYPEv2 = 'application/x-vnd.kolab.journal';
- protected $read_func = 'kolabformat::readJournal';
- protected $write_func = 'kolabformat::writeJournal';
+ protected $objclass = 'Journal';
+ protected $read_func = 'readJournal';
+ protected $write_func = 'writeJournal';
- function __construct($xmldata = null)
- {
- $this->obj = new Journal;
- $this->xmldata = $xmldata;
- }
-
/**
* Set properties to the kolabformat object
*
@@ -43,14 +39,8 @@ class kolab_format_journal extends kolab_format
*/
public function set(&$object)
{
- $this->init();
-
- // set some automatic values if missing
- if (!empty($object['uid']))
- $this->obj->setUid($object['uid']);
-
- $object['changed'] = new DateTime('now', self::$timezone);
- $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+ // set common object properties
+ parent::set($object);
// TODO: set object propeties
@@ -68,40 +58,20 @@ class kolab_format_journal extends kolab_format
}
/**
- * Load data from old Kolab2 format
- */
- public function fromkolab2($record)
- {
- $object = array(
- 'uid' => $record['uid'],
- 'changed' => $record['last-modification-date'],
- );
-
- // TODO: implement this
-
- $this->data = $object;
- }
-
- /**
* Convert the Configuration object into a hash array data structure
*
+ * @param array Additional data for merge
+ *
* @return array Config object data as hash array
*/
- public function to_array()
+ public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
return $this->data;
- $this->init();
-
- // read object properties
- $object = array(
- 'uid' => $this->obj->uid(),
- 'created' => self::php_datetime($this->obj->created()),
- 'changed' => self::php_datetime($this->obj->lastModified()),
- );
-
+ // read common object props into local data object
+ $object = parent::to_array();
// TODO: read object properties
diff --git a/lib/plugins/libkolab/lib/kolab_format_note.php b/lib/plugins/libkolab/lib/kolab_format_note.php
index 1c88a8b..cee6345 100644
--- a/lib/plugins/libkolab/lib/kolab_format_note.php
+++ b/lib/plugins/libkolab/lib/kolab_format_note.php
@@ -25,17 +25,13 @@
class kolab_format_note extends kolab_format
{
public $CTYPE = 'application/x-vnd.kolab.note';
+ public $CTYPEv2 = 'application/x-vnd.kolab.note';
- protected $read_func = 'kolabformat::readNote';
- protected $write_func = 'kolabformat::writeNote';
+ protected $objclass = 'Note';
+ protected $read_func = 'readNote';
+ protected $write_func = 'writeNote';
- function __construct($xmldata = null)
- {
- $this->obj = new Note;
- $this->xmldata = $xmldata;
- }
-
/**
* Set properties to the kolabformat object
*
@@ -43,14 +39,8 @@ class kolab_format_note extends kolab_format
*/
public function set(&$object)
{
- $this->init();
-
- // set some automatic values if missing
- if (!empty($object['uid']))
- $this->obj->setUid($object['uid']);
-
- $object['changed'] = new DateTime('now', self::$timezone);
- $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+ // set common object properties
+ parent::set($object);
// TODO: set object propeties
@@ -68,39 +58,20 @@ class kolab_format_note extends kolab_format
}
/**
- * Load data from old Kolab2 format
- */
- public function fromkolab2($record)
- {
- $object = array(
- 'uid' => $record['uid'],
- 'changed' => $record['last-modification-date'],
- );
-
-
- $this->data = $object;
- }
-
- /**
* Convert the Configuration object into a hash array data structure
*
+ * @param array Additional data for merge
+ *
* @return array Config object data as hash array
*/
- public function to_array()
+ public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
return $this->data;
- $this->init();
-
- // read object properties
- $object = array(
- 'uid' => $this->obj->uid(),
- 'created' => self::php_datetime($this->obj->created()),
- 'changed' => self::php_datetime($this->obj->lastModified()),
- );
-
+ // read common object props into local data object
+ $object = parent::to_array();
// TODO: read object properties
diff --git a/lib/plugins/libkolab/lib/kolab_format_task.php b/lib/plugins/libkolab/lib/kolab_format_task.php
index 2a7a629..0fa2806 100644
--- a/lib/plugins/libkolab/lib/kolab_format_task.php
+++ b/lib/plugins/libkolab/lib/kolab_format_task.php
@@ -24,15 +24,12 @@
class kolab_format_task extends kolab_format_xcal
{
- protected $read_func = 'kolabformat::readTodo';
- protected $write_func = 'kolabformat::writeTodo';
+ public $CTYPEv2 = 'application/x-vnd.kolab.task';
+ protected $objclass = 'Todo';
+ protected $read_func = 'readTodo';
+ protected $write_func = 'writeTodo';
- function __construct($xmldata = null)
- {
- $this->obj = new Todo;
- $this->xmldata = $xmldata;
- }
/**
* Set properties to the kolabformat object
@@ -41,8 +38,6 @@ class kolab_format_task extends kolab_format_xcal
*/
public function set(&$object)
{
- $this->init();
-
// set common xcal properties
parent::set($object);
@@ -74,16 +69,16 @@ class kolab_format_task extends kolab_format_xcal
/**
* Convert the Configuration object into a hash array data structure
*
+ * @param array Additional data for merge
+ *
* @return array Config object data as hash array
*/
- public function to_array()
+ public function to_array($data = array())
{
// return cached result
if (!empty($this->data))
return $this->data;
- $this->init();
-
// read common xcal props
$object = parent::to_array();
@@ -105,21 +100,6 @@ class kolab_format_task extends kolab_format_xcal
}
/**
- * Load data from old Kolab2 format
- */
- public function fromkolab2($record)
- {
- $object = array(
- 'uid' => $record['uid'],
- 'changed' => $record['last-modification-date'],
- );
-
- // TODO: implement this
-
- $this->data = $object;
- }
-
- /**
* Callback for kolab_storage_cache to get object specific tags to cache
*
* @return array List of tags to save in cache
diff --git a/lib/plugins/libkolab/lib/kolab_format_xcal.php b/lib/plugins/libkolab/lib/kolab_format_xcal.php
index 1191df5..bbe3404 100644
--- a/lib/plugins/libkolab/lib/kolab_format_xcal.php
+++ b/lib/plugins/libkolab/lib/kolab_format_xcal.php
@@ -88,17 +88,20 @@ abstract class kolab_format_xcal extends kolab_format
/**
* Convert common xcard properties into a hash array data structure
*
+ * @param array Additional data for merge
+ *
* @return array Object data as hash array
*/
- public function to_array()
+ public function to_array($data = array())
{
+ // read common object props
+ $object = parent::to_array();
+
$status_map = array_flip($this->status_map);
$sensitivity_map = array_flip($this->sensitivity_map);
- $object = array(
- 'uid' => $this->obj->uid(),
- 'created' => self::php_datetime($this->obj->created()),
- 'changed' => self::php_datetime($this->obj->lastModified()),
+ $object += array(
+ 'sequence' => intval($this->obj->sequence()),
'title' => $this->obj->summary(),
'location' => $this->obj->location(),
'description' => $this->obj->description(),
@@ -110,7 +113,7 @@ abstract class kolab_format_xcal extends kolab_format
);
// read organizer and attendees
- if ($organizer = $this->obj->organizer()) {
+ if (($organizer = $this->obj->organizer()) && ($organizer->email() || $organizer->name())) {
$object['organizer'] = array(
'email' => $organizer->email(),
'name' => $organizer->name(),
@@ -167,9 +170,9 @@ abstract class kolab_format_xcal extends kolab_format
$object['recurrence']['BYMONTH'] = join(',', self::vector2array($bymonth));
}
- if ($exceptions = $this->obj->exceptionDates()) {
- for ($i=0; $i < $exceptions->size(); $i++) {
- if ($exdate = self::php_datetime($exceptions->get($i)))
+ if ($exdates = $this->obj->exceptionDates()) {
+ for ($i=0; $i < $exdates->size(); $i++) {
+ if ($exdate = self::php_datetime($exdates->get($i)))
$object['recurrence']['EXDATE'][] = $exdate;
}
}
@@ -213,21 +216,16 @@ abstract class kolab_format_xcal extends kolab_format
*/
public function set(&$object)
{
- // set some automatic values if missing
- if (!$this->obj->created()) {
- if (!empty($object['created']))
- $object['created'] = new DateTime('now', self::$timezone);
- $this->obj->setCreated(self::get_datetime($object['created']));
- }
+ $this->init();
- if (!empty($object['uid']))
- $this->obj->setUid($object['uid']);
+ $is_new = !$this->obj->uid();
- $object['changed'] = new DateTime('now', self::$timezone);
- $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+ // set common object properties
+ parent::set($object);
- // increment sequence
- $this->obj->setSequence($this->obj->sequence()+1);
+ // increment sequence on updates
+ $object['sequence'] = !$is_new ? $this->obj->sequence()+1 : 0;
+ $this->obj->setSequence($object['sequence']);
$this->obj->setSummary($object['title']);
$this->obj->setLocation($object['location']);
diff --git a/lib/plugins/libkolab/lib/kolab_storage.php b/lib/plugins/libkolab/lib/kolab_storage.php
index edb512d..a569af7 100644
--- a/lib/plugins/libkolab/lib/kolab_storage.php
+++ b/lib/plugins/libkolab/lib/kolab_storage.php
@@ -5,6 +5,7 @@
*
* @version @package_version@
* @author Thomas Bruederli <bruederli at kolabsys.com>
+ * @author Aleksander Machniak <machniak at kolabsys.com>
*
* Copyright (C) 2012, Kolab Systems AG <contact at kolabsys.com>
*
@@ -28,12 +29,13 @@ class kolab_storage
const CTYPE_KEY_PRIVATE = '/private/vendor/kolab/folder-type';
const COLOR_KEY_SHARED = '/shared/vendor/kolab/color';
const COLOR_KEY_PRIVATE = '/private/vendor/kolab/color';
- const SERVERSIDE_SUBSCRIPTION = 0;
- const CLIENTSIDE_SUBSCRIPTION = 1;
+ public static $version = '3.0';
public static $last_error;
private static $ready = false;
+ private static $subscriptions;
+ private static $states;
private static $config;
private static $cache;
private static $imap;
@@ -49,6 +51,7 @@ class kolab_storage
$rcmail = rcube::get_instance();
self::$config = $rcmail->config;
+ self::$version = strval($rcmail->config->get('kolab_format_version', self::$version));
self::$imap = $rcmail->get_storage();
self::$ready = class_exists('kolabformat') &&
(self::$imap->get_capability('METADATA') || self::$imap->get_capability('ANNOTATEMORE') || self::$imap->get_capability('ANNOTATEMORE2'));
@@ -61,6 +64,18 @@ class kolab_storage
));
self::$imap->set_pagesize(9999);
}
+ else if (!class_exists('kolabformat')) {
+ rcube::raise_error(array(
+ 'code' => 900, 'type' => 'php',
+ 'message' => "required kolabformat module not found"
+ ), true);
+ }
+ else {
+ rcube::raise_error(array(
+ 'code' => 900, 'type' => 'php',
+ 'message' => "IMAP server doesn't support METADATA or ANNOTATEMORE"
+ ), true);
+ }
return self::$ready;
}
@@ -78,7 +93,7 @@ class kolab_storage
$folders = $folderdata = array();
if (self::setup()) {
- foreach ((array)self::list_folders('', '*', $type, false, $folderdata) as $foldername) {
+ foreach ((array)self::list_folders('', '*', $type, null, $folderdata) as $foldername) {
$folders[$foldername] = new kolab_storage_folder($foldername, $folderdata[$foldername]);
}
}
@@ -178,13 +193,14 @@ class kolab_storage
/**
* Creates IMAP folder
*
- * @param string $name Folder name (UTF7-IMAP)
- * @param string $type Folder type
- * @param bool $subscribed Sets folder subscription
+ * @param string $name Folder name (UTF7-IMAP)
+ * @param string $type Folder type
+ * @param bool $subscribed Sets folder subscription
+ * @param bool $active Sets folder state (client-side subscription)
*
* @return bool True on success, false on failure
*/
- public static function folder_create($name, $type = null, $subscribed = false)
+ public static function folder_create($name, $type = null, $subscribed = false, $active = false)
{
self::setup();
@@ -197,6 +213,10 @@ class kolab_storage
if (!$saved) {
self::$imap->delete_folder($name);
}
+ // activate folder
+ else if ($active) {
+ self::set_state($name, true);
+ }
}
}
@@ -208,6 +228,7 @@ class kolab_storage
return false;
}
+
/**
* Renames IMAP folder
*
@@ -233,10 +254,12 @@ class kolab_storage
* Does additional checks for permissions and folder name restrictions
*
* @param array Hash array with folder properties and metadata
- * - name: Folder name
- * - oldname: Old folder name when changed
- * - parent: Parent folder to create the new one in
- * - type: Folder type to create
+ * - name: Folder name
+ * - oldname: Old folder name when changed
+ * - parent: Parent folder to create the new one in
+ * - type: Folder type to create
+ * - subscribed: Subscribed flag (IMAP subscription)
+ * - active: Activation flag (client-side subscription)
* @return mixed New folder name or False on failure
*/
public static function folder_update(&$prop)
@@ -305,7 +328,7 @@ class kolab_storage
}
// create new folder
else {
- $result = self::folder_create($folder, $prop['type'], $prop['subscribed'] === self::SERVERSIDE_SUBSCRIPTION);
+ $result = self::folder_create($folder, $prop['type'], $prop['subscribed'], $prop['active']);
}
// save color in METADATA
@@ -518,17 +541,22 @@ class kolab_storage
* @param string Optional root folder
* @param string Optional name pattern
* @param string Data type to list folders for (contact,distribution-list,event,task,note,mail)
- * @param string Enable to return subscribed folders only
+ * @param boolean Enable to return subscribed folders only (null to use configured subscription mode)
* @param array Will be filled with folder-types data
*
* @return array List of folders
*/
- public static function list_folders($root = '', $mbox = '*', $filter = null, $subscribed = false, &$folderdata = array())
+ public static function list_folders($root = '', $mbox = '*', $filter = null, $subscribed = null, &$folderdata = array())
{
if (!self::setup()) {
return null;
}
+ // use IMAP subscriptions
+ if ($subscribed === null && self::$config->get('kolab_use_subscriptions')) {
+ $subscribed = true;
+ }
+
if (!$filter) {
// Get ALL folders list, standard way
if ($subscribed) {
@@ -552,7 +580,7 @@ class kolab_storage
$regexp = '/^' . preg_quote($filter, '/') . '(\..+)?$/';
// In some conditions we can skip LIST command (?)
- if ($subscribed == false && $filter != 'mail' && $prefix == '*') {
+ if (!$subscribed && $filter != 'mail' && $prefix == '*') {
foreach ($folderdata as $folder => $type) {
if (!preg_match($regexp, $type)) {
unset($folderdata[$folder]);
@@ -595,7 +623,14 @@ class kolab_storage
*/
static function folder_select_metadata($types)
{
- return $types[self::CTYPE_KEY_PRIVATE] ?: $types[self::CTYPE_KEY];
+ if (!empty($types[self::CTYPE_KEY_PRIVATE])) {
+ return $types[self::CTYPE_KEY_PRIVATE];
+ }
+ else if (!empty($types[self::CTYPE_KEY])) {
+ list($ctype, $suffix) = explode('.', $types[self::CTYPE_KEY]);
+ return $ctype;
+ }
+ return null;
}
@@ -623,6 +658,7 @@ class kolab_storage
return 'mail';
}
+
/**
* Sets folder content-type.
*
@@ -633,6 +669,8 @@ class kolab_storage
*/
static function set_folder_type($folder, $type='mail')
{
+ self::setup();
+
list($ctype, $subtype) = explode('.', $type);
$success = self::$imap->set_metadata($folder, array(self::CTYPE_KEY => $ctype, self::CTYPE_KEY_PRIVATE => $subtype ? $type : null));
@@ -642,4 +680,156 @@ class kolab_storage
return $success;
}
+
+
+ /**
+ * Check subscription status of this folder
+ *
+ * @param string $folder Folder name
+ *
+ * @return boolean True if subscribed, false if not
+ */
+ public static function folder_is_subscribed($folder)
+ {
+ if (self::$subscriptions === null) {
+ self::setup();
+ self::$subscriptions = self::$imap->list_folders_subscribed();
+ }
+
+ return in_array($folder, self::$subscriptions);
+ }
+
+
+ /**
+ * Change subscription status of this folder
+ *
+ * @param string $folder Folder name
+ *
+ * @return True on success, false on error
+ */
+ public static function folder_subscribe($folder)
+ {
+ self::setup();
+
+ if (self::$imap->subscribe($folder)) {
+ self::$subscriptions === null;
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Change subscription status of this folder
+ *
+ * @param string $folder Folder name
+ *
+ * @return True on success, false on error
+ */
+ public static function folder_unsubscribe($folder)
+ {
+ self::setup();
+
+ if (self::$imap->unsubscribe($folder)) {
+ self::$subscriptions === null;
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Check activation status of this folder
+ *
+ * @param string $folder Folder name
+ *
+ * @return boolean True if active, false if not
+ */
+ public static function folder_is_active($folder)
+ {
+ $active_folders = self::get_states();
+
+ return in_array($folder, $active_folders);
+ }
+
+
+ /**
+ * Change activation status of this folder
+ *
+ * @param string $folder Folder name
+ *
+ * @return True on success, false on error
+ */
+ public static function folder_activate($folder)
+ {
+ return self::set_state($folder, true);
+ }
+
+
+ /**
+ * Change activation status of this folder
+ *
+ * @param string $folder Folder name
+ *
+ * @return True on success, false on error
+ */
+ public static function folder_deactivate($folder)
+ {
+ return self::set_state($folder, false);
+ }
+
+
+ /**
+ * Return list of active folders
+ */
+ private static function get_states()
+ {
+ if (self::$states !== null) {
+ return self::$states;
+ }
+
+ $rcube = rcube::get_instance();
+ $folders = $rcube->config->get('kolab_active_folders');
+
+ if ($folders !== null) {
+ self::$states = !empty($folders) ? explode('**', $folders) : array();
+ }
+ // for backward-compatibility copy server-side subscriptions to activation states
+ else {
+ self::setup();
+ if (self::$subscriptions === null) {
+ self::$subscriptions = self::$imap->list_folders_subscribed();
+ }
+ self::$states = self::$subscriptions;
+ $folders = implode(self::$states, '**');
+ $rcube->user->save_prefs(array('kolab_active_folders' => $folders));
+ }
+
+ return self::$states;
+ }
+
+
+ /**
+ * Update list of active folders
+ */
+ private static function set_state($folder, $state)
+ {
+ self::get_states();
+
+ // update in-memory list
+ $idx = array_search($folder, self::$states);
+ if ($state && $idx === false) {
+ self::$states[] = $folder;
+ }
+ else if (!$state && $idx !== false) {
+ unset(self::$states[$idx]);
+ }
+
+ // update user preferences
+ $folders = implode(self::$states, '**');
+ $rcube = rcube::get_instance();
+ return $rcube->user->save_prefs(array('kolab_active_folders' => $folders));
+ }
}
diff --git a/lib/plugins/libkolab/lib/kolab_storage_cache.php b/lib/plugins/libkolab/lib/kolab_storage_cache.php
index c3e88da..ef4dd22 100644
--- a/lib/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/lib/plugins/libkolab/lib/kolab_storage_cache.php
@@ -363,6 +363,15 @@ class kolab_storage_cache
// TODO: post-filter result according to query
}
+ // We don't want to cache big results in-memory, however
+ // if we select only one object here, there's a big chance we will need it later
+ if (!$uids && count($result) == 1) {
+ if ($msguid = $result[0]['_msguid']) {
+ $this->uid2msg[$result[0]['uid']] = $msguid;
+ $this->objects[$msguid] = $result[0];
+ }
+ }
+
return $result;
}
@@ -517,8 +526,8 @@ class kolab_storage_cache
$sql_data['dtend'] = date('Y-m-d H:i:s', is_object($object['end']) ? $object['end']->format('U') : $object['end']);
// extend date range for recurring events
- if ($object['recurrence']) {
- $recurrence = new kolab_date_recurrence($object);
+ if ($object['recurrence'] && $object['_formatobj']) {
+ $recurrence = new kolab_date_recurrence($object['_formatobj']);
$sql_data['dtend'] = date('Y-m-d 23:59:59', $recurrence->end() ?: strtotime('now +1 year'));
}
}
@@ -534,7 +543,7 @@ class kolab_storage_cache
}
if ($object['_formatobj']) {
- $sql_data['xml'] = preg_replace('!(</?[a-z0-9:-]+>)[\n\r\t\s]+!ms', '$1', (string)$object['_formatobj']->write());
+ $sql_data['xml'] = preg_replace('!(</?[a-z0-9:-]+>)[\n\r\t\s]+!ms', '$1', (string)$object['_formatobj']->write(3.0));
$sql_data['tags'] = ' ' . join(' ', $object['_formatobj']->get_tags()) . ' '; // pad with spaces for strict/prefix search
$sql_data['words'] = ' ' . join(' ', $object['_formatobj']->get_words()) . ' ';
}
@@ -582,7 +591,8 @@ class kolab_storage_cache
$object['_type'] = $sql_arr['type'];
$object['_msguid'] = $sql_arr['msguid'];
$object['_mailbox'] = $this->folder->name;
- $object['_formatobj'] = kolab_format::factory($sql_arr['type'], $sql_arr['xml']);
+ $object['_size'] = strlen($sql_arr['xml']);
+ $object['_formatobj'] = kolab_format::factory($sql_arr['type'], 3.0, $sql_arr['xml']);
return $object;
}
@@ -717,7 +727,8 @@ class kolab_storage_cache
{
if (!isset($this->uid2msg[$uid])) {
// use IMAP SEARCH to get the right message
- $index = $this->imap->search_once($this->folder->name, ($deleted ? '' : 'UNDELETED ') . 'HEADER SUBJECT ' . $uid);
+ $index = $this->imap->search_once($this->folder->name, ($deleted ? '' : 'UNDELETED ') .
+ 'HEADER SUBJECT ' . rcube_imap_generic::escape($uid));
$results = $index->get();
$this->uid2msg[$uid] = $results[0];
}
diff --git a/lib/plugins/libkolab/lib/kolab_storage_folder.php b/lib/plugins/libkolab/lib/kolab_storage_folder.php
index bc47eab..dd0e8d2 100644
--- a/lib/plugins/libkolab/lib/kolab_storage_folder.php
+++ b/lib/plugins/libkolab/lib/kolab_storage_folder.php
@@ -5,6 +5,7 @@
*
* @version @package_version@
* @author Thomas Bruederli <bruederli at kolabsys.com>
+ * @author Aleksander Machniak <machniak at kolabsys.com>
*
* Copyright (C) 2012, Kolab Systems AG <contact at kolabsys.com>
*
@@ -50,6 +51,7 @@ class kolab_storage_folder
private $type_annotation;
private $imap;
private $info;
+ private $idata;
private $owner;
private $resource_uri;
private $uid2msg = array();
@@ -98,6 +100,16 @@ class kolab_storage_folder
return $this->info;
}
+ /**
+ * Make IMAP folder data available for this folder
+ */
+ public function get_imap_data()
+ {
+ if (!isset($this->idata))
+ $this->idata = $this->imap->folder_data($this->name);
+
+ return $this->idata;
+ }
/**
* Returns IMAP metadata/annotations (GETMETADATA/GETANNOTATION)
@@ -191,6 +203,24 @@ class kolab_storage_folder
/**
+ * Get the color value stores in metadata
+ *
+ * @param string Default color value to return if not set
+ * @return mixed Color value from IMAP metadata or $default is not set
+ */
+ public function get_color($default = null)
+ {
+ // color is defined in folder METADATA
+ $metadata = $this->get_metadata(array(kolab_storage::COLOR_KEY_PRIVATE, kolab_storage::COLOR_KEY_SHARED));
+ if (($color = $metadata[kolab_storage::COLOR_KEY_PRIVATE]) || ($color = $metadata[kolab_storage::COLOR_KEY_SHARED])) {
+ return $color;
+ }
+
+ return $default;
+ }
+
+
+ /**
* Compose a unique resource URI for this IMAP folder
*/
public function get_resource_uri()
@@ -218,46 +248,47 @@ class kolab_storage_folder
}
/**
- * Check subscription status of this folder
+ * Check activation status of this folder
*
- * @param string Subscription type (kolab_storage::SERVERSIDE_SUBSCRIPTION or kolab_storage::CLIENTSIDE_SUBSCRIPTION)
- * @return boolean True if subscribed, false if not
+ * @return boolean True if enabled, false if not
*/
- public function is_subscribed($type = 0)
+ public function is_active()
{
- static $subscribed; // local cache
-
- if ($type == kolab_storage::SERVERSIDE_SUBSCRIPTION) {
- if (!$subscribed)
- $subscribed = $this->imap->list_folders_subscribed();
+ return kolab_storage::folder_is_active($this->name);
+ }
- return in_array($this->name, $subscribed);
- }
- else if (kolab_storage::CLIENTSIDE_SUBSCRIPTION) {
- // TODO: implement this
- return true;
- }
+ /**
+ * Change activation status of this folder
+ *
+ * @param boolean The desired subscription status: true = active, false = not active
+ *
+ * @return True on success, false on error
+ */
+ public function activate($active)
+ {
+ return $active ? kolab_storage::folder_activate($this->name) : kolab_storage::folder_deactivate($this->name);
+ }
- return false;
+ /**
+ * Check subscription status of this folder
+ *
+ * @return boolean True if subscribed, false if not
+ */
+ public function is_subscribed()
+ {
+ return kolab_storage::folder_is_subscribed($this->name);
}
/**
* Change subscription status of this folder
*
* @param boolean The desired subscription status: true = subscribed, false = not subscribed
- * @param string Subscription type (kolab_storage::SERVERSIDE_SUBSCRIPTION or kolab_storage::CLIENTSIDE_SUBSCRIPTION)
+ *
* @return True on success, false on error
*/
- public function subscribe($subscribed, $type = 0)
+ public function subscribe($subscribed)
{
- if ($type == kolab_storage::SERVERSIDE_SUBSCRIPTION) {
- return $subscribed ? $this->imap->subscribe($this->name) : $this->imap->unsubscribe($this->name);
- }
- else {
- // TODO: implement this
- }
-
- return false;
+ return $subscribed ? kolab_storage::folder_subscribe($this->name) : kolab_storage::folder_unsubscribe($this->name);
}
@@ -389,17 +420,21 @@ class kolab_storage_folder
* Fetch a Kolab object attachment which is stored in a separate part
* of the mail MIME message that represents the Kolab record.
*
- * @param string Object's UID
- * @param string The attachment's mime number
- * @param string IMAP folder where message is stored;
- * If set, that also implies that the given UID is an IMAP UID
+ * @param string Object's UID
+ * @param string The attachment's mime number
+ * @param string IMAP folder where message is stored;
+ * If set, that also implies that the given UID is an IMAP UID
+ * @param bool True to print the part content
+ * @param resource File pointer to save the message part
+ * @param boolean Disables charset conversion
+ *
* @return mixed The attachment content as binary string
*/
- public function get_attachment($uid, $part, $mailbox = null)
+ public function get_attachment($uid, $part, $mailbox = null, $print = false, $fp = null, $skip_charset_conv = false)
{
if ($msguid = ($mailbox ? $uid : $this->cache->uid2msguid($uid))) {
$this->imap->set_folder($mailbox ? $mailbox : $this->name);
- return $this->imap->get_message_part($msguid, $part);
+ return $this->imap->get_message_part($msguid, $part, null, $print, $fp, $skip_charset_conv);
}
return null;
@@ -423,12 +458,40 @@ class kolab_storage_folder
$this->imap->set_folder($folder);
$headers = $this->imap->get_message_headers($msguid);
+ $message = null;
// Message doesn't exist?
if (empty($headers)) {
return false;
}
+ // extract the X-Kolab-Type header from the XML attachment part if missing
+ if (empty($headers->others['x-kolab-type'])) {
+ $message = new rcube_message($msguid);
+ foreach ((array)$message->attachments as $part) {
+ if (strpos($part->mimetype, kolab_format::KTYPE_PREFIX) === 0) {
+ $headers->others['x-kolab-type'] = $part->mimetype;
+ break;
+ }
+ }
+ }
+ // fix buggy messages stating the X-Kolab-Type header twice
+ else if (is_array($headers->others['x-kolab-type'])) {
+ $headers->others['x-kolab-type'] = reset($headers->others['x-kolab-type']);
+ }
+
+ // no object type header found: abort
+ if (empty($headers->others['x-kolab-type'])) {
+ rcube::raise_error(array(
+ 'code' => 600,
+ 'type' => 'php',
+ 'file' => __FILE__,
+ 'line' => __LINE__,
+ 'message' => "No X-Kolab-Type information found in message $msguid ($this->name).",
+ ), true);
+ return false;
+ }
+
$object_type = kolab_format::mime2object_type($headers->others['x-kolab-type']);
$content_type = kolab_format::KTYPE_PREFIX . $object_type;
@@ -436,7 +499,7 @@ class kolab_storage_folder
if ($type != '*' && $object_type != $type)
return false;
- $message = new rcube_message($msguid);
+ if (!$message) $message = new rcube_message($msguid);
$attachments = array();
// get XML part
@@ -445,12 +508,23 @@ class kolab_storage_folder
$xml = $part->body ? $part->body : $message->get_part_content($part->mime_id);
}
else if ($part->filename || $part->content_id) {
- $key = $part->content_id ? trim($part->content_id, '<>') : $part->filename;
+ $key = $part->content_id ? trim($part->content_id, '<>') : $part->filename;
+ $size = null;
+
+ // Use Content-Disposition 'size' as for the Kolab Format spec.
+ if (isset($part->d_parameters['size'])) {
+ $size = $part->d_parameters['size'];
+ }
+ // we can trust part size only if it's not encoded
+ else if ($part->encoding == 'binary' || $part->encoding == '7bit' || $part->encoding == '8bit') {
+ $size = $part->size;
+ }
+
$attachments[$key] = array(
- 'id' => $part->mime_id,
- 'name' => $part->filename,
+ 'id' => $part->mime_id,
+ 'name' => $part->filename,
'mimetype' => $part->mimetype,
- 'size' => $part->size,
+ 'size' => $size,
);
}
}
@@ -466,46 +540,33 @@ class kolab_storage_folder
return false;
}
- $format = kolab_format::factory($object_type);
-
- if (is_a($format, 'PEAR_Error'))
- return false;
-
// check kolab format version
- $mime_version = $headers->others['x-kolab-mime-version'];
- if (empty($mime_version)) {
+ $format_version = $headers->others['x-kolab-mime-version'];
+ if (empty($format_version)) {
list($xmltype, $subtype) = explode('.', $object_type);
$xmlhead = substr($xml, 0, 512);
// detect old Kolab 2.0 format
if (strpos($xmlhead, '<' . $xmltype) !== false && strpos($xmlhead, 'xmlns=') === false)
- $mime_version = 2.0;
+ $format_version = '2.0';
else
- $mime_version = 3.0; // assume 3.0
+ $format_version = '3.0'; // assume 3.0
}
- if ($mime_version <= 2.0) {
- // read Kolab 2.0 format
- $handler = class_exists('Horde_Kolab_Format') ? Horde_Kolab_Format::factory('XML', $xmltype, array('subtype' => $subtype)) : null;
- if (!is_object($handler) || is_a($handler, 'PEAR_Error')) {
- return false;
- }
+ // get Kolab format handler for the given type
+ $format = kolab_format::factory($object_type, $format_version);
- // XML-to-array
- $object = $handler->load($xml);
- $format->fromkolab2($object);
- }
- else {
- // load Kolab 3 format using libkolabxml
- $format->load($xml);
- }
+ if (is_a($format, 'PEAR_Error'))
+ return false;
+
+ // load Kolab object from XML part
+ $format->load($xml);
if ($format->is_valid()) {
- $object = $format->to_array();
- $object['_type'] = $object_type;
- $object['_msguid'] = $msguid;
- $object['_mailbox'] = $this->name;
- $object['_attachments'] = array_merge((array)$object['_attachments'], $attachments);
+ $object = $format->to_array(array('_attachments' => $attachments));
+ $object['_type'] = $object_type;
+ $object['_msguid'] = $msguid;
+ $object['_mailbox'] = $this->name;
$object['_formatobj'] = $format;
return $object;
@@ -527,7 +588,6 @@ class kolab_storage_folder
return false;
}
-
/**
* Save an object in this folder.
*
@@ -552,17 +612,39 @@ class kolab_storage_folder
unset($object['_attachments'][$key]);
}
// load photo.attachment from old Kolab2 format to be directly embedded in xcard block
- else if ($key == 'photo.attachment' && !isset($object['photo']) && !$object['_attachments'][$key]['content'] && $att['id']) {
- $object['photo'] = $this->get_attachment($object['_msguid'], $att['id'], $object['_mailbox']);
+ else if ($type == 'contact' && ($key == 'photo.attachment' || $key == 'kolab-picture.png') && $att['id']) {
+ if (!isset($object['photo']))
+ $object['photo'] = $this->get_attachment($object['_msguid'], $att['id'], $object['_mailbox']);
unset($object['_attachments'][$key]);
}
}
}
- // generate unique keys (used as content-id) for attachments
+ // save contact photo to attachment for Kolab2 format
+ if (kolab_storage::$version == '2.0' && $object['photo'] && !$existing_photo) {
+ $attkey = 'kolab-picture.png'; // this file name is hard-coded in libkolab/kolabformatV2/contact.cpp
+ $object['_attachments'][$attkey] = array(
+ 'mimetype'=> rc_image_content_type($object['photo']),
+ 'content' => preg_match('![^a-z0-9/=+-]!i', $object['photo']) ? $object['photo'] : base64_decode($object['photo']),
+ );
+ }
+
+ // process attachments
if (is_array($object['_attachments'])) {
$numatt = count($object['_attachments']);
foreach ($object['_attachments'] as $key => $attachment) {
+ // make sure size is set, so object saved in cache contains this info
+ if (!isset($attachment['size'])) {
+ if (!empty($attachment['content'])) {
+ $attachment['size'] = strlen($attachment['content']);
+ }
+ else if (!empty($attachment['path'])) {
+ $attachment['size'] = filesize($attachment['path']);
+ }
+ $object['_attachments'][$key] = $attachment;
+ }
+
+ // generate unique keys (used as content-id) for attachments
if (is_numeric($key) && $key < $numatt) {
// derrive content-id from attachment file name
$ext = preg_match('/(\.[a-z0-9]{1,6})$/i', $attachment['name'], $m) ? $m[1] : null;
@@ -576,18 +658,37 @@ class kolab_storage_folder
}
}
- if ($raw_msg = $this->build_message($object, $type)) {
- $result = $this->imap->save_message($this->name, $raw_msg, '', false);
+ // save recurrence exceptions as individual objects due to lack of support in Kolab v2 format
+ if (kolab_storage::$version == '2.0' && $object['recurrence']['EXCEPTIONS']) {
+ $this->save_recurrence_exceptions($object, $type);
+ }
+
+ // check IMAP BINARY extension support for 'file' objects
+ // allow configuration to workaround bug in Cyrus < 2.4.17
+ $rcmail = rcube::get_instance();
+ $binary = $type == 'file' && !$rcmail->config->get('kolab_binary_disable') && $this->imap->get_capability('BINARY');
+
+ // generate and save object message
+ if ($raw_msg = $this->build_message($object, $type, $binary)) {
+ // resolve old msguid before saving
+ if ($uid && empty($object['_msguid']) && ($msguid = $this->cache->uid2msguid($uid))) {
+ $object['_msguid'] = $msguid;
+ $object['_mailbox'] = $this->name;
+ }
+
+ if (is_array($raw_msg)) {
+ $result = $this->imap->save_message($this->name, $raw_msg[0], $raw_msg[1], true, null, null, $binary);
+ @unlink($raw_msg[0]);
+ }
+ else {
+ $result = $this->imap->save_message($this->name, $raw_msg, null, false, null, null, $binary);
+ }
// delete old message
if ($result && !empty($object['_msguid']) && !empty($object['_mailbox'])) {
$this->imap->delete_message($object['_msguid'], $object['_mailbox']);
$this->cache->set($object['_msguid'], false, $object['_mailbox']);
}
- else if ($result && $uid && ($msguid = $this->cache->uid2msguid($uid))) {
- $this->imap->delete_message($msguid, $this->name);
- $this->cache->set($object['_msguid'], false);
- }
// update cache with new UID
if ($result) {
@@ -595,10 +696,72 @@ class kolab_storage_folder
$this->cache->insert($result, $object);
}
}
-
+
return $result;
}
+ /**
+ * Save recurrence exceptions as individual objects.
+ * The Kolab v2 format doesn't allow us to save fully embedded exception objects.
+ *
+ * @param array Hash array with event properties
+ * @param string Object type
+ */
+ private function save_recurrence_exceptions(&$object, $type = null)
+ {
+ if ($object['recurrence']['EXCEPTIONS']) {
+ $exdates = array();
+ foreach ((array)$object['recurrence']['EXDATE'] as $exdate) {
+ $key = is_a($exdate, 'DateTime') ? $exdate->format('Y-m-d') : strval($exdate);
+ $exdates[$key] = 1;
+ }
+
+ // save every exception as individual object
+ foreach((array)$object['recurrence']['EXCEPTIONS'] as $exception) {
+ $exception['uid'] = self::recurrence_exception_uid($object['uid'], $exception['start']->format('Ymd'));
+ $exception['sequence'] = $object['sequence'] + 1;
+
+ if ($exception['thisandfuture']) {
+ $exception['recurrence'] = $object['recurrence'];
+
+ // adjust the recurrence duration of the exception
+ if ($object['recurrence']['COUNT']) {
+ $recurrence = new kolab_date_recurrence($object['_formatobj']);
+ if ($end = $recurrence->end()) {
+ unset($exception['recurrence']['COUNT']);
+ $exception['recurrence']['UNTIL'] = new DateTime('@'.$end);
+ }
+ }
+
+ // set UNTIL date if we have a thisandfuture exception
+ $untildate = clone $exception['start'];
+ $untildate->sub(new DateInterval('P1D'));
+ $object['recurrence']['UNTIL'] = $untildate;
+ unset($object['recurrence']['COUNT']);
+ }
+ else {
+ if (!$exdates[$exception['start']->format('Y-m-d')])
+ $object['recurrence']['EXDATE'][] = clone $exception['start'];
+ unset($exception['recurrence']);
+ }
+
+ unset($exception['recurrence']['EXCEPTIONS'], $exception['_formatobj'], $exception['_msguid']);
+ $this->save($exception, $type, $exception['uid']);
+ }
+
+ unset($object['recurrence']['EXCEPTIONS']);
+ }
+ }
+
+ /**
+ * Generate an object UID with the given recurrence-ID in a way that it is
+ * unique (the original UID is not a substring) but still recoverable.
+ */
+ private static function recurrence_exception_uid($uid, $recurrence_id)
+ {
+ $offset = -2;
+ return substr($uid, 0, $offset) . '-' . $recurrence_id . '-' . substr($uid, $offset);
+ }
/**
* Delete the specified object from this folder.
@@ -685,8 +848,11 @@ class kolab_storage_folder
/**
* Creates source of the configuration object message
+ *
+ * @return mixed Message as string or array with two elements
+ * (one for message file path, second for message headers)
*/
- private function build_message(&$object, $type)
+ private function build_message(&$object, $type, $binary)
{
// load old object to preserve data we don't understand/process
if (is_object($object['_formatobj']))
@@ -696,43 +862,66 @@ class kolab_storage_folder
// create new kolab_format instance
if (!$format)
- $format = kolab_format::factory($type);
+ $format = kolab_format::factory($type, kolab_storage::$version);
if (PEAR::isError($format))
return false;
$format->set($object);
- $xml = $format->write();
+ $xml = $format->write(kolab_storage::$version);
$object['uid'] = $format->uid; // read UID from format
$object['_formatobj'] = $format;
- if (!$format->is_valid() || empty($object['uid'])) {
+ if (empty($xml) || !$format->is_valid() || empty($object['uid'])) {
return false;
}
- $mime = new Mail_mime("\r\n");
- $rcmail = rcube::get_instance();
- $headers = array();
- $part_id = 1;
+ $mime = new Mail_mime("\r\n");
+ $rcmail = rcube::get_instance();
+ $headers = array();
+ $part_id = 1;
+ $encoding = $binary ? 'binary' : 'base64';
- if ($ident = $rcmail->user->get_identity()) {
- $headers['From'] = $ident['email'];
- $headers['To'] = $ident['email'];
+ if ($user_email = $rcmail->get_user_email()) {
+ $headers['From'] = $user_email;
+ $headers['To'] = $user_email;
}
$headers['Date'] = date('r');
$headers['X-Kolab-Type'] = kolab_format::KTYPE_PREFIX . $type;
- $headers['X-Kolab-Mime-Version'] = kolab_format::VERSION;
+ $headers['X-Kolab-Mime-Version'] = kolab_storage::$version;
$headers['Subject'] = $object['uid'];
// $headers['Message-ID'] = $rcmail->gen_message_id();
$headers['User-Agent'] = $rcmail->config->get('useragent');
+ // Check if we have enough memory to handle the message in it
+ // It's faster than using files, so we'll do this if we only can
+ if (!empty($object['_attachments']) && ($mem_limit = parse_bytes(ini_get('memory_limit'))) > 0) {
+ $memory = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB
+
+ foreach ($object['_attachments'] as $id => $attachment) {
+ $memory += $attachment['size'];
+ }
+
+ // 1.33 is for base64, we need at least 2x more memory than the message size
+ if ($memory * ($binary ? 1 : 1.33) * 2 > $mem_limit) {
+ $is_file = true;
+ $temp_dir = unslashify($rcmail->config->get('temp_dir'));
+ $mime->setParam('delay_file_io', true);
+ }
+ }
+
$mime->headers($headers);
- $mime->setTXTBody('This is a Kolab Groupware object. '
- . 'To view this object you will need an email client that understands the Kolab Groupware format. '
+ $mime->setTXTBody("This is a Kolab Groupware object. "
+ . "To view this object you will need an email client that understands the Kolab Groupware format. "
. "For a list of such email clients please visit http://www.kolab.org/\n\n");
+ $ctype = kolab_storage::$version == '2.0' ? $format->CTYPEv2 : $format->CTYPE;
+ // Convert new lines to \r\n, to wrokaround "NO Message contains bare newlines"
+ // when APPENDing from temp file
+ $xml = preg_replace('/\r?\n/', "\r\n", $xml);
+
$mime->addAttachment($xml, // file
- $format->CTYPE, // content-type
+ $ctype, // content-type
'kolab.xml', // filename
false, // is_file
'8bit', // encoding
@@ -742,29 +931,55 @@ class kolab_storage_folder
$part_id++;
// save object attachments as separate parts
- // TODO: optimize memory consumption by using tempfiles for transfer
foreach ((array)$object['_attachments'] as $key => $att) {
if (empty($att['content']) && !empty($att['id'])) {
$msguid = !empty($object['_msguid']) ? $object['_msguid'] : $object['uid'];
- $att['content'] = $this->get_attachment($msguid, $att['id'], $object['_mailbox']);
+ if ($is_file) {
+ $att['path'] = tempnam($temp_dir, 'rcmAttmnt');
+ if (($fp = fopen($att['path'], 'w')) && $this->get_attachment($msguid, $att['id'], $object['_mailbox'], false, $fp)) {
+ fclose($fp);
+ }
+ else {
+ return false;
+ }
+ }
+ else {
+ $att['content'] = $this->get_attachment($msguid, $att['id'], $object['_mailbox']);
+ }
}
$headers = array('Content-ID' => Mail_mimePart::encodeHeader('Content-ID', '<' . $key . '>', RCUBE_CHARSET, 'quoted-printable'));
$name = !empty($att['name']) ? $att['name'] : $key;
if (!empty($att['content'])) {
- $mime->addAttachment($att['content'], $att['mimetype'], $name, false, 'base64', 'attachment', '', '', '', null, null, '', RCUBE_CHARSET, $headers);
+ $mime->addAttachment($att['content'], $att['mimetype'], $name, false, $encoding, 'attachment', '', '', '', null, null, '', RCUBE_CHARSET, $headers);
$part_id++;
}
else if (!empty($att['path'])) {
- $mime->addAttachment($att['path'], $att['mimetype'], $name, true, 'base64', 'attachment', '', '', '', null, null, '', RCUBE_CHARSET, $headers);
+ $mime->addAttachment($att['path'], $att['mimetype'], $name, true, $encoding, 'attachment', '', '', '', null, null, '', RCUBE_CHARSET, $headers);
$part_id++;
}
$object['_attachments'][$key]['id'] = $part_id;
}
- return $mime->getMessage();
+ if ($is_file) {
+ // use common temp dir
+ $body_file = tempnam($temp_dir, 'rcmMsg');
+
+ if (PEAR::isError($mime_result = $mime->saveMessageBody($body_file))) {
+ self::raise_error(array('code' => 650, 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Could not create message: ".$mime_result->getMessage()),
+ true, false);
+ return false;
+ }
+
+ return array($body_file, $mime->txtHeaders());
+ }
+ else {
+ return $mime->getMessage();
+ }
}
@@ -784,7 +999,11 @@ class kolab_storage_folder
case 'event':
if ($this->get_namespace() == 'personal') {
$result = $this->trigger_url(
- sprintf('%s/trigger/%s/%s.pfb', kolab_storage::get_freebusy_server(), $owner, $this->imap->mod_folder($this->name)),
+ sprintf('%s/trigger/%s/%s.pfb',
+ kolab_storage::get_freebusy_server(),
+ urlencode($owner),
+ urlencode($this->imap->mod_folder($this->name))
+ ),
$this->imap->options['user'],
$this->imap->options['password']
);
diff --git a/lib/plugins/libkolab/libkolab.php b/lib/plugins/libkolab/libkolab.php
index 3709ee0..b5ff968 100644
--- a/lib/plugins/libkolab/libkolab.php
+++ b/lib/plugins/libkolab/libkolab.php
@@ -46,20 +46,9 @@ class libkolab extends rcube_plugin
kolab_format::$timezone = new DateTimeZone($rcmail->config->get('timezone', 'GMT'));
}
catch (Exception $e) {
- raise_error($e, true);
+ rcube::raise_error($e, true);
kolab_format::$timezone = new DateTimeZone('GMT');
}
-
- // load (old) dependencies if available
- if (@include_once('Horde/Util.php')) {
- include_once 'Horde/Kolab/Format.php';
- include_once 'Horde/Kolab/Format/XML.php';
- include_once 'Horde/Kolab/Format/XML/contact.php';
- include_once 'Horde/Kolab/Format/XML/event.php';
- include_once 'Horde_Kolab_Format_XML_configuration.php';
-
- String::setDefaultCharset('UTF-8');
- }
}
/**
@@ -70,6 +59,4 @@ class libkolab extends rcube_plugin
$p['fetch_headers'] = trim($p['fetch_headers'] .' X-KOLAB-TYPE X-KOLAB-MIME-VERSION');
return $p;
}
-
-
}
commit e4ad6bfdcc943761bd14c1de338dace87cde135b
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun Mar 17 08:05:12 2013 +0100
Update Roundcube Framework
diff --git a/lib/ext/Roundcube/html.php b/lib/ext/Roundcube/html.php
index 522a823..5927203 100644
--- a/lib/ext/Roundcube/html.php
+++ b/lib/ext/Roundcube/html.php
@@ -21,7 +21,7 @@
* Class for HTML code creation
*
* @package Framework
- * @subpackage HTML
+ * @subpackage View
*/
class html
{
@@ -287,7 +287,7 @@ class html
}
// attributes with no value
- if (in_array($key, array('checked', 'multiple', 'disabled', 'selected'))) {
+ if (in_array($key, array('checked', 'multiple', 'disabled', 'selected', 'autofocus'))) {
if ($value) {
$attrib_arr[] = $key . '="' . $key . '"';
}
@@ -340,7 +340,8 @@ class html
/**
* Class to create an HTML input field
*
- * @package HTML
+ * @package Framework
+ * @subpackage View
*/
class html_inputfield extends html
{
@@ -350,6 +351,7 @@ class html_inputfield extends html
'type','name','value','size','tabindex','autocapitalize',
'autocomplete','checked','onchange','onclick','disabled','readonly',
'spellcheck','results','maxlength','src','multiple','placeholder',
+ 'autofocus',
);
/**
@@ -395,7 +397,8 @@ class html_inputfield extends html
/**
* Class to create an HTML password field
*
- * @package HTML
+ * @package Framework
+ * @subpackage View
*/
class html_passwordfield extends html_inputfield
{
@@ -405,9 +408,9 @@ class html_passwordfield extends html_inputfield
/**
* Class to create an hidden HTML input field
*
- * @package HTML
+ * @package Framework
+ * @subpackage View
*/
-
class html_hiddenfield extends html
{
protected $tagname = 'input';
@@ -455,7 +458,8 @@ class html_hiddenfield extends html
/**
* Class to create HTML radio buttons
*
- * @package HTML
+ * @package Framework
+ * @subpackage View
*/
class html_radiobutton extends html_inputfield
{
@@ -485,7 +489,8 @@ class html_radiobutton extends html_inputfield
/**
* Class to create HTML checkboxes
*
- * @package HTML
+ * @package Framework
+ * @subpackage View
*/
class html_checkbox extends html_inputfield
{
@@ -515,7 +520,8 @@ class html_checkbox extends html_inputfield
/**
* Class to create an HTML textarea
*
- * @package HTML
+ * @package Framework
+ * @subpackage View
*/
class html_textarea extends html
{
@@ -573,7 +579,8 @@ class html_textarea extends html
* print $select->show('CH');
* </pre>
*
- * @package HTML
+ * @package Framework
+ * @subpackage View
*/
class html_select extends html
{
@@ -638,7 +645,8 @@ class html_select extends html
/**
* Class to build an HTML table
*
- * @package HTML
+ * @package Framework
+ * @subpackage View
*/
class html_table extends html
{
diff --git a/lib/ext/Roundcube/rcube.php b/lib/ext/Roundcube/rcube.php
index a914ae6..3ae511e 100644
--- a/lib/ext/Roundcube/rcube.php
+++ b/lib/ext/Roundcube/rcube.php
@@ -1073,14 +1073,17 @@ class rcube
{
// handle PHP exceptions
if (is_object($arg) && is_a($arg, 'Exception')) {
- $err = array(
+ $arg = array(
'type' => 'php',
'code' => $arg->getCode(),
'line' => $arg->getLine(),
'file' => $arg->getFile(),
'message' => $arg->getMessage(),
);
- $arg = $err;
+ }
+
+ if (empty($arg['code'])) {
+ $arg['code'] = 500;
}
// installer
diff --git a/lib/ext/Roundcube/rcube_addressbook.php b/lib/ext/Roundcube/rcube_addressbook.php
index 4210627..cbc3c67 100644
--- a/lib/ext/Roundcube/rcube_addressbook.php
+++ b/lib/ext/Roundcube/rcube_addressbook.php
@@ -524,6 +524,22 @@ abstract class rcube_addressbook
}
/**
+ * Create a unique key for sorting contacts
+ */
+ public static function compose_contact_key($contact, $sort_col)
+ {
+ $key = $contact[$sort_col] . ':' . $row['sourceid'];
+
+ // add email to a key to not skip contacts with the same name (#1488375)
+ if (!empty($contact['email'])) {
+ $key .= ':' . implode(':', (array)$contact['email']);
+ }
+
+ return $key;
+ }
+
+
+ /**
* Compare search value with contact data
*
* @param string $colname Data name
diff --git a/lib/ext/Roundcube/rcube_base_replacer.php b/lib/ext/Roundcube/rcube_base_replacer.php
index fcd85c2..e41ccb1 100644
--- a/lib/ext/Roundcube/rcube_base_replacer.php
+++ b/lib/ext/Roundcube/rcube_base_replacer.php
@@ -21,7 +21,7 @@
* using a predefined base
*
* @package Framework
- * @subpackage Core
+ * @subpackage Utils
* @author Thomas Bruederli <roundcube at gmail.com>
*/
class rcube_base_replacer
diff --git a/lib/ext/Roundcube/rcube_browser.php b/lib/ext/Roundcube/rcube_browser.php
index d10fe2a..3412829 100644
--- a/lib/ext/Roundcube/rcube_browser.php
+++ b/lib/ext/Roundcube/rcube_browser.php
@@ -20,7 +20,7 @@
* Provide details about the client's browser based on the User-Agent header
*
* @package Framework
- * @subpackage Core
+ * @subpackage Utils
*/
class rcube_browser
{
diff --git a/lib/ext/Roundcube/rcube_content_filter.php b/lib/ext/Roundcube/rcube_content_filter.php
index b814bb7..ae6617d 100644
--- a/lib/ext/Roundcube/rcube_content_filter.php
+++ b/lib/ext/Roundcube/rcube_content_filter.php
@@ -20,7 +20,7 @@
* PHP stream filter to detect html/javascript code in attachments
*
* @package Framework
- * @subpackage Core
+ * @subpackage Utils
*/
class rcube_content_filter extends php_user_filter
{
diff --git a/lib/ext/Roundcube/rcube_db.php b/lib/ext/Roundcube/rcube_db.php
index 086a38a..49bbe5c 100644
--- a/lib/ext/Roundcube/rcube_db.php
+++ b/lib/ext/Roundcube/rcube_db.php
@@ -70,7 +70,7 @@ class rcube_db
$driver = isset($driver_map[$driver]) ? $driver_map[$driver] : $driver;
$class = "rcube_db_$driver";
- if (!class_exists($class)) {
+ if (!$driver || !class_exists($class)) {
rcube::raise_error(array('code' => 600, 'type' => 'db',
'line' => __LINE__, 'file' => __FILE__,
'message' => "Configuration error. Unsupported database driver: $driver"),
@@ -222,7 +222,7 @@ class rcube_db
$this->db_connected = is_object($this->dbh);
// use write-master when read-only fails
- if (!$this->db_connected && $mode == 'r') {
+ if (!$this->db_connected && $mode == 'r' && $this->is_replicated()) {
$mode = 'w';
$this->dbh = $this->dsn_connect($this->db_dsnw_array);
$this->db_connected = is_object($this->dbh);
@@ -439,6 +439,29 @@ class rcube_db
}
/**
+ * Get number of rows for a SQL query
+ * If no query handle is specified, the last query will be taken as reference
+ *
+ * @param mixed $result Optional query handle
+ * @return mixed Number of rows or false on failure
+ */
+ public function num_rows($result = null)
+ {
+ if ($result || ($result === null && ($result = $this->last_result))) {
+ // repeat query with SELECT COUNT(*) ...
+ if (preg_match('/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i', $result->queryString, $m)) {
+ $query = $this->dbh->query('SELECT COUNT(*) FROM ' . $m[1], PDO::FETCH_NUM);
+ return $query ? intval($query->fetchColumn(0)) : false;
+ }
+ else {
+ return count($result->fetchAll());
+ }
+ }
+
+ return false;
+ }
+
+ /**
* Get last inserted record ID
*
* @param string $table Table name (to find the incremented sequence)
@@ -571,7 +594,7 @@ class rcube_db
* Formats input so it can be safely used in a query
*
* @param mixed $input Value to quote
- * @param string $type Type of data
+ * @param string $type Type of data (integer, bool, ident)
*
* @return string Quoted/converted string for use in query
*/
@@ -586,6 +609,10 @@ class rcube_db
return 'NULL';
}
+ if ($type == 'ident') {
+ return $this->quote_identifier($input);
+ }
+
// create DB handle if not available
if (!$this->dbh) {
$this->db_connect('r');
@@ -635,7 +662,7 @@ class rcube_db
$name[] = $start . $elem . $end;
}
- return implode($name, '.');
+ return implode($name, '.');
}
/**
@@ -652,7 +679,7 @@ class rcube_db
* Return list of elements for use with SQL's IN clause
*
* @param array $arr Input array
- * @param string $type Type of data
+ * @param string $type Type of data (integer, bool, ident)
*
* @return string Comma-separated list of quoted values for use in query
*/
diff --git a/lib/ext/Roundcube/rcube_db_mssql.php b/lib/ext/Roundcube/rcube_db_mssql.php
index 84fe22b..37a4267 100644
--- a/lib/ext/Roundcube/rcube_db_mssql.php
+++ b/lib/ext/Roundcube/rcube_db_mssql.php
@@ -100,26 +100,30 @@ class rcube_db_mssql extends rcube_db
{
$limit = intval($limit);
$offset = intval($offset);
+ $end = $offset + $limit;
- $orderby = stristr($query, 'ORDER BY');
- if ($orderby !== false) {
- $sort = (stripos($orderby, ' desc') !== false) ? 'desc' : 'asc';
- $order = str_ireplace('ORDER BY', '', $orderby);
- $order = trim(preg_replace('/\bASC\b|\bDESC\b/i', '', $order));
+ // query without OFFSET
+ if (!$offset) {
+ $query = preg_replace('/^SELECT\s/i', "SELECT TOP $limit ", $query);
+ return $query;
}
- $query = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($limit + $offset) . ' ', $query);
+ $orderby = stristr($query, 'ORDER BY');
+ $offset += 1;
- $query = 'SELECT * FROM (SELECT TOP ' . $limit . ' * FROM (' . $query . ') AS inner_tbl';
if ($orderby !== false) {
- $query .= ' ORDER BY ' . $order . ' ';
- $query .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
+ $query = trim(substr($query, 0, -1 * strlen($orderby)));
}
- $query .= ') AS outer_tbl';
- if ($orderby !== false) {
- $query .= ' ORDER BY ' . $order . ' ' . $sort;
+ else {
+ // it shouldn't happen, paging without sorting has not much sense
+ // @FIXME: I don't know how to build paging query without ORDER BY
+ $orderby = "ORDER BY 1";
}
+ $query = preg_replace('/^SELECT\s/i', '', $query);
+ $query = "WITH paging AS (SELECT ROW_NUMBER() OVER ($orderby) AS [RowNumber], $query)"
+ . " SELECT * FROM paging WHERE [RowNumber] BETWEEN $offset AND $end ORDER BY [RowNumber]";
+
return $query;
}
diff --git a/lib/ext/Roundcube/rcube_db_sqlsrv.php b/lib/ext/Roundcube/rcube_db_sqlsrv.php
index e696780..e5dfb11 100644
--- a/lib/ext/Roundcube/rcube_db_sqlsrv.php
+++ b/lib/ext/Roundcube/rcube_db_sqlsrv.php
@@ -100,26 +100,30 @@ class rcube_db_sqlsrv extends rcube_db
{
$limit = intval($limit);
$offset = intval($offset);
+ $end = $offset + $limit;
- $orderby = stristr($query, 'ORDER BY');
- if ($orderby !== false) {
- $sort = (stripos($orderby, ' desc') !== false) ? 'desc' : 'asc';
- $order = str_ireplace('ORDER BY', '', $orderby);
- $order = trim(preg_replace('/\bASC\b|\bDESC\b/i', '', $order));
+ // query without OFFSET
+ if (!$offset) {
+ $query = preg_replace('/^SELECT\s/i', "SELECT TOP $limit ", $query);
+ return $query;
}
- $query = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($limit + $offset) . ' ', $query);
+ $orderby = stristr($query, 'ORDER BY');
+ $offset += 1;
- $query = 'SELECT * FROM (SELECT TOP ' . $limit . ' * FROM (' . $query . ') AS inner_tbl';
if ($orderby !== false) {
- $query .= ' ORDER BY ' . $order . ' ';
- $query .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
+ $query = trim(substr($query, 0, -1 * strlen($orderby)));
}
- $query .= ') AS outer_tbl';
- if ($orderby !== false) {
- $query .= ' ORDER BY ' . $order . ' ' . $sort;
+ else {
+ // it shouldn't happen, paging without sorting has not much sense
+ // @FIXME: I don't know how to build paging query without ORDER BY
+ $orderby = "ORDER BY 1";
}
+ $query = preg_replace('/^SELECT\s/i', '', $query);
+ $query = "WITH paging AS (SELECT ROW_NUMBER() OVER ($orderby) AS [RowNumber], $query)"
+ . " SELECT * FROM paging WHERE [RowNumber] BETWEEN $offset AND $end ORDER BY [RowNumber]";
+
return $query;
}
diff --git a/lib/ext/Roundcube/rcube_html2text.php b/lib/ext/Roundcube/rcube_html2text.php
index 0b172eb..9b248a3 100644
--- a/lib/ext/Roundcube/rcube_html2text.php
+++ b/lib/ext/Roundcube/rcube_html2text.php
@@ -571,55 +571,65 @@ class rcube_html2text
*/
protected function _convert_blockquotes(&$text)
{
- if (preg_match_all('/<\/*blockquote[^>]*>/i', $text, $matches, PREG_OFFSET_CAPTURE)) {
- $level = 0;
- $diff = 0;
- foreach ($matches[0] as $m) {
- if ($m[0][0] == '<' && $m[0][1] == '/') {
+ $level = 0;
+ $offset = 0;
+ while (($start = strpos($text, '<blockquote', $offset)) !== false) {
+ $offset = $start + 12;
+ do {
+ $end = strpos($text, '</blockquote>', $offset);
+ $next = strpos($text, '<blockquote', $offset);
+
+ // nested <blockquote>, skip
+ if ($next !== false && $next < $end) {
+ $offset = $next + 12;
+ $level++;
+ }
+ // nested </blockquote> tag
+ if ($end !== false && $level > 0) {
+ $offset = $end + 12;
$level--;
- if ($level < 0) {
- $level = 0; // malformed HTML: go to next blockquote
- }
- else if ($level > 0) {
- // skip inner blockquote
- }
- else {
- $end = $m[1];
- $len = $end - $taglen - $start;
- // Get blockquote content
- $body = substr($text, $start + $taglen - $diff, $len);
-
- // Set text width
- $p_width = $this->width;
- if ($this->width > 0) $this->width -= 2;
- // Convert blockquote content
- $body = trim($body);
- $this->_converter($body);
- // Add citation markers and create PRE block
- $body = preg_replace('/((^|\n)>*)/', '\\1> ', trim($body));
- $body = '<pre>' . htmlspecialchars($body) . '</pre>';
- // Re-set text width
- $this->width = $p_width;
- // Replace content
- $text = substr($text, 0, $start - $diff)
- . $body . substr($text, $end + strlen($m[0]) - $diff);
-
- $diff = $len + $taglen + strlen($m[0]) - strlen($body);
- unset($body);
- }
}
- else {
- if ($level == 0) {
- $start = $m[1];
- $taglen = strlen($m[0]);
- }
- $level ++;
+ // found matching end tag
+ else if ($end !== false && $level == 0) {
+ $taglen = strpos($text, '>', $start) - $start;
+ $startpos = $start + $taglen + 1;
+
+ // get blockquote content
+ $body = trim(substr($text, $startpos, $end - $startpos));
+
+ // adjust text wrapping width
+ $p_width = $this->width;
+ if ($this->width > 0) $this->width -= 2;
+
+ // replace content with inner blockquotes
+ $this->_converter($body);
+
+ // resore text width
+ $this->width = $p_width;
+
+ // Add citation markers and create <pre> block
+ $body = preg_replace_callback('/((?:^|\n)>*)([^\n]*)/', array($this, 'blockquote_citation_ballback'), trim($body));
+ $body = '<pre>' . htmlspecialchars($body) . '</pre>';
+
+ $text = substr($text, 0, $start) . $body . "\n" . substr($text, $end + 13);
+ $offset = 0;
+ break;
}
- }
+ } while ($end || $next);
}
}
/**
+ * Callback function to correctly add citation markers for blockquote contents
+ */
+ public function blockquote_citation_ballback($m)
+ {
+ $line = ltrim($m[2]);
+ $space = $line[0] == '>' ? '' : ' ';
+ return $m[1] . '>' . $space . $line;
+ }
+
+ /**
* Callback function for preg_replace_callback use.
*
* @param array PREG matches
diff --git a/lib/ext/Roundcube/rcube_image.php b/lib/ext/Roundcube/rcube_image.php
index 9695022..a55ba16 100644
--- a/lib/ext/Roundcube/rcube_image.php
+++ b/lib/ext/Roundcube/rcube_image.php
@@ -77,7 +77,8 @@ class rcube_image
}
/**
- * Resize image to a given size
+ * Resize image to a given size. Use only to shrink an image.
+ * If an image is smaller than specified size it will be not resized.
*
* @param int $size Max width/height size
* @param string $filename Output filename
@@ -131,19 +132,30 @@ class rcube_image
if ($props['gd_type']) {
if ($props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) {
$image = imagecreatefromjpeg($this->image_file);
+ $type = 'jpg';
}
else if($props['gd_type'] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) {
$image = imagecreatefromgif($this->image_file);
+ $type = 'gid';
}
else if($props['gd_type'] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) {
$image = imagecreatefrompng($this->image_file);
+ $type = 'png';
}
else {
// @TODO: print error to the log?
return false;
}
- $scale = $size / max($props['width'], $props['height']);
+ $scale = $size / max($props['width'], $props['height']);
+
+ // Imagemagick resize is implemented in shrinking mode (see -resize argument above)
+ // we do the same here, if an image is smaller than specified size
+ // we do nothing but copy original file to destination file
+ if ($scale > 1) {
+ return $this->image_file == $filename || copy($this->image_file, $filename) ? $type : false;
+ }
+
$width = $props['width'] * $scale;
$height = $props['height'] * $scale;
@@ -162,15 +174,12 @@ class rcube_image
if ($props['gd_type'] == IMAGETYPE_JPEG) {
$result = imagejpeg($image, $filename, 75);
- $type = 'jpg';
}
elseif($props['gd_type'] == IMAGETYPE_GIF) {
$result = imagegif($image, $filename);
- $type = 'gid';
}
elseif($props['gd_type'] == IMAGETYPE_PNG) {
$result = imagepng($image, $filename, 6, PNG_ALL_FILTERS);
- $type = 'png';
}
if ($result) {
@@ -245,6 +254,10 @@ class rcube_image
else if ($type == self::TYPE_PNG) {
$result = imagepng($image, $filename, 6, PNG_ALL_FILTERS);
}
+
+ if ($result) {
+ return true;
+ }
}
// @TODO: print error to the log?
diff --git a/lib/ext/Roundcube/rcube_imap.php b/lib/ext/Roundcube/rcube_imap.php
index 74c1f53..0aa059c 100644
--- a/lib/ext/Roundcube/rcube_imap.php
+++ b/lib/ext/Roundcube/rcube_imap.php
@@ -1096,16 +1096,17 @@ class rcube_imap extends rcube_storage
/**
- * Returns current status of folder
+ * Returns current status of a folder (compared to the last time use)
*
* We compare the maximum UID to determine the number of
* new messages because the RECENT flag is not reliable.
*
* @param string $folder Folder name
+ * @param array $diff Difference data
*
- * @return int Folder status
+ * @return int Folder status
*/
- public function folder_status($folder = null)
+ public function folder_status($folder = null, &$diff = array())
{
if (!strlen($folder)) {
$folder = $this->folder;
@@ -1126,6 +1127,9 @@ class rcube_imap extends rcube_storage
// got new messages
if ($new['maxuid'] > $old['maxuid']) {
$result += 1;
+ // get new message UIDs range, that can be used for example
+ // to get the data of these messages
+ $diff['new'] = ($old['maxuid'] + 1 < $new['maxuid'] ? ($old['maxuid']+1).':' : '') . $new['maxuid'];
}
// some messages has been deleted
if ($new['cnt'] < $old['cnt']) {
@@ -1634,9 +1638,15 @@ class rcube_imap extends rcube_storage
// Example of structure for malformed MIME message:
// ("text" "plain" NIL NIL NIL "7bit" 2154 70 NIL NIL NIL)
if ($headers->ctype && !is_array($structure[0]) && $headers->ctype != 'text/plain'
- && strtolower($structure[0].'/'.$structure[1]) == 'text/plain') {
+ && strtolower($structure[0].'/'.$structure[1]) == 'text/plain'
+ ) {
+ // A special known case "Content-type: text" (#1488968)
+ if ($headers->ctype == 'text') {
+ $structure[1] = 'plain';
+ $headers->ctype = 'text/plain';
+ }
// we can handle single-part messages, by simple fix in structure (#1486898)
- if (preg_match('/^(text|application)\/(.*)/', $headers->ctype, $m)) {
+ else if (preg_match('/^(text|application)\/(.*)/', $headers->ctype, $m)) {
$structure[0] = $m[1];
$structure[1] = $m[2];
}
@@ -1660,11 +1670,21 @@ class rcube_imap extends rcube_storage
$struct = $this->structure_part($structure, 0, '', $headers);
}
- // don't trust given content-type
- if (empty($struct->parts) && !empty($headers->ctype)) {
- $struct->mime_id = '1';
- $struct->mimetype = strtolower($headers->ctype);
- list($struct->ctype_primary, $struct->ctype_secondary) = explode('/', $struct->mimetype);
+ // some workarounds on simple messages...
+ if (empty($struct->parts)) {
+ // ...don't trust given content-type
+ if (!empty($headers->ctype)) {
+ $struct->mime_id = '1';
+ $struct->mimetype = strtolower($headers->ctype);
+ list($struct->ctype_primary, $struct->ctype_secondary) = explode('/', $struct->mimetype);
+ }
+
+ // ...and charset (there's a case described in #1488968 where invalid content-type
+ // results in invalid charset in BODYSTRUCTURE)
+ if (!empty($headers->charset) && $headers->charset != $struct->ctype_parameters['charset']) {
+ $struct->charset = $headers->charset;
+ $struct->ctype_parameters['charset'] = $headers->charset;
+ }
}
$headers->structure = $struct;
@@ -2317,10 +2337,7 @@ class rcube_imap extends rcube_storage
// move messages
$moved = $this->conn->move($uids, $from_mbox, $to_mbox);
- // send expunge command in order to have the moved message
- // really deleted from the source folder
if ($moved) {
- $this->expunge_message($uids, $from_mbox, false);
$this->clear_messagecount($from_mbox);
$this->clear_messagecount($to_mbox);
}
diff --git a/lib/ext/Roundcube/rcube_imap_cache.php b/lib/ext/Roundcube/rcube_imap_cache.php
index f33ac07..748474a 100644
--- a/lib/ext/Roundcube/rcube_imap_cache.php
+++ b/lib/ext/Roundcube/rcube_imap_cache.php
@@ -485,7 +485,7 @@ class rcube_imap_cache
.", flags = flags ".($enabled ? "+ $idx" : "- $idx")
." WHERE user_id = ?"
." AND mailbox = ?"
- .($uids !== null ? " AND uid IN (".$this->db->array2list($uids, 'integer').")" : "")
+ .(!empty($uids) ? " AND uid IN (".$this->db->array2list($uids, 'integer').")" : "")
." AND (flags & $idx) ".($enabled ? "= 0" : "= $idx"),
$this->userid, $mailbox);
}
diff --git a/lib/ext/Roundcube/rcube_imap_generic.php b/lib/ext/Roundcube/rcube_imap_generic.php
index 8d84bf7..2ac1355 100644
--- a/lib/ext/Roundcube/rcube_imap_generic.php
+++ b/lib/ext/Roundcube/rcube_imap_generic.php
@@ -906,7 +906,7 @@ class rcube_imap_generic
*/
function closeConnection()
{
- if ($this->putLine($this->nextTag() . ' LOGOUT')) {
+ if ($this->logged && $this->putLine($this->nextTag() . ' LOGOUT')) {
$this->readReply();
}
@@ -1065,8 +1065,8 @@ class rcube_imap_generic
/**
* Executes EXPUNGE command
*
- * @param string $mailbox Mailbox name
- * @param string $messages Message UIDs to expunge
+ * @param string $mailbox Mailbox name
+ * @param string|array $messages Message UIDs to expunge
*
* @return boolean True on success, False on error
*/
@@ -1084,10 +1084,13 @@ class rcube_imap_generic
// Clear internal status cache
unset($this->data['STATUS:'.$mailbox]);
- if ($messages)
- $result = $this->execute('UID EXPUNGE', array($messages), self::COMMAND_NORESPONSE);
- else
+ if (!empty($messages) && $messages != '*' && $this->hasCapability('UIDPLUS')) {
+ $messages = self::compressMessageSet($messages);
+ $result = $this->execute('UID EXPUNGE', array($messages), self::COMMAND_NORESPONSE);
+ }
+ else {
$result = $this->execute('EXPUNGE', null, self::COMMAND_NORESPONSE);
+ }
if ($result == self::ERROR_OK) {
$this->selected = null; // state has changed, need to reselect
@@ -1980,7 +1983,6 @@ class rcube_imap_generic
/**
* Moves message(s) from one folder to another.
- * Original message(s) will be marked as deleted.
*
* @param string|array $messages Message UID(s)
* @param string $from Mailbox name
@@ -1999,15 +2001,41 @@ class rcube_imap_generic
return false;
}
- $r = $this->copy($messages, $from, $to);
+ // use MOVE command (RFC 6851)
+ if ($this->hasCapability('MOVE')) {
+ // Clear last COPYUID data
+ unset($this->data['COPYUID']);
+
+ // Clear internal status cache
+ unset($this->data['STATUS:'.$to]);
+ unset($this->data['STATUS:'.$from]);
+
+ $result = $this->execute('UID MOVE', array(
+ $this->compressMessageSet($messages), $this->escape($to)),
+ self::COMMAND_NORESPONSE);
+
+ return ($result == self::ERROR_OK);
+ }
+
+ // use COPY + STORE +FLAGS.SILENT \Deleted + EXPUNGE
+ $result = $this->copy($messages, $from, $to);
- if ($r) {
+ if ($result) {
// Clear internal status cache
unset($this->data['STATUS:'.$from]);
- return $this->flag($from, $messages, 'DELETED');
+ $result = $this->flag($from, $messages, 'DELETED');
+
+ if ($messages == '*') {
+ // CLOSE+SELECT should be faster than EXPUNGE
+ $this->close();
+ }
+ else {
+ $this->expunge($from, $messages);
+ }
}
- return $r;
+
+ return $result;
}
/**
@@ -3502,7 +3530,7 @@ class rcube_imap_generic
// if less than 255 bytes long, let's not bother
if (!$force && strlen($messages)<255) {
return $messages;
- }
+ }
// see if it's already been compressed
if (strpos($messages, ':') !== false) {
diff --git a/lib/ext/Roundcube/rcube_ldap.php b/lib/ext/Roundcube/rcube_ldap.php
index 700c6f6..a2dd163 100644
--- a/lib/ext/Roundcube/rcube_ldap.php
+++ b/lib/ext/Roundcube/rcube_ldap.php
@@ -214,15 +214,16 @@ class rcube_ldap extends rcube_addressbook
if (empty($this->prop['ldap_version']))
$this->prop['ldap_version'] = 3;
- foreach ($this->prop['hosts'] as $host)
- {
+ // try to connect + bind for every host configured
+ // with OpenLDAP 2.x ldap_connect() always succeeds but ldap_bind will fail if host isn't reachable
+ // see http://www.php.net/manual/en/function.ldap-connect.php
+ foreach ($this->prop['hosts'] as $host) {
$host = rcube_utils::idn_to_ascii(rcube_utils::parse_host($host));
$hostname = $host.($this->prop['port'] ? ':'.$this->prop['port'] : '');
$this->_debug("C: Connect [$hostname] [{$this->prop['name']}]");
- if ($lc = @ldap_connect($host, $this->prop['port']))
- {
+ if ($lc = @ldap_connect($host, $this->prop['port'])) {
if ($this->prop['use_tls'] === true)
if (!ldap_start_tls($lc))
continue;
@@ -233,113 +234,124 @@ class rcube_ldap extends rcube_addressbook
$this->prop['host'] = $host;
$this->conn = $lc;
+ if (!empty($this->prop['network_timeout']))
+ ldap_set_option($lc, LDAP_OPT_NETWORK_TIMEOUT, $this->prop['network_timeout']);
+
if (isset($this->prop['referrals']))
ldap_set_option($lc, LDAP_OPT_REFERRALS, $this->prop['referrals']);
- break;
}
- $this->_debug("S: NOT OK");
- }
-
- // See if the directory is writeable.
- if ($this->prop['writable']) {
- $this->readonly = false;
- }
-
- if (!is_resource($this->conn)) {
- rcube::raise_error(array('code' => 100, 'type' => 'ldap',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Could not connect to any LDAP server, last tried $hostname"), true);
+ else {
+ $this->_debug("S: NOT OK");
+ continue;
+ }
- return false;
- }
+ // See if the directory is writeable.
+ if ($this->prop['writable']) {
+ $this->readonly = false;
+ }
- $bind_pass = $this->prop['bind_pass'];
- $bind_user = $this->prop['bind_user'];
- $bind_dn = $this->prop['bind_dn'];
+ $bind_pass = $this->prop['bind_pass'];
+ $bind_user = $this->prop['bind_user'];
+ $bind_dn = $this->prop['bind_dn'];
- $this->base_dn = $this->prop['base_dn'];
- $this->groups_base_dn = ($this->prop['groups']['base_dn']) ?
- $this->prop['groups']['base_dn'] : $this->base_dn;
+ $this->base_dn = $this->prop['base_dn'];
+ $this->groups_base_dn = ($this->prop['groups']['base_dn']) ?
+ $this->prop['groups']['base_dn'] : $this->base_dn;
- // User specific access, generate the proper values to use.
- if ($this->prop['user_specific']) {
- // No password set, use the session password
- if (empty($bind_pass)) {
- $bind_pass = $rcube->get_user_password();
- }
+ // User specific access, generate the proper values to use.
+ if ($this->prop['user_specific']) {
+ // No password set, use the session password
+ if (empty($bind_pass)) {
+ $bind_pass = $rcube->get_user_password();
+ }
- // Get the pieces needed for variable replacement.
- if ($fu = $rcube->get_user_email())
- list($u, $d) = explode('@', $fu);
- else
- $d = $this->mail_domain;
+ // Get the pieces needed for variable replacement.
+ if ($fu = $rcube->get_user_email())
+ list($u, $d) = explode('@', $fu);
+ else
+ $d = $this->mail_domain;
- $dc = 'dc='.strtr($d, array('.' => ',dc=')); // hierarchal domain string
+ $dc = 'dc='.strtr($d, array('.' => ',dc=')); // hierarchal domain string
- $replaces = array('%dn' => '', '%dc' => $dc, '%d' => $d, '%fu' => $fu, '%u' => $u);
+ $replaces = array('%dn' => '', '%dc' => $dc, '%d' => $d, '%fu' => $fu, '%u' => $u);
- if ($this->prop['search_base_dn'] && $this->prop['search_filter']) {
- if (!empty($this->prop['search_bind_dn']) && !empty($this->prop['search_bind_pw'])) {
- $this->bind($this->prop['search_bind_dn'], $this->prop['search_bind_pw']);
- }
+ if ($this->prop['search_base_dn'] && $this->prop['search_filter']) {
+ if (!empty($this->prop['search_bind_dn']) && !empty($this->prop['search_bind_pw'])) {
+ $this->bind($this->prop['search_bind_dn'], $this->prop['search_bind_pw']);
+ }
- // Search for the dn to use to authenticate
- $this->prop['search_base_dn'] = strtr($this->prop['search_base_dn'], $replaces);
- $this->prop['search_filter'] = strtr($this->prop['search_filter'], $replaces);
+ // Search for the dn to use to authenticate
+ $this->prop['search_base_dn'] = strtr($this->prop['search_base_dn'], $replaces);
+ $this->prop['search_filter'] = strtr($this->prop['search_filter'], $replaces);
- $this->_debug("S: searching with base {$this->prop['search_base_dn']} for {$this->prop['search_filter']}");
+ $this->_debug("S: searching with base {$this->prop['search_base_dn']} for {$this->prop['search_filter']}");
- $res = @ldap_search($this->conn, $this->prop['search_base_dn'], $this->prop['search_filter'], array('uid'));
- if ($res) {
- if (($entry = ldap_first_entry($this->conn, $res))
- && ($bind_dn = ldap_get_dn($this->conn, $entry))
- ) {
- $this->_debug("S: search returned dn: $bind_dn");
- $dn = ldap_explode_dn($bind_dn, 1);
- $replaces['%dn'] = $dn[0];
+ $res = @ldap_search($this->conn, $this->prop['search_base_dn'], $this->prop['search_filter'], array('uid'));
+ if ($res) {
+ if (($entry = ldap_first_entry($this->conn, $res))
+ && ($bind_dn = ldap_get_dn($this->conn, $entry))
+ ) {
+ $this->_debug("S: search returned dn: $bind_dn");
+ $dn = ldap_explode_dn($bind_dn, 1);
+ $replaces['%dn'] = $dn[0];
+ }
}
- }
- else {
- $this->_debug("S: ".ldap_error($this->conn));
- }
-
- // DN not found
- if (empty($replaces['%dn'])) {
- if (!empty($this->prop['search_dn_default']))
- $replaces['%dn'] = $this->prop['search_dn_default'];
else {
- rcube::raise_error(array(
- 'code' => 100, 'type' => 'ldap',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "DN not found using LDAP search."), true);
- return false;
+ $this->_debug("S: ".ldap_error($this->conn));
+ }
+
+ // DN not found
+ if (empty($replaces['%dn'])) {
+ if (!empty($this->prop['search_dn_default']))
+ $replaces['%dn'] = $this->prop['search_dn_default'];
+ else {
+ rcube::raise_error(array(
+ 'code' => 100, 'type' => 'ldap',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "DN not found using LDAP search."), true);
+ return false;
+ }
}
}
- }
- // Replace the bind_dn and base_dn variables.
- $bind_dn = strtr($bind_dn, $replaces);
- $this->base_dn = strtr($this->base_dn, $replaces);
- $this->groups_base_dn = strtr($this->groups_base_dn, $replaces);
+ // Replace the bind_dn and base_dn variables.
+ $bind_dn = strtr($bind_dn, $replaces);
+ $this->base_dn = strtr($this->base_dn, $replaces);
+ $this->groups_base_dn = strtr($this->groups_base_dn, $replaces);
- if (empty($bind_user)) {
- $bind_user = $u;
+ if (empty($bind_user)) {
+ $bind_user = $u;
+ }
}
- }
- if (empty($bind_pass)) {
- $this->ready = true;
- }
- else {
- if (!empty($bind_dn)) {
- $this->ready = $this->bind($bind_dn, $bind_pass);
- }
- else if (!empty($this->prop['auth_cid'])) {
- $this->ready = $this->sasl_bind($this->prop['auth_cid'], $bind_pass, $bind_user);
+ if (empty($bind_pass)) {
+ $this->ready = true;
}
else {
- $this->ready = $this->sasl_bind($bind_user, $bind_pass);
+ if (!empty($bind_dn)) {
+ $this->ready = $this->bind($bind_dn, $bind_pass);
+ }
+ else if (!empty($this->prop['auth_cid'])) {
+ $this->ready = $this->sasl_bind($this->prop['auth_cid'], $bind_pass, $bind_user);
+ }
+ else {
+ $this->ready = $this->sasl_bind($bind_user, $bind_pass);
+ }
}
+
+ // connection established, we're done here
+ if ($this->ready) {
+ break;
+ }
+
+ } // end foreach hosts
+
+ if (!is_resource($this->conn)) {
+ rcube::raise_error(array('code' => 100, 'type' => 'ldap',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Could not connect to any LDAP server, last tried $hostname"), true);
+
+ return false;
}
return $this->ready;
diff --git a/lib/ext/Roundcube/rcube_message.php b/lib/ext/Roundcube/rcube_message.php
index b52b79b..42d7b9b 100644
--- a/lib/ext/Roundcube/rcube_message.php
+++ b/lib/ext/Roundcube/rcube_message.php
@@ -93,7 +93,7 @@ class rcube_message
$this->subject = $this->mime->decode_mime_string($this->headers->subject);
list(, $this->sender) = each($this->mime->decode_address_list($this->headers->from, 1));
- $this->set_safe((intval($_GET['_safe']) || $_SESSION['safe_messages'][$uid]));
+ $this->set_safe((intval($_GET['_safe']) || $_SESSION['safe_messages'][$this->folder.':'.$uid]));
$this->opt = array(
'safe' => $this->is_safe,
'prefer_html' => $this->app->config->get('prefer_html'),
@@ -144,8 +144,7 @@ class rcube_message
*/
public function set_safe($safe = true)
{
- $this->is_safe = $safe;
- $_SESSION['safe_messages'][$this->uid] = $this->is_safe;
+ $_SESSION['safe_messages'][$this->folder.':'.$this->uid] = $this->is_safe = $safe;
}
@@ -194,39 +193,82 @@ class rcube_message
/**
- * Determine if the message contains a HTML part
+ * Determine if the message contains a HTML part. This must to be
+ * a real part not an attachment (or its part)
+ * This must to be
+ * a real part not an attachment (or its part)
*
- * @param bool $recursive Enables checking in all levels of the structure
- * @param bool $enriched Enables checking for text/enriched parts too
+ * @param bool $enriched Enables checking for text/enriched parts too
*
* @return bool True if a HTML is available, False if not
*/
- function has_html_part($recursive = true, $enriched = false)
+ function has_html_part($enriched = false)
{
// check all message parts
- foreach ($this->parts as $part) {
+ foreach ($this->mime_parts as $part) {
if ($part->mimetype == 'text/html' || ($enriched && $part->mimetype == 'text/enriched')) {
- // Level check, we'll skip e.g. HTML attachments
- if (!$recursive) {
- $level = explode('.', $part->mime_id);
+ // Skip if part is an attachment, don't use is_attachment() here
+ if ($part->filename) {
+ continue;
+ }
- // Skip if level too deep or part has a file name
- if (count($level) > 2 || $part->filename) {
- continue;
+ $level = explode('.', $part->mime_id);
+
+ // Check if the part belongs to higher-level's alternative/related
+ while (array_pop($level) !== null) {
+ if (!count($level)) {
+ return true;
}
- // HTML part can be on the lower level, if not...
- if (count($level) > 1) {
- array_pop($level);
- $parent = $this->mime_parts[join('.', $level)];
- // ... parent isn't multipart/alternative or related
- if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') {
- continue;
- }
+ $parent = $this->mime_parts[join('.', $level)];
+ if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') {
+ continue 2;
}
}
- return true;
+ if ($part->size) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Determine if the message contains a text/plain part. This must to be
+ * a real part not an attachment (or its part)
+ *
+ * @return bool True if a plain text part is available, False if not
+ */
+ function has_text_part()
+ {
+ // check all message parts
+ foreach ($this->mime_parts as $part) {
+ if ($part->mimetype == 'text/plain') {
+ // Skip if part is an attachment, don't use is_attachment() here
+ if ($part->filename) {
+ continue;
+ }
+
+ $level = explode('.', $part->mime_id);
+
+ // Check if the part belongs to higher-level's alternative/related
+ while (array_pop($level) !== null) {
+ if (!count($level)) {
+ return true;
+ }
+
+ $parent = $this->mime_parts[join('.', $level)];
+ if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') {
+ continue 2;
+ }
+ }
+
+ if ($part->size) {
+ return true;
+ }
}
}
@@ -321,7 +363,7 @@ class rcube_message
$mimetype = $structure->real_mimetype;
// parse headers from message/rfc822 part
- if (!isset($structure->headers['subject'])) {
+ if (!isset($structure->headers['subject']) && !isset($structure->headers['from'])) {
list($headers, $dump) = explode("\r\n\r\n", $this->get_part_content($structure->mime_id, null, true, 8192));
$structure->headers = rcube_mime::parse_headers($headers);
}
@@ -330,7 +372,7 @@ class rcube_message
$mimetype = $structure->mimetype;
// show message headers
- if ($recursive && is_array($structure->headers) && isset($structure->headers['subject'])) {
+ if ($recursive && is_array($structure->headers) && (isset($structure->headers['subject']) || isset($structure->headers['from']))) {
$c = new stdClass;
$c->type = 'headers';
$c->headers = $structure->headers;
@@ -468,6 +510,17 @@ class rcube_message
$this->parts[] = $p;
}
+ // this is an S/MIME ecrypted message -> create a plaintext body with the according message
+ else if ($mimetype == 'application/pkcs7-mime') {
+ $p = new stdClass;
+ $p->type = 'content';
+ $p->ctype_primary = 'text';
+ $p->ctype_secondary = 'plain';
+ $p->mimetype = 'text/plain';
+ $p->realtype = 'application/pkcs7-mime';
+
+ $this->parts[] = $p;
+ }
// message contains multiple parts
else if (is_array($structure->parts) && !empty($structure->parts)) {
// iterate over parts
@@ -605,7 +658,7 @@ class rcube_message
foreach ($this->inline_parts as $inline_object) {
$part_url = $this->get_part_url($inline_object->mime_id, true);
- if ($inline_object->content_id)
+ if (isset($inline_object->content_id))
$a_replaces['cid:'.$inline_object->content_id] = $part_url;
if ($inline_object->content_location) {
$a_replaces[$inline_object->content_location] = $part_url;
diff --git a/lib/ext/Roundcube/rcube_mime.php b/lib/ext/Roundcube/rcube_mime.php
index eef8ca1..2f24a1b 100644
--- a/lib/ext/Roundcube/rcube_mime.php
+++ b/lib/ext/Roundcube/rcube_mime.php
@@ -476,13 +476,19 @@ class rcube_mime
$q_level = 0;
foreach ($text as $idx => $line) {
- if ($line[0] == '>' && preg_match('/^(>+\s*)/', $line, $regs)) {
- $q = strlen(str_replace(' ', '', $regs[0]));
- $line = substr($line, strlen($regs[0]));
-
- if ($q == $q_level && $line
- && isset($text[$last])
- && $text[$last][strlen($text[$last])-1] == ' '
+ if ($line[0] == '>') {
+ // remove quote chars, store level in $q
+ $line = preg_replace('/^>+/', '', $line, -1, $q);
+ // remove (optional) space-staffing
+ $line = preg_replace('/^ /', '', $line);
+
+ // The same paragraph (We join current line with the previous one) when:
+ // - the same level of quoting
+ // - previous line was flowed
+ // - previous line contains more than only one single space (and quote char(s))
+ if ($q == $q_level
+ && isset($text[$last]) && $text[$last][strlen($text[$last])-1] == ' '
+ && !preg_match('/^>+ {0,1}$/', $text[$last])
) {
$text[$last] .= $line;
unset($text[$idx]);
@@ -535,10 +541,12 @@ class rcube_mime
foreach ($text as $idx => $line) {
if ($line != '-- ') {
- if ($line[0] == '>' && preg_match('/^(>+ {0,1})+/', $line, $regs)) {
- $level = substr_count($regs[0], '>');
+ if ($line[0] == '>') {
+ // remove quote chars, store level in $level
+ $line = preg_replace('/^>+/', '', $line, -1, $level);
+ // remove (optional) space-staffing and spaces before the line end
+ $line = preg_replace('/(^ | +$)/', '', $line);
$prefix = str_repeat('>', $level) . ' ';
- $line = rtrim(substr($line, strlen($regs[0])));
$line = $prefix . self::wordwrap($line, $length - $level - 2, " \r\n$prefix", false, $charset);
}
else if ($line) {
@@ -578,7 +586,7 @@ class rcube_mime
while (count($para)) {
$line = array_shift($para);
if ($line[0] == '>') {
- $string .= $line.$break;
+ $string .= $line . (count($para) ? $break : '');
continue;
}
diff --git a/lib/ext/Roundcube/rcube_plugin.php b/lib/ext/Roundcube/rcube_plugin.php
index 66e77cc..9ea0f73 100644
--- a/lib/ext/Roundcube/rcube_plugin.php
+++ b/lib/ext/Roundcube/rcube_plugin.php
@@ -237,7 +237,7 @@ abstract class rcube_plugin
/**
* Register this plugin to be responsible for a specific task
*
- * @param string $task Task name (only characters [a-z0-9_.-] are allowed)
+ * @param string $task Task name (only characters [a-z0-9_-] are allowed)
*/
public function register_task($task)
{
diff --git a/lib/ext/Roundcube/rcube_plugin_api.php b/lib/ext/Roundcube/rcube_plugin_api.php
index 8a4cce2..111c177 100644
--- a/lib/ext/Roundcube/rcube_plugin_api.php
+++ b/lib/ext/Roundcube/rcube_plugin_api.php
@@ -372,7 +372,7 @@ class rcube_plugin_api
/**
* Register this plugin to be responsible for a specific task
*
- * @param string $task Task name (only characters [a-z0-9_.-] are allowed)
+ * @param string $task Task name (only characters [a-z0-9_-] are allowed)
* @param string $owner Plugin name that registers this action
*/
public function register_task($task, $owner)
@@ -382,7 +382,7 @@ class rcube_plugin_api
return true;
}
- if ($task != asciiwords($task)) {
+ if ($task != asciiwords($task, true)) {
rcube::raise_error(array('code' => 526, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Invalid task name: $task."
diff --git a/lib/ext/Roundcube/rcube_result_set.php b/lib/ext/Roundcube/rcube_result_set.php
index 1391e5e..a4b070e 100644
--- a/lib/ext/Roundcube/rcube_result_set.php
+++ b/lib/ext/Roundcube/rcube_result_set.php
@@ -3,7 +3,7 @@
/*
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2006-2011, The Roundcube Dev Team |
+ | Copyright (C) 2006-2013, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -17,20 +17,22 @@
*/
/**
- * Roundcube result set class.
+ * Roundcube result set class
+ *
* Representing an address directory result set.
+ * Implenets Iterator and thus be used in foreach() loops.
*
* @package Framework
* @subpackage Addressbook
*/
-class rcube_result_set
+class rcube_result_set implements Iterator
{
- var $count = 0;
- var $first = 0;
- var $current = 0;
- var $searchonly = false;
- var $records = array();
+ public $count = 0;
+ public $first = 0;
+ public $searchonly = false;
+ public $records = array();
+ private $current = 0;
function __construct($c=0, $f=0)
{
@@ -51,18 +53,39 @@ class rcube_result_set
function first()
{
$this->current = 0;
- return $this->records[$this->current++];
+ return $this->records[$this->current];
+ }
+
+ function seek($i)
+ {
+ $this->current = $i;
+ }
+
+ /*** PHP 5 Iterator interface ***/
+
+ function rewind()
+ {
+ $this->current = 0;
+ }
+
+ function current()
+ {
+ return $this->records[$this->current];
+ }
+
+ function key()
+ {
+ return $this->current;
}
- // alias for iterate()
function next()
{
return $this->iterate();
}
- function seek($i)
+ function valid()
{
- $this->current = $i;
+ return isset($this->records[$this->current]);
}
}
diff --git a/lib/ext/Roundcube/rcube_session.php b/lib/ext/Roundcube/rcube_session.php
index 1aa5d58..82ff8a8 100644
--- a/lib/ext/Roundcube/rcube_session.php
+++ b/lib/ext/Roundcube/rcube_session.php
@@ -32,6 +32,7 @@ class rcube_session
private $ip;
private $start;
private $changed;
+ private $reloaded = false;
private $unsets = array();
private $gc_handlers = array();
private $cookiename = 'roundcube_sessauth';
@@ -200,8 +201,13 @@ class rcube_session
if ($oldvars !== null) {
$a_oldvars = $this->unserialize($oldvars);
if (is_array($a_oldvars)) {
- foreach ((array)$this->unsets as $k)
- unset($a_oldvars[$k]);
+ // remove unset keys on oldvars
+ foreach ((array)$this->unsets as $var) {
+ $path = explode('.', $var);
+ $k = array_pop($path);
+ $node = &$this->get_node($path, $a_oldvars);
+ unset($node[$k]);
+ }
$newvars = $this->serialize(array_merge(
(array)$a_oldvars, (array)$this->unserialize($vars)));
@@ -371,9 +377,32 @@ class rcube_session
/**
+ * Append the given value to the certain node in the session data array
+ *
+ * @param string Path denoting the session variable where to append the value
+ * @param string Key name under which to append the new value (use null for appending to an indexed list)
+ * @param mixed Value to append to the session data array
+ */
+ public function append($path, $key, $value)
+ {
+ // re-read session data from DB because it might be outdated
+ if (!$this->reloaded && microtime(true) - $this->start > 0.5) {
+ $this->reload();
+ $this->reloaded = true;
+ $this->start = microtime(true);
+ }
+
+ $node = &$this->get_node(explode('.', $path), $_SESSION);
+
+ if ($key !== null) $node[$key] = $value;
+ else $node[] = $value;
+ }
+
+
+ /**
* Unset a session variable
*
- * @param string Varibale name
+ * @param string Varibale name (can be a path denoting a certain node in the session array, e.g. compose.attachments.5)
* @return boolean True on success
*/
public function remove($var=null)
@@ -383,7 +412,11 @@ class rcube_session
}
$this->unsets[] = $var;
- unset($_SESSION[$var]);
+
+ $path = explode('.', $var);
+ $key = array_pop($path);
+ $node = &$this->get_node($path, $_SESSION);
+ unset($node[$key]);
return true;
}
@@ -415,6 +448,23 @@ class rcube_session
session_decode($data);
}
+ /**
+ * Returns a reference to the node in data array referenced by the given path.
+ * e.g. ['compose','attachments'] will return $_SESSION['compose']['attachments']
+ */
+ private function &get_node($path, &$data_arr)
+ {
+ $node = &$data_arr;
+ if (!empty($path)) {
+ foreach ((array)$path as $key) {
+ if (!isset($node[$key]))
+ $node[$key] = array();
+ $node = &$node[$key];
+ }
+ }
+
+ return $node;
+ }
/**
* Serialize session data
diff --git a/lib/ext/Roundcube/rcube_spellchecker.php b/lib/ext/Roundcube/rcube_spellchecker.php
index 3d4d3a3..816bcad 100644
--- a/lib/ext/Roundcube/rcube_spellchecker.php
+++ b/lib/ext/Roundcube/rcube_spellchecker.php
@@ -31,7 +31,7 @@ class rcube_spellchecker
private $lang;
private $rc;
private $error;
- private $separator = '/[\s\r\n\t\(\)\/\[\]{}<>\\"]+|[:;?!,\.]([^\w]|$)/';
+ private $separator = '/[\s\r\n\t\(\)\/\[\]{}<>\\"]+|[:;?!,\.](?=\W|$)/';
private $options = array();
private $dict;
private $have_dict;
diff --git a/lib/ext/Roundcube/rcube_storage.php b/lib/ext/Roundcube/rcube_storage.php
index 8a36f1f..700d12f 100644
--- a/lib/ext/Roundcube/rcube_storage.php
+++ b/lib/ext/Roundcube/rcube_storage.php
@@ -807,13 +807,14 @@ abstract class rcube_storage
/**
- * Returns current status of a folder
+ * Returns current status of a folder (compared to the last time use)
*
* @param string $folder Folder name
+ * @param array $diff Difference data
*
* @return int Folder status
*/
- abstract function folder_status($folder = null);
+ abstract function folder_status($folder = null, &$diff = array());
/**
diff --git a/lib/ext/Roundcube/rcube_utils.php b/lib/ext/Roundcube/rcube_utils.php
index 4b68711..1ae782a 100644
--- a/lib/ext/Roundcube/rcube_utils.php
+++ b/lib/ext/Roundcube/rcube_utils.php
@@ -156,7 +156,7 @@ class rcube_utils
{
// IPv6, but there's no build-in IPv6 support
if (strpos($ip, ':') !== false && !defined('AF_INET6')) {
- $parts = explode(':', $domain_part);
+ $parts = explode(':', $ip);
$count = count($parts);
if ($count > 8 || $count < 2) {
diff --git a/lib/ext/Roundcube/rcube_vcard.php b/lib/ext/Roundcube/rcube_vcard.php
index c2b30af..de28767 100644
--- a/lib/ext/Roundcube/rcube_vcard.php
+++ b/lib/ext/Roundcube/rcube_vcard.php
@@ -513,7 +513,7 @@ class rcube_vcard
*
* @return string Cleaned vcard block
*/
- private static function cleanup($vcard)
+ public static function cleanup($vcard)
{
// Convert special types (like Skype) to normal type='skype' classes with this simple regex ;)
$vcard = preg_replace(
diff --git a/lib/ext/Roundcube/rcube_washtml.php b/lib/ext/Roundcube/rcube_washtml.php
index 715c460..2a26141 100644
--- a/lib/ext/Roundcube/rcube_washtml.php
+++ b/lib/ext/Roundcube/rcube_washtml.php
@@ -240,7 +240,8 @@ class rcube_washtml
$value = $node->getAttribute($key);
if (isset($this->_html_attribs[$key]) ||
- ($key == 'href' && !preg_match('!^(javascript|vbscript|data:text)!i', $value)
+ ($key == 'href' && ($value = trim($value))
+ && !preg_match('!^(javascript|vbscript|data:text)!i', $value)
&& preg_match('!^([a-z][a-z0-9.+-]+:|//|#).+!i', $value))
) {
$t .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"';
diff --git a/lib/ext/tnef_decoder.php b/lib/ext/tnef_decoder.php
index 28d3689..e6ccc23 100644
--- a/lib/ext/tnef_decoder.php
+++ b/lib/ext/tnef_decoder.php
@@ -243,16 +243,16 @@ class tnef_decoder
/* Store any interesting attributes. */
switch ($attr_name) {
case self::MAPI_ATTACH_LONG_FILENAME:
+ $value = str_replace("\0", '', $value);
/* Used in preference to AFILENAME value. */
$attachment_data[0]['name'] = preg_replace('/.*[\/](.*)$/', '\1', $value);
- $attachment_data[0]['name'] = str_replace("\0", '', $attachment_data[0]['name']);
break;
case self::MAPI_ATTACH_MIME_TAG:
+ $value = str_replace("\0", '', $value);
/* Is this ever set, and what is format? */
- $attachment_data[0]['type'] = preg_replace('/^(.*)\/.*/', '\1', $value);
+ $attachment_data[0]['type'] = preg_replace('/^(.*)\/.*/', '\1', $value);
$attachment_data[0]['subtype'] = preg_replace('/.*\/(.*)$/', '\1', $value);
- $attachment_data[0]['subtype'] = str_replace("\0", '', $attachment_data[0]['subtype']);
break;
}
}
@@ -295,9 +295,10 @@ class tnef_decoder
break;
case self::AFILENAME:
+ $value = $this->_getx($data, $this->_geti($data, 32));
+ $value = str_replace("\0", '', $value);
/* Strip path. */
- $attachment_data[0]['name'] = preg_replace('/.*[\/](.*)$/', '\1', $this->_getx($data, $this->_geti($data, 32)));
- $attachment_data[0]['name'] = str_replace("\0", '', $attachment_data[0]['name']);
+ $attachment_data[0]['name'] = preg_replace('/.*[\/](.*)$/', '\1', $value);
/* Checksum */
$this->_geti($data, 16);
diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php
index 6959e71..f68609e 100644
--- a/lib/kolab_sync_data_email.php
+++ b/lib/kolab_sync_data_email.php
@@ -301,7 +301,7 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
// original body type
// @TODO: get this value from getMessageBody()
- $result['nativeBodyType'] = $message->has_html_part(false) ? 2 : 1;
+ $result['nativeBodyType'] = $message->has_html_part() ? 2 : 1;
// Message class
// @TODO: add messageClass suffix for encrypted messages
More information about the commits
mailing list