/**
  * maybe there are some messages missing before $this->_imapMessageSequence
  * 
  * @param Felamimail_Model_Folder $_folder
  * @param Felamimail_Backend_ImapProxy $_imap
  */
 protected function _checkForMissingMessages(Felamimail_Model_Folder $_folder, Felamimail_Backend_ImapProxy $_imap)
 {
     if ($this->_messagesMissingFromCache($_folder)) {
         if ($this->_initialCacheStatus == Felamimail_Model_Folder::CACHE_STATUS_COMPLETE || $this->_initialCacheStatus == Felamimail_Model_Folder::CACHE_STATUS_EMPTY) {
             $_folder->cache_job_actions_est += $_folder->imap_totalcount - $_folder->cache_totalcount;
         }
         $_folder->cache_status = Felamimail_Model_Folder::CACHE_STATUS_INCOMPLETE;
         if ($this->_timeLeft()) {
             // add missing messages
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Retrieve message from {$_folder->imap_totalcount} to 1");
             }
             $begin = $_folder->cache_job_lowestuid > 0 ? $_folder->cache_job_lowestuid : $this->_imapMessageSequence;
             for ($i = $begin; $i > 0; $i -= $this->_importCountPerStep) {
                 $messageSequenceStart = $i - $this->_importCountPerStep > 0 ? $i - $this->_importCountPerStep : 1;
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Fetch message from {$messageSequenceStart} to {$i} {$this->_timeElapsed} / {$this->_availableUpdateTime}");
                 }
                 $messageUidsOnImapServer = $_imap->resolveMessageSequence($messageSequenceStart, $i);
                 $missingUids = $this->_getMissingMessageUids($_folder, $messageUidsOnImapServer);
                 if (count($missingUids) != 0) {
                     $messages = $_imap->getSummary($missingUids);
                     $this->_addMessagesToCacheAndIncreaseCounters($messages, $_folder);
                 }
                 if ($_folder->cache_totalcount == $_folder->imap_totalcount || $messageSequenceStart == 1) {
                     $_folder->cache_job_lowestuid = 0;
                     $_folder->cache_status = Felamimail_Model_Folder::CACHE_STATUS_UPDATING;
                     break;
                 }
                 if (!$this->_timeLeft()) {
                     $_folder->cache_job_lowestuid = $messageSequenceStart;
                     break;
                 }
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Folder cache status: ' . $_folder->cache_status);
             }
             if (defined('messageSequenceStart') && $messageSequenceStart === 1) {
                 $_folder->cache_status = Felamimail_Model_Folder::CACHE_STATUS_UPDATING;
             }
         }
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Cache status cache total count: {$_folder->cache_totalcount} imap total count: {$_folder->imap_totalcount} cache sequence: {$this->_cacheMessageSequence} imap sequence: {$this->_imapMessageSequence}");
     }
     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Folder cache status: ' . $_folder->cache_status);
 }