Ejemplo n.º 1
0
 /**
  * try to lock a folder
  *
  * @param  Felamimail_Model_Folder  $_folder  the folder to lock
  * @return bool  true if locking was successful, false if locking was not possible
  */
 public function lockFolder(Felamimail_Model_Folder $_folder)
 {
     $folderData = $_folder->toArray();
     $data = array('cache_timestamp' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'cache_status' => Felamimail_Model_Folder::CACHE_STATUS_UPDATING);
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $folderData['id']), $this->_db->quoteInto($this->_db->quoteIdentifier('cache_status') . ' = ?', $folderData['cache_status']));
     if (!empty($folderData['cache_timestamp'])) {
         $where[] = $this->_db->quoteInto($this->_db->quoteIdentifier('cache_timestamp') . ' = ?', $folderData['cache_timestamp']);
     }
     $affectedRows = $this->_db->update($this->_tablePrefix . $this->_tableName, $data, $where);
     if ($affectedRows !== 1) {
         return false;
     }
     return true;
 }
 /**
  * create new folders or get existing folders from db and return record set
  *
  * @param array $_folders
  * @param Felamimail_Model_Account $_account
  * @param string $_parentFolder
  * @return Tinebase_Record_RecordSet of Felamimail_Model_Folder
  * 
  * @todo    move delete sync to extra function
  */
 protected function _getOrCreateFolders(array $_folders, $_account, $_parentFolder)
 {
     $parentFolder = $_parentFolder !== NULL ? $_parentFolder : '';
     $result = new Tinebase_Record_RecordSet('Felamimail_Model_Folder');
     $systemFolders = Felamimail_Controller_Folder::getInstance()->getSystemFolders($_account);
     // get configured account standard folders here
     if (strtolower($_account->sent_folder) != $systemFolders[2]) {
         $systemFolders[2] = strtolower($_account->sent_folder);
     }
     if (strtolower($_account->trash_folder) != $systemFolders[5]) {
         $systemFolders[5] = strtolower($_account->trash_folder);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_folders, TRUE));
     }
     // do some mapping and save folder in db (if it doesn't exist
     foreach ($_folders as $folderData) {
         try {
             $folderData['localName'] = Felamimail_Model_Folder::decodeFolderName($folderData['localName']);
             $folderData['globalName'] = Felamimail_Model_Folder::decodeFolderName($folderData['globalName']);
             $isSelectable = $this->_isSelectable($folderData, $_account);
             $folder = Felamimail_Controller_Folder::getInstance()->getByBackendAndGlobalName($_account->getId(), $folderData['globalName']);
             $folder->is_selectable = $isSelectable;
             $folder->supports_condstore = $this->_supportsCondStore($folder, $_account);
             $folder->imap_status = Felamimail_Model_Folder::IMAP_STATUS_OK;
             $folder->has_children = $folderData['hasChildren'] == '1';
             $folder->parent = $parentFolder;
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Update cached folder ' . $folderData['globalName']);
             }
         } catch (Tinebase_Exception_NotFound $tenf) {
             // create new folder
             if (empty($folderData['localName'])) {
                 // skip
                 if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Do not add folder ' . $folderData['globalName'] . '. Localname is empty.');
                 }
                 continue;
             } else {
                 $delimiter = strlen($folderData['delimiter']) === 1 ? $folderData['delimiter'] : '';
                 $folder = new Felamimail_Model_Folder(array('localname' => $folderData['localName'], 'globalname' => $folderData['globalName'], 'is_selectable' => $isSelectable, 'supports_condstore' => $this->_supportsCondStore($folderData['globalName'], $_account), 'has_children' => $folderData['hasChildren'] == '1', 'account_id' => $_account->getId(), 'imap_timestamp' => Tinebase_DateTime::now(), 'imap_status' => Felamimail_Model_Folder::IMAP_STATUS_OK, 'user_id' => Tinebase_Core::getUser()->getId(), 'parent' => $parentFolder, 'system_folder' => in_array(strtolower($folderData['localName']), $systemFolders), 'delimiter' => $delimiter));
                 // update delimiter setting of account
                 if ($folder->delimiter && $folder->delimiter !== $_account->delimiter && $folder->localname === 'INBOX') {
                     $_account->delimiter = $folder->delimiter;
                     $_account = Felamimail_Controller_Account::getInstance()->update($_account);
                 }
                 if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Adding new folder ' . $folderData['globalName'] . ' to cache.');
                 }
                 if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                     Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . print_r($folder->toArray(), true));
                 }
                 $folder = $this->_backend->create($folder);
             }
         }
         $result->addRecord($folder);
     }
     if (count($_folders) > 0) {
         $this->_removeFromCache($_account, $parentFolder, $result->getArrayOfIds());
     }
     return $result;
 }
 /**
  * expunge cache folder
  * 
  * @param Felamimail_Model_Folder $_folder
  * @param Felamimail_Backend_ImapProxy $_imap
  * @throws Felamimail_Exception_IMAPFolderNotFound
  */
 protected function _expungeCacheFolder(Felamimail_Model_Folder $_folder, Felamimail_Backend_ImapProxy $_imap)
 {
     try {
         $_imap->expunge(Felamimail_Model_Folder::encodeFolderName($_folder->globalname));
     } catch (Zend_Mail_Storage_Exception $zmse) {
         Tinebase_Exception::log($zmse);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Marking folder as not selectable: ' . print_r($_folder->toArray(), true));
         }
         // mark folder as not selectable + finish cache update
         $_folder->is_selectable = 0;
         $_folder->cache_status = Felamimail_Model_Folder::CACHE_STATUS_COMPLETE;
         $_folder = Felamimail_Controller_Folder::getInstance()->update($_folder);
         // @todo check if folder is really deleted?
         //Felamimail_Controller_Cache_Folder::getInstance()->delete($_folder->getId());
         throw new Felamimail_Exception_IMAPFolderNotFound('Folder not found / is not selectable: ' . $_folder->globalname);
     }
 }