diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php --- a/lib/kolab_sync_data_email.php +++ b/lib/kolab_sync_data_email.php @@ -602,30 +602,34 @@ */ public function updateEntry($folderId, $serverId, Syncroton_Model_IEntry $entry) { - $msg = $this->parseMessageId($serverId); - $message = $this->getObject($serverId); + $msg = $this->parseMessageId($serverId); - if (empty($message)) { + if (empty($msg)) { throw new Syncroton_Exception_Status_Sync(Syncroton_Exception_Status_Sync::SYNC_SERVER_ERROR); } - $is_flagged = !empty($message->headers->flags['FLAGGED']); + if (isset($entry->categories)) { + // Read the message headers only when they are needed + $message = $this->getObject($serverId); + + if (empty($message)) { + throw new Syncroton_Exception_Status_Sync(Syncroton_Exception_Status_Sync::SYNC_SERVER_ERROR); + } + } // Read status change if (isset($entry->read)) { // here we update only Read flag - $flag = (((int)$entry->read != 1) ? 'UN' : '') . 'SEEN'; + $flag = !empty($entry->read) ? 'SEEN' : 'UNSEEN'; $this->storage->set_flag($msg['uid'], $flag, $msg['foldername']); } // Flag change - if (isset($entry->flag) && (empty($entry->flag) || empty($entry->flag->flagType))) { - if ($is_flagged) { + if (isset($entry->flag)) { + if (empty($entry->flag) || empty($entry->flag->flagType)) { $this->storage->set_flag($msg['uid'], 'UNFLAGGED', $msg['foldername']); } - } - else if (!$is_flagged && !empty($entry->flag)) { - if ($entry->flag->flagType && preg_match('/follow\s*up/i', $entry->flag->flagType)) { + else if (preg_match('/follow\s*up/i', $entry->flag->flagType)) { $this->storage->set_flag($msg['uid'], 'FLAGGED', $msg['foldername']); } }