Exemplo 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;
 }
 /**
  * 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);
 }
 /**
  * check if folder is selectable: try to select folder on imap server if isSelectable is false/not set
  * - courier imap servers subfolder have isSelectable = 0 but they still can be selected 
  *   @see http://www.tine20.org/bugtracker/view.php?id=2736
  * 
  * @param array $_folderData
  * @param Felamimail_Model_Account $_account
  * @return boolean
  */
 protected function _isSelectable($_folderData, $_account)
 {
     $result = TRUE;
     if (!$_folderData['isSelectable'] == '1') {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Folder ' . $_folderData['globalName'] . ' is not selectable.');
         }
         $imap = Felamimail_Backend_ImapFactory::factory($_account);
         try {
             $folderData = $imap->examineFolder(Felamimail_Model_Folder::encodeFolderName($_folderData['globalName']));
         } catch (Zend_Mail_Storage_Exception $zmse) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Could not select folder. Skipping it.');
             }
             $result = FALSE;
         }
     }
     return $result;
 }
 /**
  * test folder status of deleted folder
  *
  * @see 0007134: getFolderStatus should ignore non-existent folders
  */
 public function testGetFolderStatusOfDeletedFolder()
 {
     $this->testCreateFolders();
     // remove one of the created folders
     $removedFolder = $this->_createdFolders[0];
     $this->_imap->removeFolder(Felamimail_Model_Folder::encodeFolderName($removedFolder));
     $status = $this->_json->getFolderStatus(array(array('field' => 'account_id', 'operator' => 'equals', 'value' => $this->_account->getId())));
     $this->assertGreaterThan(2, count($status), 'Expected more than 2 folders that need an update: ' . print_r($status, TRUE));
     foreach ($status as $folder) {
         if ($folder['globalname'] == $removedFolder) {
             $this->fail('removed folder should not appear in status array!');
         }
     }
 }
 /**
  * append mail to send folder
  * 
  * @param Felamimail_Transport $_transport
  * @param Felamimail_Model_Account $_account
  * @param array $_additionalHeaders
  * @return void
  */
 protected function _saveInSent(Felamimail_Transport $_transport, Felamimail_Model_Account $_account, $_additionalHeaders = array())
 {
     try {
         $mailAsString = $_transport->getRawMessage(NULL, $_additionalHeaders);
         $sentFolder = Felamimail_Controller_Account::getInstance()->getSystemFolder($_account, Felamimail_Model_Folder::FOLDER_SENT);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' About to save message in sent folder (' . $sentFolder->globalname . ') ...');
         }
         Felamimail_Backend_ImapFactory::factory($_account)->appendMessage($mailAsString, Felamimail_Model_Folder::encodeFolderName($sentFolder->globalname));
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Saved sent message in "' . $sentFolder->globalname . '".');
     } catch (Zend_Mail_Protocol_Exception $zmpe) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not save sent message in "' . $sentFolder->globalname . '".' . ' Please check if a folder with this name exists.' . '(' . $zmpe->getMessage() . ')');
     } catch (Zend_Mail_Storage_Exception $zmse) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not save sent message in "' . $sentFolder->globalname . '".' . ' Please check if a folder with this name exists.' . '(' . $zmse->getMessage() . ')');
     }
 }
Exemplo n.º 6
0
 /**
  * create new system folder
  * 
  * @param Felamimail_Model_Account $_account
  * @param string $_systemFolder
  * @return Felamimail_Model_Folder
  */
 protected function _createSystemFolder(Felamimail_Model_Account $_account, $_systemFolder)
 {
     Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Folder not found: ' . $_systemFolder . '. Trying to add it.');
     $splitFolderName = Felamimail_Model_Folder::extractLocalnameAndParent($_systemFolder, $_account->delimiter);
     try {
         $result = Felamimail_Controller_Folder::getInstance()->create($_account, $splitFolderName['localname'], $splitFolderName['parent']);
     } catch (Felamimail_Exception_IMAPServiceUnavailable $feisu) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $feisu->getMessage());
         }
         // try again with INBOX as parent because some IMAP servers can not handle namespaces correctly
         $result = Felamimail_Controller_Folder::getInstance()->create($_account, $splitFolderName['localname'], 'INBOX');
     }
     return $result;
 }
Exemplo n.º 7
0
 /**
  * Gets one entry (by id)
  *
  * @param string $_id
  * @param $_getDeleted get deleted records
  * @return Tinebase_Record_Interface
  * @throws Tinebase_Exception_NotFound
  */
 public function get($_id, $_getDeleted = FALSE)
 {
     $folderDecoded = self::decodeFolderUid($_id);
     try {
         $imap = Felamimail_Backend_ImapFactory::factory($folderDecoded['accountId']);
         $folder = $imap->getFolders('', $folderDecoded['globalName']);
         $counter = $imap->examineFolder($folderDecoded['globalName']);
         $status = $imap->getFolderStatus($folderDecoded['globalName']);
         $quota = $imap->getQuota($folderDecoded['globalName']);
     } catch (Zend_Mail_Storage_Exception $ex) {
         // we can not access folder, create Model as unselectable
         $globalname = $folderDecoded['globalName'];
         $localname = array_pop(explode(self::IMAPDELIMITER, $globalname));
         $translate = Tinebase_Translation::getTranslation("Felamimail");
         return new Felamimail_Model_Folder(array('id' => $_id, 'account_id' => Tinebase_Core::getPreference('Felamimail')->{Felamimail_Preference::DEFAULTACCOUNT}, 'localname' => $localname == 'user' ? $translate->_("Shared Folders") : $localname, 'globalname' => $folderDecoded['globalName'], 'parent' => $globalname === 'user' ? '' : substr($globalname, 0, strrpos($globalname, self::IMAPDELIMITER)), 'delimiter' => self::IMAPDELIMITER, 'is_selectable' => 0, 'has_children' => 1, 'system_folder' => 1, 'imap_status' => Felamimail_Model_Folder::IMAP_STATUS_OK, 'imap_timestamp' => Tinebase_DateTime::now(), 'cache_status' => 'complete', 'cache_timestamp' => Tinebase_DateTime::now(), 'cache_job_lowestuid' => 0, 'cache_job_startuid' => 0, 'cache_job_actions_est' => 0, 'cache_job_actions_done' => 0));
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . $ex->getMessage());
         }
     }
     $globalName = $folderDecoded['globalName'];
     if ($globalName == 'INBOX' || $globalName == 'user') {
         $folder[$folderDecoded['globalName']]['parent'] = '';
     } else {
         $folder[$folderDecoded['globalName']]['parent'] = substr($globalName, 0, strrpos($globalName, self::IMAPDELIMITER));
     }
     /*
      * @todo must see if it is not better do this on the model directly
      */
     $systemFolders = FALSE;
     if (strtolower($folder[$folderDecoded['globalName']]['parent']) === 'inbox') {
         $systemFolders = in_array(strtolower($folder[$folderDecoded['globalName']]['localName']), Felamimail_Controller_Folder::getInstance()->getSystemFolders($folderDecoded['accountId']));
     }
     return new Felamimail_Model_Folder(array('id' => $_id, 'account_id' => $folderDecoded['accountId'], 'localname' => Felamimail_Model_Folder::decodeFolderName($folder[$folderDecoded['globalName']]['localName']), 'globalname' => Felamimail_Model_Folder::decodeFolderName($folder[$folderDecoded['globalName']]['globalName']), 'parent' => $folder[$folderDecoded['globalName']]['parent'], 'delimiter' => $folder[$folderDecoded['globalName']]['delimiter'], 'is_selectable' => $folder[$folderDecoded['globalName']]['isSelectable'], 'has_children' => $folder[$folderDecoded['globalName']]['hasChildren'], 'system_folder' => $systemFolders, 'imap_status' => Felamimail_Model_Folder::IMAP_STATUS_OK, 'imap_uidvalidity' => $counter['uidvalidity'], 'imap_totalcount' => array_key_exists('exists', $status) ? $status['exists'] : '', 'imap_timestamp' => Tinebase_DateTime::now(), 'cache_status' => 'complete', 'cache_totalcount' => array_key_exists('messages', $status) ? $status['messages'] : '', 'cache_recentcount' => array_key_exists('recent', $status) ? $status['recent'] : '', 'cache_unreadcount' => array_key_exists('unseen', $status) ? $status['unseen'] : '', 'cache_timestamp' => Tinebase_DateTime::now(), 'cache_job_lowestuid' => 0, 'cache_job_startuid' => 0, 'cache_job_actions_est' => 0, 'cache_job_actions_done' => 0, 'quota_usage' => $quota['STORAGE']['usage'], 'quota_limit' => $quota['STORAGE']['limit']));
 }
 /**
  * fetch message summary from IMAP server
  * 
  * @param string $messageUid
  * @param string $accountId
  * @param string $folderId
  * @return array
  */
 public function getMessageSummary($messageUid, $accountId, $folderId = NULL)
 {
     $imap = Felamimail_Backend_ImapFactory::factory($accountId);
     if ($folderId !== NULL) {
         try {
             $folder = Felamimail_Controller_Folder::getInstance()->get($folderId);
             $imap->selectFolder(Felamimail_Model_Folder::encodeFolderName($folder->globalname));
         } catch (Exception $e) {
             if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
                 Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not select folder ' . $folder->globalname . ': ' . $e->getMessage());
             }
         }
     }
     $summary = $imap->getSummary($messageUid, NULL, TRUE);
     return $summary;
 }
Exemplo n.º 9
0
 /**
  * get imap backend and folder (and select folder)
  *
  * @param string                    $_folderId
  * @param Felamimail_Backend_Folder &$_folder
  * @param boolean                   $_select
  * @param Felamimail_Backend_ImapProxy   $_imapBackend
  * @throws Felamimail_Exception_IMAPServiceUnavailable
  * @return Felamimail_Backend_ImapProxy
  */
 protected function _getBackendAndSelectFolder($_folderId = NULL, &$_folder = NULL, $_select = TRUE, Felamimail_Backend_ImapProxy $_imapBackend = NULL)
 {
     if ($_folder === NULL || empty($_folder)) {
         $folderBackend = Felamimail_Backend_Folder::getInstance();
         $_folder = $folderBackend->get($_folderId);
     }
     try {
         $imapBackend = $_imapBackend === NULL ? Felamimail_Backend_ImapFactory::factory($_folder->account_id) : $_imapBackend;
         if ($_select) {
             if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                 Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Select folder ' . $_folder->globalname);
             }
             $backendFolderValues = $imapBackend->selectFolder(Felamimail_Model_Folder::encodeFolderName($_folder->globalname));
         }
     } catch (Zend_Mail_Protocol_Exception $zmpe) {
         // no imap connection
         throw new Felamimail_Exception_IMAPServiceUnavailable();
     }
     return $imapBackend;
 }
 /**
  * get imap backend and folder (and select folder)
  *
  * @param string                    $_folderId
  * @param Felamimail_Backend_Folder &$_folder
  * @param boolean                   $_select
  * @param Felamimail_Backend_ImapProxy   $_imapBackend
  * @throws Felamimail_Exception_IMAPServiceUnavailable
  * @throws Felamimail_Exception_IMAPFolderNotFound
  * @return Felamimail_Backend_ImapProxy
  */
 protected function _getBackendAndSelectFolder($_folderId = NULL, &$_folder = NULL, $_select = TRUE, Felamimail_Backend_ImapProxy $_imapBackend = NULL)
 {
     if ($_folder === NULL || empty($_folder)) {
         $folderBackend = new Felamimail_Backend_Folder();
         $_folder = $folderBackend->get($_folderId);
     }
     try {
         $imapBackend = $_imapBackend === NULL ? Felamimail_Backend_ImapFactory::factory($_folder->account_id) : $_imapBackend;
         if ($_select) {
             if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                 Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Select folder ' . $_folder->globalname);
             }
             $imapBackend->selectFolder(Felamimail_Model_Folder::encodeFolderName($_folder->globalname));
         }
     } catch (Zend_Mail_Storage_Exception $zmse) {
         // @todo remove the folder from cache if it could not be found on the IMAP server?
         throw new Felamimail_Exception_IMAPFolderNotFound($zmse->getMessage());
     } catch (Zend_Mail_Protocol_Exception $zmpe) {
         throw new Felamimail_Exception_IMAPServiceUnavailable($zmpe->getMessage());
     }
     return $imapBackend;
 }
 /**
  * move messages on imap server
  * 
  * @param array $_uids
  * @param string $_targetFolderName
  * @param Felamimail_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, Felamimail_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, Felamimail_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 (Felamimail_Exception_IMAP $fei) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $fei);
         }
     }
 }
Exemplo n.º 12
0
 /**
  * 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));
     }
 }
Exemplo n.º 13
0
 /**
  * update/synchronize flags
  * 
  * @param string|Felamimail_Model_Folder $_folder
  * @param integer $_time
  * @return Felamimail_Model_Folder
  * 
  * @todo only get flags of current batch of messages from imap?
  * @todo add status/progress to start at later messages when this is called next time?
  */
 public function updateFlags($_folder, $_time = 60)
 {
     // always read folder from database
     $folder = Felamimail_Controller_Folder::getInstance()->get($_folder);
     if ($folder->cache_status !== Felamimail_Model_Folder::CACHE_STATUS_COMPLETE) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Do not update flags of incomplete folder ' . $folder->globalname);
         }
         return $folder;
     }
     if ($this->_availableUpdateTime == 0) {
         $this->_availableUpdateTime = $_time;
         $this->_timeStart = microtime(true);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updating flags of folder ' . $folder->globalname . ' / start time: ' . Tinebase_DateTime::now()->toString() . ' / available seconds: ' . ($this->_availableUpdateTime - $this->_timeElapsed));
     }
     // get all flags for folder
     $imap = Felamimail_Backend_ImapFactory::factory($folder->account_id);
     $imap->selectFolder(Felamimail_Model_Folder::encodeFolderName($folder->globalname));
     $flags = $imap->getFlags(1, INF);
     for ($i = $folder->cache_totalcount; $i > 0; $i -= $this->_flagSyncCountPerStep) {
         $firstMessageSequence = $i - $this->_flagSyncCountPerStep >= 0 ? $i - $this->_flagSyncCountPerStep : 0;
         $messagesWithFlags = $this->_backend->getFlagsForFolder($folder->getId(), $firstMessageSequence, $this->_flagSyncCountPerStep);
         $this->_setFlagsOnCache($messagesWithFlags, $flags, $folder->getId());
         if (!$this->_timeLeft()) {
             break;
         }
     }
     $updatedCounters = Felamimail_Controller_Cache_Folder::getInstance()->getCacheFolderCounter($_folder);
     $folder = Felamimail_Controller_Folder::getInstance()->updateFolderCounter($folder, array('cache_unreadcount' => $updatedCounters['cache_unreadcount']));
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' New unreadcount after flags update: ' . $updatedCounters['cache_unreadcount']);
     }
     return $folder;
 }
Exemplo n.º 14
0
 /**
  * get folder status/values from imap server and update folder cache record in database
  * 
  * @param Felamimail_Model_Folder $_folder
  * @param Felamimail_Backend_Imap|boolean $_imap
  * @return Felamimail_Model_Folder
  */
 public function getIMAPFolderCounter(Felamimail_Model_Folder $_folder)
 {
     $folder = $_folder instanceof Felamimail_Model_Folder ? $_folder : Felamimail_Controller_Folder::getInstance()->get($_folder);
     $imap = Felamimail_Backend_ImapFactory::factory($folder->account_id);
     // get folder values / status from imap server
     $counter = $imap->examineFolder(Felamimail_Model_Folder::encodeFolderName($folder->globalname));
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($counter, TRUE));
     }
     // check validity
     $folder->cache_uidvalidity = $folder->imap_uidvalidity;
     $folder->imap_uidvalidity = $counter['uidvalidity'];
     $folder->cache_uidvalidity = empty($folder->cache_uidvalidity) ? $folder->imap_uidvalidity : $folder->cache_uidvalidity;
     $folder->imap_totalcount = $counter['exists'];
     $folder->imap_status = Felamimail_Model_Folder::IMAP_STATUS_OK;
     $folder->imap_timestamp = Tinebase_DateTime::now();
     return $folder;
 }
Exemplo n.º 15
0
 /**
  * Search for records matching given filter
  *
  * @param  Tinebase_Model_Filter_FilterGroup    $_filter
  * @param  Tinebase_Model_Pagination            $_pagination
  * @param  array|string|boolean                 $_cols columns to get, * per default / use self::IDCOL or TRUE to get only ids
  * @return Tinebase_Record_RecordSet|array
  *
  * @todo implement optimizations on flags and security sorting
  * @todo implement messageuid,account_id search
  */
 public function search(Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Model_Pagination $_pagination = NULL, $_cols = '*')
 {
     /*        
     Tinebase_Core::getLogger()->alert(__METHOD__ . '#####::#####' . __LINE__ . ' Message Search = $_filter ' . print_r($_filter,true));
     Tinebase_Core::getLogger()->alert(__METHOD__ . '#####::#####' . __LINE__ . ' Message Search = $_pagination' . print_r($_filter,true));
     Tinebase_Core::getLogger()->alert(__METHOD__ . '#####::#####' . __LINE__ . ' Message Search = $_cols' . print_r($_cols,true));
     */
     $return = null;
     $messages = array();
     $filterObjects = $_filter->getFilterObjects();
     $imapFilters = $this->_parseFilterGroup($_filter, $_pagination);
     $pagination = !$_pagination ? new Tinebase_Model_Pagination(NULL, TRUE) : $_pagination;
     if (empty($imapFilters['paths'])) {
         $paths = $this->_getAllFolders();
         $imapFilters['paths'] = $this->_getFoldersInfo($paths);
     }
     // TODO: do pagination on $ids and return after getMultiple
     if ($imapFilters['filters'] == 'Id') {
         $ids = $filterObjects[0]->getValue();
         $ids = $this->_doPagination((array) $ids, $pagination);
         if ($_cols === TRUE) {
             return empty($ids) ? array() : $ids;
         } else {
             return empty($ids) ? $this->_rawDataToRecordSet(array()) : $this->getMultiple($ids);
         }
     } else {
         $ids = $this->_getIds($imapFilters, $_pagination);
         // get Summarys and merge results
         foreach ($ids as $folderId => $idsInFolder) {
             $folder = Felamimail_Controller_Folder::getInstance()->get($folderId);
             $imap = Felamimail_Backend_ImapFactory::factory($folder->account_id);
             $imap->selectFolder(Felamimail_Model_Folder::encodeFolderName($folder->globalname));
             $idsInFolder = count($ids) === 1 ? $this->_doPagination($idsInFolder, $_pagination) : $idsInFolder;
             // do pagination early
             $messagesInFolder = $imap->getSummary($idsInFolder, null, null, $folderId);
             if (count($ids) === 1) {
                 $tmp = array();
                 // We cannot trust the order we get from getSummary(), so we'll have to
                 // put it the right order, defined by $idsInFolder
                 // TODO: Put it into Felamilail_Backend_Imap->getSummary()????
                 foreach ($idsInFolder as $id) {
                     $tmp[$id] = $messagesInFolder[$id];
                 }
                 $messagesInFolder = $tmp;
                 unset($tmp);
             }
             $messages = array_merge($messages, $messagesInFolder);
             if (count($ids) !== 1 && count($messages) > 1000) {
                 throw new Felamimail_Exception_IMAPCacheTooMuchResults();
             }
         }
         if (count($ids) === 1 && !in_array($pagination->sort, $this->_imapSortParams) || count($ids) > 1) {
             $callback = new Felamimail_Backend_Cache_Imap_MessageComparator($pagination);
             uasort($messages, array($callback, 'compare'));
         }
     }
     if (empty($messages)) {
         return $this->_rawDataToRecordSet(array());
     }
     // Apply Pagination and get the resulting summary
     $page = count($ids) === 1 ? $messages : $this->_doPagination($messages, $_pagination);
     //        $limit = empty($pagination->limit) ? count($messages) : $pagination->limit;
     //        $chunked = array_chunk($messages, $limit, true);
     //        $chunkIndex = empty($pagination->start) ? 0 : $pagination->start/$limit;
     // Put headers into model
     //        if($imapFilters['filters'] == 'Id'){
     //            $return = empty($chunked[$chunkIndex])?new Tinebase_Record_RecordSet('Felamimail_Model_Message', array(), true): new Tinebase_Record_RecordSet('Felamimail_Model_Message', $chunked[$chunkIndex], true);
     //        }else
     $return = empty($page) ? $this->_rawDataToRecordSet(array()) : $this->_rawDataToRecordSet($this->_createModelMessageArray($page));
     Tinebase_Core::getLogger()->alert(__METHOD__ . '#####::#####' . __LINE__ . ' Imap Sort = $sorted ' . print_r($messages, true));
     return $return;
     //
     //        Tinebase_Core::getLogger()->alert(__METHOD__ . '#####::#####' . __LINE__ . ' Could\'nt use Imap directly' . print_r($return,true));
     //        $aux = new Felamimail_Backend_Cache_Sql_Message();
     //        $return = $aux->search($_filter,$_pagination, $_cols);
     //Tinebase_Core::getLogger()->alert(__METHOD__ . '#####::#####' . __LINE__ . ' Message Search = $retorno' . print_r($retorno,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;
 }
 /**
  * delete all messages in one folder -> be careful, they are completly removed and not moved to trash
  * -> delete subfolders if param set
  *
  * @param string $_folderId
  * @param boolean $_deleteSubfolders
  * @return Felamimail_Model_Folder
  * @throws Felamimail_Exception_IMAPServiceUnavailable
  */
 public function emptyFolder($_folderId, $_deleteSubfolders = FALSE)
 {
     $folder = $this->_backend->get($_folderId);
     $account = Felamimail_Controller_Account::getInstance()->get($folder->account_id);
     $imap = Felamimail_Backend_ImapFactory::factory($account);
     try {
         // try to delete messages in imap folder
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Delete all messages in folder ' . $folder->globalname);
         $imap->emptyFolder(Felamimail_Model_Folder::encodeFolderName($folder->globalname));
     } catch (Zend_Mail_Protocol_Exception $zmpe) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $zmpe->getMessage());
         throw new Felamimail_Exception_IMAPServiceUnavailable($zmpe->getMessage());
     } catch (Zend_Mail_Storage_Exception $zmse) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Folder could be empty (' . $zmse->getMessage() . ')');
     }
     if ($_deleteSubfolders) {
         $this->deleteSubfolders($folder);
     }
     $folder = Felamimail_Controller_Cache_Message::getInstance()->clear($_folderId);
     return $folder;
 }
Exemplo n.º 18
0
 /**
  * Tears down the fixture
  * This method is called after a test is executed.
  *
  * @access protected
  */
 protected function tearDown()
 {
     if (count($this->_createdFolders) > 0) {
         foreach ($this->_createdFolders as $folderName) {
             //echo "delete $folderName\n";
             try {
                 $this->_imap->removeFolder(Felamimail_Model_Folder::encodeFolderName($folderName));
             } catch (Zend_Mail_Storage_Exception $zmse) {
                 // already deleted
             }
         }
         Felamimail_Controller_Cache_Folder::getInstance()->clear($this->_account);
     }
     if (!empty($this->_foldersToClear)) {
         foreach ($this->_foldersToClear as $folderName) {
             // delete test messages from given folders on imap server (search by special header)
             $this->_imap->selectFolder($folderName);
             $result = $this->_imap->search(array('HEADER X-Tine20TestMessage jsontest'));
             //print_r($result);
             foreach ($result as $messageUid) {
                 $this->_imap->removeMessage($messageUid);
             }
             // clear message cache
             $folder = Felamimail_Controller_Folder::getInstance()->getByBackendAndGlobalName($this->_account->getId(), $folderName);
             Felamimail_Controller_Cache_Message::getInstance()->clear($folder);
         }
     }
     // sieve cleanup
     if ($this->_testSieveScriptName !== NULL) {
         Felamimail_Controller_Sieve::getInstance()->setScriptName($this->_testSieveScriptName);
         try {
             Felamimail_Controller_Sieve::getInstance()->deleteScript($this->_account->getId());
         } catch (Zend_Mail_Protocol_Exception $zmpe) {
             // do not delete script if active
         }
         Felamimail_Controller_Account::getInstance()->setVacationActive($this->_account, $this->_oldSieveVacationActiveState);
         if ($this->_oldSieveData !== NULL) {
             $this->_oldSieveData->save();
         }
     }
     if ($this->_oldActiveSieveScriptName !== NULL) {
         Felamimail_Controller_Sieve::getInstance()->setScriptName($this->_oldActiveSieveScriptName);
         Felamimail_Controller_Sieve::getInstance()->activateScript($this->_account->getId());
     }
 }