summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_data_email.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-09-03 10:43:37 (GMT)
committerAleksander Machniak <alec@alec.pl>2012-09-03 10:43:37 (GMT)
commit43cd411c0028193c704ca08c75c4bd873f055797 (patch)
treef26b862f1f78e34eb6ab563c5201636505fa77c7 /lib/kolab_sync_data_email.php
parent748290b81482bbd540de25a1f6c2584179ff1ab3 (diff)
downloadkolab-syncroton-43cd411c0028193c704ca08c75c4bd873f055797.tar.gz
Fixed email folders handling, fixed some minor issues
Diffstat (limited to 'lib/kolab_sync_data_email.php')
-rw-r--r--lib/kolab_sync_data_email.php106
1 files changed, 83 insertions, 23 deletions
diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php
index 3e97dae..22207a0 100644
--- a/lib/kolab_sync_data_email.php
+++ b/lib/kolab_sync_data_email.php
@@ -51,6 +51,19 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
);
/**
+ * Special folder type/name map
+ *
+ * @var array
+ */
+ protected $folder_types = array(
+ 2 => 'Inbox',
+ 3 => 'Drafts',
+ 4 => 'Deleted Items',
+ 5 => 'Sent Items',
+ 6 => 'Outbox',
+ );
+
+ /**
* Kolab object type
*
* @var string
@@ -388,21 +401,72 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
}
/**
- * Returns default folder for current class type.
- */
- protected function getDefaultFolder()
+ * Return list of supported folders for this backend
+ *
+ * @return array
+ */
+ public function getAllFolders()
{
- // There's always INBOX
- $real_id = $this->backend->folder_id('INBOX', 'mail.inbox');
- $folder_id = $this->defaultRootFolder;
+ $list = $this->backend->folders_list($this->device->deviceid, $this->modelName);
+
+ // device doesn't support multiple folders
+ if (!in_array(strtolower($this->device->devicetype), array('iphone', 'ipad', 'thundertine', 'windowsphone'))) {
+ // We'll return max. one folder of supported type
+ $result = array();
+ $types = $this->folder_types;
+
+ foreach ($list as $idx => $folder) {
+ if (isset($types[$folder['type']])) {
+ $folder_id = $types[$folder['type']];
+ $result[$folder_id] = array(
+ 'displayName' => $folder_id,
+ 'serverId' => $folder_id,
+ 'parentId' => 0,
+ 'type' => $folder['type'],
+ );
+ unset($types[$folder['type']]);
+ }
+ }
- return array(
- 'displayName' => 'Inbox',
- 'realid' => $real_id,
- 'serverId' => $folder_id,
- 'parentId' => 0,
- 'type' => $this->defaultFolderType,
- );
+ $list = $result;
+ }
+
+ foreach ($list as $idx => $folder) {
+ $list[$idx] = new Syncroton_Model_Folder($folder);
+ }
+
+ return $list;
+ }
+
+ /**
+ * Return list of folders for specified folder ID
+ *
+ * @return array Folder identifiers list
+ */
+ protected function extractFolders($folder_id)
+ {
+ $list = $this->backend->folders_list($this->device->deviceid, $this->modelName);
+ $result = array();
+
+ // device supports multiple folders?
+ if (in_array(strtolower($this->device->devicetype), array('iphone', 'ipad', 'thundertine', 'windowsphone'))) {
+ if ($list[$folder_id]) {
+ $result[] = $folder_id;
+ }
+ }
+ else if ($type = array_search($folder_id, $this->folder_types)) {
+ foreach ($list as $id => $folder) {
+ if ($folder['type'] == $type || ($folder_id == 'Inbox' && $folder['type'] == 12)) {
+ $result[] = $id;
+ }
+ }
+ }
+
+ if (empty($result)) {
+ throw new Syncroton_Exception_NotFound('Folder not found');
+ }
+
+ return $result;
}
/**
@@ -418,7 +482,8 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
public function moveItem($srcFolderId, $serverId, $dstFolderId)
{
$msg = $this->parseMessageId($serverId);
- $dstname = $this->backend->folder_id2name($dstFolderId, $this->device->deviceid);
+ $dest = $this->extractFolders($dstFolderId);
+ $dstname = $this->backend->folder_id2name(array_shift($dest), $this->device->deviceid);
if (empty($msg)) {
throw new Syncroton_Exception_Status_MoveItems(Syncroton_Exception_Status_MoveItems::INVALID_SOURCE);
@@ -652,14 +717,7 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
*/
protected function searchEntries($folderid, $filter = array(), $result_type = self::RESULT_UID)
{
- if ($folderid == $this->defaultRootFolder) {
- $folders = $this->backend->folders_list($this->device->deviceid, $this->modelName);
- $folders = array_keys($folders);
- }
- else {
- $folders = array($folderid);
- }
-
+ $folders = $this->extractFolders($folderid);
$filter_str = 'ALL UNDELETED';
// convert filter into one IMAP search string
@@ -799,7 +857,9 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
}
if (!empty($query['and']['collections'])) {
- $folders[] = $query['and']['collections'];
+ foreach ($query['and']['collections'] as $collection) {
+ $folders = array_merge($folders, $this->extractFolders($collection));
+ }
}
if (!empty($query['and']['greaterThan'])