/**
  * test clear message cache
  *
  */
 public function testClear()
 {
     $this->_controller->clear($this->_folder);
     $messageCacheBackend = new Expressomail_Backend_Cache_Sql_Message();
     $count = $messageCacheBackend->searchCountByFolderId($this->_folder->getId());
     // check if empty
     $this->assertEquals(0, $count);
     $this->assertEquals(Expressomail_Model_Folder::CACHE_STATUS_EMPTY, $this->_folder->cache_status);
     $this->assertEquals(0, $this->_folder->cache_job_actions_est);
 }
 /**
  * update folder quota (check if server supports QUOTA first)
  * 
  * @param Felamimail_Model_Folder $_folder
  * @param Felamimail_Backend_ImapProxy $_imap
  */
 protected function _updateFolderQuota(Felamimail_Model_Folder $_folder, Felamimail_Backend_ImapProxy $_imap)
 {
     // only do it for INBOX
     if ($_folder->localname !== 'INBOX') {
         return;
     }
     $account = Felamimail_Controller_Account::getInstance()->get($_folder->account_id);
     if (!$account->hasCapability('QUOTA')) {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Account ' . $account->name . ' has no QUOTA capability');
         }
         return;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Getting quota for INBOX ' . $_folder->getId());
     }
     // get quota and save in folder
     $quota = $_imap->getQuota($_folder->localname);
     if (!empty($quota) && isset($quota['STORAGE'])) {
         $_folder->quota_usage = $quota['STORAGE']['usage'];
         $_folder->quota_limit = $quota['STORAGE']['limit'];
     } else {
         $_folder->quota_usage = 0;
         $_folder->quota_limit = 0;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($quota, TRUE));
     }
 }
 /**
  * get Syncroton_Model_Folder folders recursively by parentFolder
  * 
  * @param Felamimail_Model_Folder $parentFolder
  * @param array $result
  * @return array of Syncroton_Model_Folder
  */
 protected function _getFolders($parentFolder = NULL, &$result = array())
 {
     $globalname = $parentFolder ? $parentFolder->globalname : '';
     $account = $this->_getAccount();
     if (!$account) {
         return array();
     }
     $filter = new Felamimail_Model_FolderFilter(array(array('field' => 'globalname', 'operator' => 'startswith', 'value' => $globalname), array('field' => 'account_id', 'operator' => 'equals', 'value' => $account->getId())));
     try {
         $folders = Felamimail_Controller_Folder::getInstance()->search($filter);
     } catch (Felamimail_Exception_IMAPInvalidCredentials $feiic) {
         Tinebase_Exception::log($feiic, null, array('accountname' => $account->name));
         return array();
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Found " . count($folders) . ' subfolders of folder "' . $globalname . '"');
     }
     foreach ($folders as $folder) {
         $result[$folder->getId()] = new Syncroton_Model_Folder(array('serverId' => $folder->getId(), 'parentId' => $parentFolder ? $parentFolder->getId() : 0, 'displayName' => $folder->localname, 'type' => $this->_getFolderType($folder)));
         if ($folder->has_children) {
             $this->_getFolders($folder, $result);
         }
     }
     return $result;
 }
 /**
  * move messages from one folder to another
  * 
  * @param Tinebase_Record_RecordSet $_messages
  * @param string $_folderId
  * @param Felamimail_Model_Folder|string $_targetFolder
  * @return boolean did we move messages?
  */
 protected function _moveMessagesByFolder(Tinebase_Record_RecordSet $_messages, $_folderId, $_targetFolder)
 {
     $messagesInFolder = $_messages->filter('folder_id', $_folderId);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Moving messages: ' . print_r($messagesInFolder->getArrayOfIds(), TRUE));
     }
     $result = TRUE;
     if ($_targetFolder === Felamimail_Model_Folder::FOLDER_TRASH) {
         $result = $this->_moveMessagesToTrash($messagesInFolder, $_folderId);
     } else {
         if ($_folderId === $_targetFolder->getId()) {
             // no need to move
             $result = FALSE;
         } else {
             if ($messagesInFolder->getFirstRecord()->account_id == $_targetFolder->account_id) {
                 $this->_moveMessagesInFolderOnSameAccount($messagesInFolder, $_targetFolder);
             } else {
                 $this->_moveMessagesToAnotherAccount($messagesInFolder, $_targetFolder);
             }
         }
     }
     if (!$result) {
         $_messages->removeRecords($messagesInFolder);
     }
     return $result;
 }