/**
  * update folder flags using condstore
  * 
  * @param Felamimail_Backend_ImapProxy $imap
  * @param Felamimail_Model_Folder $folder
  */
 protected function _updateCondstoreFlags($imap, Felamimail_Model_Folder $folder)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Folder supports condstore, fetching flags since last mod seq ' . $folder->imap_lastmodseq);
     }
     $flags = $imap->getChangedFlags($folder->imap_lastmodseq);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' got ' . count($flags) . ' changed flags');
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Flags: ' . print_r($flags, true));
     }
     if (!empty($flags)) {
         if (count($flags) <= $this->_flagSyncCountPerStep) {
             $filter = new Felamimail_Model_MessageFilter(array(array('field' => 'account_id', 'operator' => 'equals', 'value' => $folder->account_id), array('field' => 'folder_id', 'operator' => 'equals', 'value' => $folder->getId()), array('field' => 'messageuid', 'operator' => 'in', 'value' => array_keys($flags))));
             $messages = $this->_backend->search($filter);
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' got ' . count($messages) . ' messages.');
             }
             $this->_setFlagsOnCache($flags, $folder, $messages, false);
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Got too many changed flags. Maybe this is the initial load of the cache. Just updating last mod seq ...');
             }
         }
         foreach ($flags as $flag) {
             if ($folder->imap_lastmodseq < $flag['modseq']) {
                 $folder->imap_lastmodseq = $flag['modseq'];
             }
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Got ' . count($flags) . ' changed flags and updated last mod seq to ' . $folder->imap_lastmodseq);
         }
         $folder = Felamimail_Controller_Folder::getInstance()->update($folder);
     }
 }