示例#1
0
 /**
  * the singleton pattern
  *
  * @return Felamimail_Controller_Folder
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = Felamimail_Controller_Cache_Folder::getInstance();
     }
     return self::$_instance;
 }
 /**
  * folder counts test helper
  * 
  * @param Felamimail_Model_Folder $_folder
  * @param array $_newCounters
  * @param array $_expectedValues
  */
 protected function _folderCountsTestHelper($_folder, $_newCounters, $_expectedValues)
 {
     $updatedFolder = $this->_controller->updateFolderCounter($_folder, $_newCounters);
     foreach ($_expectedValues as $key => $value) {
         $this->assertEquals($value, $updatedFolder->{$key}, $key . ' does not match.');
     }
     $folderInDb = $this->_controller->get($_folder->getId());
     $this->assertTrue($updatedFolder->toArray() == $folderInDb->toArray(), 'folder values do not match');
 }
示例#3
0
 /**
  * Tears down the fixture
  * This method is called after a test is executed.
  *
  * @access protected
  */
 protected function tearDown()
 {
     Tinebase_TransactionManager::getInstance()->rollBack();
     foreach ($this->_foldersToDelete as $foldername) {
         try {
             Felamimail_Controller_Folder::getInstance()->delete($this->_account->getId(), $foldername);
         } catch (Felamimail_Exception_IMAP $fei) {
             // do nothing
         }
     }
 }
 /**
  * Tears down the fixture
  * This method is called after a test is executed.
  *
  * @access protected
  */
 protected function tearDown()
 {
     foreach ($this->_foldersToDelete as $foldername) {
         try {
             Felamimail_Controller_Folder::getInstance()->delete($this->_account->getId(), $foldername);
         } catch (Felamimail_Exception_IMAP $fei) {
             // do nothing
         }
     }
     Tinebase_TransactionManager::getInstance()->rollBack();
     if ($this->_pwChanged) {
         $testConfig = Zend_Registry::get('testConfig');
         $this->_setCredentials($testConfig->username, $testConfig->password);
     }
 }
 /**
  * parse FolderUpdate request
  *
  */
 public function handle()
 {
     $xml = simplexml_import_dom($this->_inputDom);
     $this->_syncKey = (int) $xml->SyncKey;
     $this->_parentId = (string) $xml->ParentId;
     $this->_displayName = (string) $xml->DisplayName;
     $this->_serverId = (string) $xml->ServerId;
     if ($this->_logger instanceof Zend_Log) {
         $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " synckey is {$this->_syncKey} parentId {$this->_parentId} name {$this->_displayName}");
     }
     $defaultAccountId = Tinebase_Core::getPreference('Felamimail')->{Felamimail_Preference::DEFAULTACCOUNT};
     $this->_syncState = $this->_syncStateBackend->validate($this->_device, 'FolderSync', $this->_syncKey);
     try {
         $this->_folder = $this->_folderBackend->getFolder($this->_device, $this->_serverId);
         $dataController = Syncope_Data_Factory::factory($this->_folder->class, $this->_device, $this->_syncTimeStamp);
         $felamimail_model_folder = Felamimail_Controller_Folder::getInstance()->get($this->_folder->folderid);
         $dataController->updateFolder($defaultAccountId, trim($this->_displayName), $felamimail_model_folder['globalname']);
         $this->_folderBackend->update($this->_folder);
     } catch (Syncope_Exception_NotFound $senf) {
         if ($this->_logger instanceof Zend_Log) {
             $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " " . $senf->getMessage());
         }
     }
 }
 /**
  * update folder counts and returns list of affected folders
  * 
  * @param array $_folderCounter (folderId => unreadcounter)
  * @return Tinebase_Record_RecordSet of affected folders
  * @throws Felamimail_Exception
  */
 protected function _updateFolderCounts($_folderCounter)
 {
     foreach ($_folderCounter as $folderId => $counter) {
         $folder = Felamimail_Controller_Folder::getInstance()->get($folderId);
         // get error condition and update array by checking $counter keys
         if (isset($counter['incrementUnreadCounter']) || array_key_exists('incrementUnreadCounter', $counter)) {
             // this is only used in clearFlags() atm
             $errorCondition = $folder->cache_unreadcount + $counter['incrementUnreadCounter'] > $folder->cache_totalcount;
             $updatedCounters = array('cache_unreadcount' => '+' . $counter['incrementUnreadCounter']);
         } else {
             if ((isset($counter['decrementMessagesCounter']) || array_key_exists('decrementMessagesCounter', $counter)) && (isset($counter['decrementUnreadCounter']) || array_key_exists('decrementUnreadCounter', $counter))) {
                 $errorCondition = $folder->cache_unreadcount < $counter['decrementUnreadCounter'] || $folder->cache_totalcount < $counter['decrementMessagesCounter'];
                 $updatedCounters = array('cache_totalcount' => '-' . $counter['decrementMessagesCounter'], 'cache_unreadcount' => '-' . $counter['decrementUnreadCounter']);
             } else {
                 throw new Felamimail_Exception('Wrong folder counter given: ' . print_r($_folderCounter, TRUE));
             }
         }
         if ($errorCondition) {
             // something went wrong => recalculate counter
             if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
                 Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' folder counters dont match => refresh counters');
             }
             $updatedCounters = Felamimail_Controller_Cache_Folder::getInstance()->getCacheFolderCounter($folder);
         }
         Felamimail_Controller_Folder::getInstance()->updateFolderCounter($folder, $updatedCounters);
     }
     return Felamimail_Controller_Folder::getInstance()->getMultiple(array_keys($_folderCounter));
 }
示例#7
0
 /**
  * Gets one entry (by id)
  *
  * @param integer|Tinebase_Record_Interface $_id
  * @param $_getDeleted get deleted records
  * @return Tinebase_Record_Interface
  * @throws Tinebase_Exception_NotFound
  */
 public function get($_id, $_getDeleted = FALSE)
 {
     /*        
     Tinebase_Core::getLogger()->alert(__METHOD__ . '#####::#####' . __LINE__ . ' Message get = $_id ' . print_r($_id,true));
     Tinebase_Core::getLogger()->alert(__METHOD__ . '#####::#####' . __LINE__ . ' Message get = $_getDeleted' . print_r($_getDeleted,true));
     */
     $decodedIds = self::decodeMessageId($_id);
     $uid = $decodedIds['messageUid'];
     $folder = Felamimail_Controller_Folder::getInstance()->get($decodedIds['folderId']);
     $globalname = Felamimail_Backend_Cache_Imap_Folder::decodeFolderUid($decodedIds['folderId']);
     $accountId = $decodedIds['accountId'];
     $imap = Felamimail_Backend_ImapFactory::factory($accountId);
     $imap->selectFolder($globalname['globalName']);
     // we're getting just one message
     $messages = $imap->getSummary($uid, $uid, TRUE, $folder->getId());
     // $folder->getId() = ugly hack, have to try to find another solution
     if (count($messages) === 0) {
         throw new Tinebase_Exception_NotFound("Message number {$uid} not found!");
     }
     $message = array_shift($messages);
     $retorno = $this->_createModelMessage($message, $folder);
     return $retorno;
 }
 /**
  * get mailbox
  *
  * @param string $name
  * @param boolean $createFolder
  * @return Felamimail_Model_Folder|NULL
  */
 protected function _getFolder($name, $createFolder = TRUE)
 {
     Felamimail_Controller_Cache_Folder::getInstance()->update($this->_account->getId());
     try {
         $folder = Felamimail_Controller_Folder::getInstance()->getByBackendAndGlobalName($this->_account->getId(), $name);
     } catch (Tinebase_Exception_NotFound $tenf) {
         $folder = $createFolder ? Felamimail_Controller_Folder::getInstance()->create($this->_account, $name) : NULL;
     }
     return $folder;
 }
 /**
  * remove all messages from folder and delete subfolders
  *
  * @param  string $folderId the folder id to delete
  * @return array with folder status
  */
 public function emptyFolder($folderId)
 {
     // close session to allow other requests
     Tinebase_Session::writeClose(true);
     $result = Felamimail_Controller_Folder::getInstance()->emptyFolder($folderId, TRUE);
     return $this->_recordToJson($result);
 }
示例#10
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']));
 }
示例#11
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;
 }
示例#12
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;
 }
示例#13
0
 /**
  * get folder
  *
  * @return Felamimail_Model_Folder
  */
 protected function _getFolder($_folderName = null)
 {
     $folderName = $_folderName !== null ? $_folderName : $this->_testFolderName;
     $filter = new Felamimail_Model_FolderFilter(array(array('field' => 'globalname', 'operator' => 'equals', 'value' => ''), array('field' => 'account_id', 'operator' => 'equals', 'value' => $this->_account->getId())));
     $result = Felamimail_Controller_Folder::getInstance()->search($filter);
     $folder = $result->filter('localname', $folderName)->getFirstRecord();
     if (empty($folder)) {
         print_r($result->toArray());
         throw new Exception('folder not found');
     }
     return $folder;
 }
 /**
  * validate getAllFolders
  * 
  * @see 0007206: ActiveSync doesn't show all folder tree until it's fully viewed in web-interface
  */
 public function testGetAllFolders()
 {
     // create a subfolder of INBOX
     $emailAccount = Felamimail_Controller_Account::getInstance()->search()->getFirstRecord();
     try {
         $subfolder = Felamimail_Controller_Folder::getInstance()->create($emailAccount->getId(), 'sub', 'INBOX');
     } catch (Zend_Mail_Storage_Exception $zmse) {
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " " . $zmse);
         }
     }
     $controller = $this->_getController($this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE));
     $folders = $controller->getAllFolders();
     $this->assertGreaterThanOrEqual(5, count($folders));
     $foundFolderTypes = array();
     foreach ($folders as $folder) {
         $foundFolderTypes[] = $folder->type;
     }
     $this->assertContains(Syncroton_Command_FolderSync::FOLDERTYPE_DRAFTS, $foundFolderTypes, 'Drafts folder missing:' . print_r($foundFolderTypes, TRUE));
     $this->assertContains(Syncroton_Command_FolderSync::FOLDERTYPE_DELETEDITEMS, $foundFolderTypes, 'Trash folder missing:' . print_r($foundFolderTypes, TRUE));
     $this->assertContains(Syncroton_Command_FolderSync::FOLDERTYPE_SENTMAIL, $foundFolderTypes, 'Sent folder missing:' . print_r($foundFolderTypes, TRUE));
     $this->assertContains(Syncroton_Command_FolderSync::FOLDERTYPE_OUTBOX, $foundFolderTypes, 'Outbox folder missing:' . print_r($foundFolderTypes, TRUE));
     $this->assertTrue(array_pop($folders) instanceof Syncroton_Model_Folder);
     // look for 'INBOX/sub'
     $inbox = $this->_emailTestClass->getFolder('INBOX');
     $found = FALSE;
     $foundFolders = array();
     foreach ($folders as $folder) {
         $foundFolders[] = $folder->displayName;
         if ($folder->displayName === 'sub' && $folder->parentId === $inbox->getId()) {
             $found = TRUE;
             break;
         }
     }
     try {
         Felamimail_Controller_Folder::getInstance()->delete($emailAccount->getId(), 'INBOX/sub');
     } catch (Felamimail_Exception_IMAPFolderNotFound $feifnf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " " . $feifnf);
         }
     }
     $this->assertTrue($found, 'could not find INBOX/sub with getAllFolders(): ' . print_r($foundFolders, 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;
 }
 /**
  * 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;
 }
示例#17
0
 /**
  * Returns registry data of felamimail.
  * @see Tinebase_Application_Json_Abstract
  * 
  * @return mixed array 'variable name' => 'data'
  * 
  * @todo get default account data (host, port, ...) from preferences?
  */
 public function getRegistryData()
 {
     try {
         $accounts = $this->searchAccounts('');
     } catch (Exception $e) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not get accounts: ' . $e->getMessage());
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
         }
         $accounts = array('results' => array(), 'totalcount' => 0);
     }
     $supportedFlags = Felamimail_Controller_Message_Flags::getInstance()->getSupportedFlags();
     $extraSenderAccounts = array();
     foreach ($accounts['results'] as $key => $account) {
         try {
             $extraSenderAccounts = Felamimail_Controller_Folder::getInstance()->getUsersWithSendAsAcl($account['id']);
         } catch (Felamimail_Exception_IMAPFolderNotFound $ex) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . $ex->getMessage());
             }
             // Ignore this exception here, it happens when INBOX folder is unaccessible.
         } catch (Felamimail_Exception_IMAPServiceUnavailable $ex) {
             // Ignoring this Exception here.
         }
         unset($account['host']);
         unset($account['port']);
         unset($account['ssl']);
         unset($account['smtp_hostname']);
         unset($account['smtp_port']);
         unset($account['smtp_ssl']);
         unset($account['smtp_auth']);
         $accounts['results'][$key] = $account;
     }
     $result = array('extraSenderAccounts' => $extraSenderAccounts, 'accounts' => $accounts, 'supportedFlags' => array('results' => $supportedFlags, 'totalcount' => count($supportedFlags)));
     $defaults = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::IMAP);
     $defaults['smtp'] = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::SMTP);
     // remove sensitive data
     unset($defaults['user']);
     unset($defaults['host']);
     unset($defaults['port']);
     unset($defaults['password']);
     unset($defaults['smtp']);
     $result['defaults'] = $defaults;
     return $result;
 }
示例#18
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;
 }
示例#19
0
 /**
  * Delete server folder
  *
  * @param Felamimail_Model_Folder $_folderName
  */
 public function deleteFolder($_folder)
 {
     $defaultAccountId = Tinebase_Core::getPreference('Felamimail')->{Felamimail_Preference::DEFAULTACCOUNT};
     $felamimail_model_folder = Felamimail_Controller_Folder::getInstance()->get($_folder->folderid);
     Felamimail_Controller_Folder::getInstance()->delete($defaultAccountId, $felamimail_model_folder['globalname'], FALSE);
 }
 /**
  * save message in folder (target folder can be within a different account)
  * 
  * @param string|Felamimail_Model_Folder $_folder globalname or folder record
  * @param Felamimail_Model_Message $_message
  * @return Felamimail_Model_Message
  */
 public function saveMessageInFolder($_folder, $_message)
 {
     $sourceAccount = Felamimail_Controller_Account::getInstance()->get($_message->account_id);
     if (is_string($_folder) && ($_folder === $sourceAccount->templates_folder || $_folder === $sourceAccount->drafts_folder)) {
         // make sure that system folder exists
         $systemFolder = $_folder === $sourceAccount->templates_folder ? Felamimail_Model_Folder::FOLDER_TEMPLATES : Felamimail_Model_Folder::FOLDER_DRAFTS;
         $folder = Felamimail_Controller_Account::getInstance()->getSystemFolder($sourceAccount, $systemFolder);
     } else {
         if ($_folder instanceof Felamimail_Model_Folder) {
             $folder = $_folder;
         } else {
             $folder = Felamimail_Controller_Folder::getInstance()->getByBackendAndGlobalName($_message->account_id, $_folder);
         }
     }
     $targetAccount = $_message->account_id == $folder->account_id ? $sourceAccount : Felamimail_Controller_Account::getInstance()->get($folder->account_id);
     $mailToAppend = $this->createMailForSending($_message, $sourceAccount);
     $transport = new Felamimail_Transport();
     $mailAsString = $transport->getRawMessage($mailToAppend, $this->_getAdditionalHeaders($_message));
     $flags = $folder->globalname === $targetAccount->drafts_folder ? array(Zend_Mail_Storage::FLAG_DRAFT) : null;
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Appending message ' . $_message->subject . ' to folder ' . $folder->globalname . ' in account ' . $targetAccount->name);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $mailAsString);
     }
     Felamimail_Backend_ImapFactory::factory($targetAccount)->appendMessage($mailAsString, Felamimail_Model_Folder::encodeFolderName($folder->globalname), $flags);
     return $_message;
 }
示例#21
0
 /**
  * check and update mismatching folder counts (totalcount + unreadcount)
  * 
  * @param Felamimail_Model_Folder $_folder
  */
 protected function _checkAndUpdateFolderCounts(Felamimail_Model_Folder $_folder)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Checking foldercounts.');
     }
     $updatedCounters = Felamimail_Controller_Cache_Folder::getInstance()->getCacheFolderCounter($_folder);
     if ($this->_countMismatch($_folder, $updatedCounters)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' something went wrong while in/decrementing counters => recalculate cache counters by counting rows in database.' . " Cache status cache total count: {$_folder->cache_totalcount} imap total count: {$_folder->imap_totalcount}");
         }
         Felamimail_Controller_Folder::getInstance()->updateFolderCounter($_folder, $updatedCounters);
     }
     if ($updatedCounters['cache_totalcount'] != $_folder->imap_totalcount) {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' There are still messages missing in the cache: setting status to INCOMPLETE');
         }
         $_folder->cache_status == Felamimail_Model_Folder::CACHE_STATUS_INCOMPLETE;
     }
 }
 /**
  * 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;
 }
 /**
  * move messages from one folder to another folder within the same email account
  * 
  * @param Tinebase_Record_RecordSet $_messages
  * @param Felamimail_Model_Folder $_targetFolder
  */
 protected function _moveMessagesInFolderOnSameAccount(Tinebase_Record_RecordSet $_messages, Felamimail_Model_Folder $_targetFolder)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Move ' . count($_messages) . ' message(s) to ' . $_targetFolder->globalname);
     }
     $firstMessage = $_messages->getFirstRecord();
     $folder = Felamimail_Controller_Folder::getInstance()->get($firstMessage->folder_id);
     $imapBackend = $this->_getBackendAndSelectFolder(NULL, $folder);
     $imapMessageUids = array();
     foreach ($_messages as $message) {
         $imapMessageUids[] = $message->messageuid;
         if (count($imapMessageUids) >= 50) {
             $this->_moveBatchOfMessages($imapMessageUids, $_targetFolder->globalname, $imapBackend);
             $imapMessageUids = array();
         }
     }
     // the rest
     if (count($imapMessageUids) > 0) {
         $this->_moveBatchOfMessages($imapMessageUids, $_targetFolder->globalname, $imapBackend);
     }
 }
示例#24
0
 /**
  * get folder
  *
  * @return Felamimail_Model_Folder
  */
 public function getFolder($_folderName = null, $_account = NULL)
 {
     $folderName = $_folderName !== null ? $_folderName : $this->_testFolderName;
     $account = $_account !== NULL ? $_account : $this->_account;
     $filter = new Felamimail_Model_FolderFilter(array(array('field' => 'globalname', 'operator' => 'equals', 'value' => ''), array('field' => 'account_id', 'operator' => 'equals', 'value' => $account->getId())));
     $result = Felamimail_Controller_Folder::getInstance()->search($filter);
     $folder = $result->filter('localname', $folderName)->getFirstRecord();
     if (empty($folder)) {
         $folder = Felamimail_Controller_Folder::getInstance()->create($account, $_folderName);
     }
     return $folder;
 }
示例#25
0
 /**
  * save message in folder (target folder can be within a different account)
  * 
  * @param string|Felamimail_Model_Folder $_folder globalname or folder record
  * @param Felamimail_Model_Message $_message
  * @return Felamimail_Model_Message
  */
 public function saveMessageInFolder($_folder, $_message)
 {
     $sourceAccount = Felamimail_Controller_Account::getInstance()->get($_message->account_id);
     $folder = $_folder instanceof Felamimail_Model_Folder ? $_folder : Felamimail_Controller_Folder::getInstance()->getByBackendAndGlobalName($_message->account_id, $_folder);
     $targetAccount = $_message->account_id == $folder->account_id ? $sourceAccount : Felamimail_Controller_Account::getInstance()->get($folder->account_id);
     $mailToAppend = $this->createMailForSending($_message, $sourceAccount);
     $transport = new Felamimail_Transport();
     $mailAsString = $transport->getRawMessage($mailToAppend);
     $flags = $folder->globalname === $targetAccount->drafts_folder ? array(Zend_Mail_Storage::FLAG_DRAFT) : null;
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Appending message ' . $_message->subject . ' to folder ' . $folder->globalname . ' in account ' . $targetAccount->name);
     }
     Felamimail_Backend_ImapFactory::factory($targetAccount)->appendMessage($mailAsString, $folder->globalname, $flags);
     return $_message;
 }