/** * sieve test helper * * @param array $_sieveData * @return array */ protected function _sieveTestHelper($_sieveData, $_isMime = FALSE) { $this->_setTestScriptname(); // check which save fn to use if (isset($_sieveData['reason']) || array_key_exists('reason', $_sieveData)) { $resultSet = $this->_json->saveVacation($_sieveData); $this->assertEquals($this->_account->email, $resultSet['addresses'][0]); $_sieveBackend = Felamimail_Backend_SieveFactory::factory($this->_account->getId()); if (preg_match('/dbmail/i', $_sieveBackend->getImplementation())) { $translate = Tinebase_Translation::getTranslation('Felamimail'); $this->assertEquals(sprintf($translate->_('Out of Office reply from %1$s'), Tinebase_Core::getUser()->accountFullName), $resultSet['subject']); } else { $this->assertEquals($_sieveData['subject'], $resultSet['subject']); } if ($_isMime) { $this->assertEquals(html_entity_decode('unittest vacation message', ENT_NOQUOTES, 'UTF-8'), $resultSet['reason']); } else { $this->assertEquals($_sieveData['reason'], $resultSet['reason']); } } else { if (isset($_sieveData[0]['action_type']) || array_key_exists('action_type', $_sieveData[0])) { $resultSet = $this->_json->saveRules($this->_account->getId(), $_sieveData); $this->assertEquals($_sieveData, $resultSet); } } return $resultSet; }
/** * factory function to return a selected account/imap backend class * * @param string|Felamimail_Model_Account $_accountId * @return Felamimail_Backend_ImapProxy * @throws Felamimail_Exception_IMAPInvalidCredentials */ public static function factory($_accountId) { $accountId = $_accountId instanceof Felamimail_Model_Account ? $_accountId->getId() : $_accountId; if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Getting IMAP backend for account id ' . $accountId); } if (!isset(self::$_backends[$accountId])) { // get imap config from account $account = $_accountId instanceof Felamimail_Model_Account ? $_accountId : Felamimail_Controller_Account::getInstance()->get($_accountId); $imapConfig = $account->getImapConfig(); // we need to instantiate a new imap backend if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Connecting to server ' . $imapConfig['host'] . ':' . $imapConfig['port'] . ' (' . (array_key_exists('ssl', $imapConfig) ? $imapConfig['ssl'] : 'none') . ')' . ' with username ' . $imapConfig['user']); } try { self::$_backends[$accountId] = new Felamimail_Backend_ImapProxy($imapConfig); Felamimail_Controller_Account::getInstance()->updateCapabilities($account, self::$_backends[$accountId]); } catch (Felamimail_Exception_IMAPInvalidCredentials $feiic) { // add account and username to Felamimail_Exception_IMAPInvalidCredentials $feiic->setAccount($account)->setUsername($imapConfig['user']); throw $feiic; } } return self::$_backends[$accountId]; }
/** * get imap backend * * @param Felamimail_Model_Folder $_folder * @return Felamimail_Backend_ImapProxy */ protected function _getImapFromFolder($_folder) { if ($_folder->account_id == $this->_account->getId()) { $imap = $this->_imap; } else { $imap = Felamimail_Backend_ImapFactory::factory($_folder->account_id); } return $imap; }
/** * test reset account capabilities */ public function testResetAccountCapabilities() { $capabilities = $this->_controller->updateCapabilities($this->_account); $account = clone $this->_account; $account->host = 'unittest.org'; $account->type = Felamimail_Model_Account::TYPE_USER; $this->_controller->update($account); $this->assertFalse(array_key_exists($this->_account->getId(), Felamimail_Session::getSessionNamespace()->account), print_r(Felamimail_Session::getSessionNamespace()->account, TRUE)); }
/** * test reset account capabilities */ public function testResetAccountCapabilities() { $capabilities = $this->_controller->updateCapabilities($this->_account); $account = clone $this->_account; $account->host = 'unittest.org'; $account->type = Felamimail_Model_Account::TYPE_USER; $this->_controller->update($account); $this->assertFalse(array_key_exists($this->_account->getId(), $_SESSION['Felamimail']), print_r($_SESSION['Felamimail'], TRUE)); }
/** * constructor * * @param string|Felamimail_Model_Account $_accountId the felamimail account id * @param boolean $_readData */ public function __construct($_accountId, $_readData = TRUE) { $this->_rulesBackend = new Tinebase_Backend_Sql(array('modelName' => 'Felamimail_Model_Sieve_Rule', 'tableName' => 'felamimail_sieve_rule')); $this->_vacationBackend = new Tinebase_Backend_Sql(array('modelName' => 'Felamimail_Model_Sieve_Vacation', 'tableName' => 'felamimail_sieve_vacation')); $this->_accountId = $_accountId instanceof Felamimail_Model_Account ? $_accountId->getId() : $_accountId; if (empty($this->_accountId)) { throw new Felamimail_Exception('No accountId has been set.'); } if ($_readData) { $this->readScriptData(); } }
/** * factory function to return a selected account/imap backend class * * @param string|Felamimail_Model_Account $_accountId * @return Felamimail_Backend_Sieve */ public static function factory($_accountId) { $accountId = $_accountId instanceof Felamimail_Model_Account ? $_accountId->getId() : $_accountId; if (!isset(self::$_backends[$accountId])) { $account = $_accountId instanceof Felamimail_Model_Account ? $_accountId : Felamimail_Controller_Account::getInstance()->get($accountId); // get imap config from account to connect with sieve server $sieveConfig = $account->getSieveConfig(); // we need to instantiate a new sieve backend if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Connecting to server ' . $sieveConfig['host'] . ':' . $sieveConfig['port'] . ' (secure: ' . ((isset($sieveConfig['ssl']) || array_key_exists('ssl', $sieveConfig)) && $sieveConfig['ssl'] !== FALSE ? $sieveConfig['ssl'] : 'none') . ') with user ' . $sieveConfig['username']); } self::$_backends[$accountId] = new Felamimail_Backend_Sieve($sieveConfig); } return self::$_backends[$accountId]; }
/** * remove folders from cache that no longer exist on the imap server * * @param Felamimail_Model_Account $_account * @param string $_parentFolder * @param array $_imapFolderIds if empty, remove all found cached folders */ protected function _removeFromCache(Felamimail_Model_Account $_account, $_parentFolder = NULL, $_imapFolderIds = array()) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ''); } $filterData = array(array('field' => 'account_id', 'operator' => 'equals', 'value' => $_account->getId())); if ($_parentFolder !== NULL) { $filterData[] = array('field' => 'parent', 'operator' => 'equals', 'value' => $_parentFolder); } $filter = new Felamimail_Model_FolderFilter($filterData); $cachedFolderIds = $this->_backend->search($filter, NULL, TRUE); if (count($cachedFolderIds) > count($_imapFolderIds)) { // remove folders from cache $idsToRemove = array_diff($cachedFolderIds, $_imapFolderIds); if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Removing ' . count($idsToRemove) . ' folders from cache.'); } $this->delete($idsToRemove); } }
/** * set vacation active field for account * * @param string|Felamimail_Model_Account $_account * @param boolean $_vacationEnabled * @return Felamimail_Model_Account */ public function setVacationActive(Felamimail_Model_Account $_account, $_vacationEnabled) { $account = $this->get($_account->getId()); if ($account->sieve_vacation_active != $_vacationEnabled) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updating sieve_vacation_active = ' . $_vacationEnabled . ' for account: ' . $account->name); } $account->sieve_vacation_active = (bool) $_vacationEnabled; // skip all special update handling $account = $this->_backend->update($account); } return $account; }
/** * append message (from given filename) to folder * * @param string $_filename * @param string $_folder */ protected function _appendMessage($_filename, $_folder) { $mailAsString = file_get_contents(dirname(dirname(dirname(__FILE__))) . '/files/' . $_filename); Expressomail_Backend_ImapFactory::factory($this->_account->getId())->appendMessage($mailAsString, $_folder); }
/** * get folder filter * * @return Felamimail_Model_FolderFilter */ protected function _getFolderFilter($_globalname = 'INBOX') { return new Expressomail_Model_FolderFilter(array(array('field' => 'globalname', 'operator' => 'equals', 'value' => $_globalname), array('field' => 'account_id', 'operator' => 'equals', 'value' => $this->_account->getId()))); }