/**
  *
  * @param Expressomail_Backend_ImapProxy $_imap
  * @param type $_ids
  * @param type $_folderId
  * @return type 
  */
 protected function _getSummary(Expressomail_Backend_ImapProxy $_imap, $_ids, $_folderId)
 {
     $return = array();
     $pos = 0;
     $last = count($_ids) - 1;
     do {
         $ids = array_slice($_ids, $pos, 1000);
         $return = empty($return) ? $_imap->getSummary($ids, null, null, $_folderId) : array_merge($return, $_imap->getSummary($ids, null, null, $_folderId));
         $pos += count($ids);
     } while ($pos < $last);
     return $return;
 }
 /**
  * move messages on imap server
  * 
  * @param array $_uids
  * @param string $_targetFolderName
  * @param Expressomail_Backend_ImapProxy $_imap
  * 
  * @todo perhaps we should check the existance of the messages on the imap instead of catching the exceptions here
  */
 protected function _moveBatchOfMessages($_uids, $_targetFolderName, Expressomail_Backend_ImapProxy $_imap)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Move ' . count($_uids) . ' messages to folder ' . $_targetFolderName . ' on imap server');
     }
     try {
         $_imap->copyMessage($_uids, Expressomail_Model_Folder::encodeFolderName($_targetFolderName));
         $_imap->addFlags($_uids, array(Zend_Mail_Storage::FLAG_DELETED));
     } catch (Zend_Mail_Storage_Exception $zmse) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $zmse);
         }
     } catch (Expressomail_Exception_IMAP $fei) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $fei);
         }
     }
 }
 /**
  * add/clear flags on imap server
  *
  * @param array $_imapMessageUids
  * @param array $_flags
  * @param Expressomail_Backend_ImapProxy $_imapBackend
  * @throws Expressomail_Exception_IMAP
  */
 protected function _updateFlagsOnImap($_imapMessageUids, $_flags, $_imapBackend, $_mode)
 {
     $flagsToChange = array_intersect($_flags, array_keys(self::$_allowedFlags));
     if (empty($flagsToChange)) {
         return;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mode . 'ing flags on IMAP server for ' . print_r($_imapMessageUids, TRUE) . ' messages:' . print_r($flagsToChange, TRUE));
     }
     try {
         if ($_mode === 'add') {
             $_imapBackend->addFlags($_imapMessageUids, $flagsToChange);
         } else {
             if ($_mode === 'clear') {
                 $_imapBackend->clearFlags($_imapMessageUids, $flagsToChange);
             }
         }
     } catch (Zend_Mail_Storage_Exception $zmse) {
         throw new Expressomail_Exception_IMAP($zmse->getMessage());
     }
 }