summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_data_email.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-10-09 09:43:08 (GMT)
committerAleksander Machniak <alec@alec.pl>2012-10-09 09:43:08 (GMT)
commit5fd57443fcefac69be20016d618e1a9df0ef8f1e (patch)
treecb3fbf2cc280e128f76c03644f3e09a721bb357d /lib/kolab_sync_data_email.php
parent607f8b195acf08c17a22885ca0dd75b6e17de981 (diff)
downloadkolab-syncroton-5fd57443fcefac69be20016d618e1a9df0ef8f1e.tar.gz
Improve backend errors handling (Bug #1088)
Diffstat (limited to 'lib/kolab_sync_data_email.php')
-rw-r--r--lib/kolab_sync_data_email.php45
1 files changed, 41 insertions, 4 deletions
diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php
index a041d7f..e197b23 100644
--- a/lib/kolab_sync_data_email.php
+++ b/lib/kolab_sync_data_email.php
@@ -409,6 +409,10 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
{
$list = $this->backend->folders_list($this->device->deviceid, $this->modelName);
+ if (!is_array($list)) {
+ throw new Syncroton_Exception_Status_FolderSync(Syncroton_Esception_Status_FolderSync::FOLDER_SERVER_ERROR);
+ }
+
// 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
@@ -448,6 +452,10 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$list = $this->backend->folders_list($this->device->deviceid, $this->modelName);
$result = array();
+ if (!is_array($list)) {
+ throw new Syncroton_Exception_NotFound('Folder not found');
+ }
+
// device supports multiple folders?
if (in_array(strtolower($this->device->devicetype), array('iphone', 'ipad', 'thundertine', 'windowsphone'))) {
if ($list[$folder_id]) {
@@ -527,8 +535,13 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
*/
public function updateEntry($folderId, $serverId, Syncroton_Model_IEntry $entry)
{
- $msg = $this->parseMessageId($serverId);
- $message = $this->getObject($serverId);
+ $msg = $this->parseMessageId($serverId);
+ $message = $this->getObject($serverId);
+
+ if (empty($message)) {
+ throw new Syncroton_Exception_Status_Sync(Syncroton_Exception_Status_Sync::SYNC_SERVER_ERROR);
+ }
+
$is_flagged = !empty($message->headers->flags['FLAGGED']);
// Read status change
@@ -563,6 +576,10 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$trash = kolab_sync::get_instance()->config->get('trash_mbox');
$msg = $this->parseMessageId($serverId);
+ if (empty($msg)) {
+ throw new Syncroton_Exception_Status_Sync(Syncroton_Exception_Status_Sync::SYNC_SERVER_ERROR);
+ }
+
// move message to trash folder
if ($collection->deletesAsMoves
&& strlen($trash)
@@ -632,6 +649,10 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$msg = $this->parseMessageId($itemId);
$message = $this->getObject($itemId);
+ if (!$message) {
+ throw new Syncroton_Exception_Status(Syncroton_Exception_Status::ITEM_NOT_FOUND);
+ }
+
// Parse message
list($headers, $body) = $this->backend->parse_mime($body, true);
@@ -677,6 +698,10 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$msg = $this->parseMessageId($itemId);
$message = $this->getObject($itemId);
+ if (!$message) {
+ throw new Syncroton_Exception_Status(Syncroton_Exception_Status::ITEM_NOT_FOUND);
+ }
+
// Parse message
// @TODO: messages with attachments
list($headers, $body) = $this->backend->parse_mime($body, true);
@@ -799,6 +824,10 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
throw new Exception('Empty/invalid search request');
}
+ if (!is_array($folders)) {
+ throw new Syncroton_Exception_Status(Syncroton_Exception_Status::SERVER_ERROR);
+ }
+
$result = array();
// no sorting for best performance
$sort_by = null;
@@ -928,7 +957,10 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
// @TODO: DeepTraversal
if (empty($folders)) {
$folders = $this->backend->folders_list($this->device->deviceid, $this->modelName);
- $folders = array_keys($folders);
+
+ if (is_array($folders)) {
+ $folders = array_keys($folders);
+ }
}
return array($folders, $search_str);
@@ -962,7 +994,12 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
{
list($folderid, $uid, $part_id) = explode('::', $fileReference);
- $message = $this->getObject($fileReference);
+ $message = $this->getObject($fileReference);
+
+ if (!$message) {
+ throw new Syncroton_Exception_NotFound('Message not found');
+ }
+
$part = $message->mime_parts[$part_id];
$body = $message->get_part_content($part_id);
$content_type = $part->mimetype;