Пример #1
0
 /**
  * the singleton pattern
  *
  * @return Felamimail_Controller_Message
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = Felamimail_Controller_Cache_Message::getInstance();
     }
     return self::$_instance;
 }
 /**
  * the constructor
  *
  * don't use the constructor. use the singleton
  */
 private function __construct()
 {
     $this->_modelName = 'Felamimail_Model_Message';
     $this->_doContainerACLChecks = FALSE;
     $this->_backend = new Felamimail_Backend_Cache_Sql_Message();
     $this->_cacheController = Felamimail_Controller_Cache_Message::getInstance();
 }
 /**
  * testGetFolderStatusOfOtherUser
  * 
  * @see 0009408: getFolderStatus must check user accounts
  */
 public function testGetFolderStatusOfOtherUser()
 {
     $this->_appendMessage('multipart_alternative.eml', $this->_testFolderName);
     $sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever');
     Tinebase_Core::set(Tinebase_Core::USER, $sclever);
     $filter = new Felamimail_Model_FolderFilter(array(array('field' => 'id', 'operator' => 'in', 'value' => array($this->_getFolder()->getId()))));
     $status = $this->_controller->getFolderStatus($filter);
     $this->assertEquals(0, count($status), 'no folders should be found for update');
 }
Пример #4
0
 /**
  * the singleton pattern
  *
  * @return Felamimail_Controller_Cache_Message
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         $adapter = Tinebase_Core::getConfig()->messagecache;
         $adapter = empty($adapter) ? 'sql' : $adapter;
         $classname = 'Felamimail_Controller_Cache_' . ucfirst($adapter) . '_Message';
         self::$_instance = $classname::getInstance();
     }
     return self::$_instance;
 }
 /**
  * test update folder quota
  */
 public function testUpdateFolderQuota()
 {
     $folderToTest = $this->_getFolder('INBOX');
     $folderToTest = $this->_controller->updateCache($folderToTest);
     $quota = $this->_imap->getQuota('INBOX');
     if (empty($quota)) {
         $this->assertEquals(0, $folderToTest->quota_usage);
         $this->assertEquals(0, $folderToTest->quota_limit);
     } else {
         $this->assertEquals($quota['STORAGE']['usage'], $folderToTest->quota_usage);
         $this->assertEquals($quota['STORAGE']['limit'], $folderToTest->quota_limit);
     }
 }
Пример #6
0
 /**
  * search message by header (X-Tine20TestMessage) and add it to cache
  *
  * @param string $_testHeaderValue
  * @param Felamimail_Model_Folder $_folder
  * @return Felamimail_Model_Message
  */
 public function searchAndCacheMessage($_testHeaderValue, $_folder = NULL)
 {
     $folder = $_folder !== NULL ? $_folder : $this->_folder;
     $message = $this->_searchMessage($_testHeaderValue, $folder);
     $cachedMessage = $this->_cache->addMessage($message, $folder);
     if ($cachedMessage === FALSE) {
         // try to add message again (it had a duplicate)
         $this->_cache->clear($folder);
         $cachedMessage = $this->_cache->addMessage($message, $folder);
     }
     $this->assertTrue($cachedMessage instanceof Felamimail_Model_Message, 'could not add message to cache');
     $this->_createdMessages->addRecord($cachedMessage);
     return $cachedMessage;
 }
 /**
  * fetch structure from cache or imap server, parse it and store it into cache
  * 
  * @return array
  */
 protected function _fetchStructure()
 {
     $cacheId = $this->_getStructureCacheId();
     $cache = Tinebase_Core::getCache();
     if ($cache->test($cacheId)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Getting message structure from cache: ' . $cacheId);
         }
         $result = $cache->load($cacheId);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Getting message structure from IMAP server.');
         }
         try {
             $summary = Felamimail_Controller_Cache_Message::getInstance()->getMessageSummary($this->messageuid, $this->account_id, $this->folder_id);
             $result = $summary['structure'];
         } catch (Zend_Mail_Protocol_Exception $zmpe) {
             // imap server might have gone away
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' IMAP protocol error during summary fetching: ' . $zmpe->getMessage());
             $result = array();
         }
         $this->_setStructure($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;
 }
 /**
  * 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 updateFolderCounters(Felamimail_Model_Folder $_folder, $_imap)
 {
     return Felamimail_Controller_Cache_Message::getInstance()->updateCache($folder, 1);
 }
 /**
  * get messages from folder
  *
  * @param string $_folderName
  * @return array
  */
 protected function _getMessages($_folderName = 'INBOX')
 {
     $folder = $this->_getFolder($_folderName);
     $filter = $this->_getMessageFilter($folder->getId());
     // update cache
     $folder = Felamimail_Controller_Cache_Message::getInstance()->updateCache($folder, 10, 1);
     $i = 0;
     while ($folder->cache_status != Felamimail_Model_Folder::CACHE_STATUS_COMPLETE && $i < 10) {
         $folder = Felamimail_Controller_Cache_Message::getInstance()->updateCache($folder, 10);
         $i++;
     }
     $result = $this->_json->searchMessages($filter, '');
     //print_r($result);
     return $result;
 }
 /**
  * update flags
  * - use session/writeClose to allow following requests
  *
  * @param  string  $folderId id of active folder
  * @param  integer $time     update time in seconds
  * @return array
  */
 public function updateFlags($folderId, $time)
 {
     // close session to allow other requests
     Tinebase_Session::writeClose(true);
     $folder = Felamimail_Controller_Cache_Message::getInstance()->updateFlags($folderId, $time);
     return $this->_recordToJson($folder);
 }
 /**
  * get test alarm emails
  * 
  * @param boolean $deleteThem
  * @return Tinebase_Record_RecordSet
  */
 protected function _getAlarmMails($deleteThem = FALSE)
 {
     // search and assert alarm mail
     $folder = $this->_emailTestClass->getFolder('INBOX');
     $folder = Felamimail_Controller_Cache_Message::getInstance()->updateCache($folder, 10, 1);
     $i = 0;
     while ($folder->cache_status != Felamimail_Model_Folder::CACHE_STATUS_COMPLETE && $i < 10) {
         $folder = Felamimail_Controller_Cache_Message::getInstance()->updateCache($folder, 10);
         $i++;
     }
     $account = Felamimail_Controller_Account::getInstance()->search()->getFirstRecord();
     $filter = new Felamimail_Model_MessageFilter(array(array('field' => 'folder_id', 'operator' => 'equals', 'value' => $folder->getId()), array('field' => 'account_id', 'operator' => 'equals', 'value' => $account->getId()), array('field' => 'subject', 'operator' => 'startswith', 'value' => 'Alarm for event "Wakeup" at')));
     $result = Felamimail_Controller_Message::getInstance()->search($filter);
     if ($deleteThem) {
         Felamimail_Controller_Message_Move::getInstance()->moveMessages($filter, Felamimail_Model_Folder::FOLDER_TRASH);
     }
     return $result;
 }
 /**
  * used by the mail backend only. Used to update the folder cache
  * 
  * @param  string  $_folderId
  */
 public function updateCache($_folderId)
 {
     try {
         Felamimail_Controller_Cache_Message::getInstance()->updateCache($_folderId, 5);
     } catch (Exception $e) {
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " catched exception " . get_class($e));
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " " . $e->getMessage());
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " " . $e->getTraceAsString());
         }
     }
 }
 /**
  * test sync of existing imap folder
  */
 public function testPingForEmails()
 {
     $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP);
     if (!$imapConfig || !isset($imapConfig->useSystemAccount) || $imapConfig->useSystemAccount != TRUE) {
         $this->markTestSkipped('IMAP backend not configured');
     }
     $emailController = new Felamimail_Frontend_ActiveSync($this->_device, new Tinebase_DateTime(null, null, 'de_DE'));
     $folders = $emailController->getAllFolders();
     $this->assertGreaterThan(0, count($folders));
     foreach ($folders as $folder) {
         if (strtoupper($folder->displayName) == 'INBOX') {
             break;
         }
     }
     $emailController->updateCache($folder->serverId);
     // first do a foldersync
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <FolderSync xmlns="uri:FolderHierarchy"><SyncKey>0</SyncKey></FolderSync>');
     $folderSync = new Syncroton_Command_FolderSync($doc, $this->_device, $this->_device->policykey);
     $folderSync->handle();
     $syncDoc = $folderSync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     // request initial synckey
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"><Collections><Collection><Class>Email</Class><SyncKey>0</SyncKey><CollectionId>' . $folder->serverId . '</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize><Options><FilterType>4</FilterType><AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize></AirSyncBase:BodyPreference><Conflict>1</Conflict></Options></Collection></Collections></Sync>');
     $sync = new Syncroton_Command_Sync($doc, $this->_device, $this->_device->policykey);
     $sync->handle();
     $syncDoc = $sync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     // now do the first sync
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"><Collections><Collection><Class>Email</Class><SyncKey>1</SyncKey><CollectionId>' . $folder->serverId . '</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize><Options><FilterType>4</FilterType><AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize></AirSyncBase:BodyPreference><Conflict>1</Conflict></Options></Collection></Collections></Sync>');
     $sync = new Syncroton_Command_Sync($doc, $this->_device, $this->_device->policykey);
     $sync->handle();
     $syncDoc = $sync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     sleep(1);
     // and now we can start the ping request
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Ping xmlns="uri:Ping"><HeartBeatInterval>10</HeartBeatInterval><Folders><Folder><Id>' . $folder->serverId . '</Id><Class>Email</Class></Folder></Folders></Ping>');
     // add test email message to folder
     $emailTest = new Felamimail_Controller_MessageTest();
     $emailTest->setUp();
     $inbox = $emailTest->getFolder('INBOX');
     $emailTest->messageTestHelper('multipart_alternative.eml', 'multipart/alternative', $inbox);
     $ping = new Syncroton_Command_Ping($doc, $this->_device, null);
     $ping->handle();
     $responseDoc = $ping->getResponse();
     $responseDoc->formatOutput = true;
     //echo $responseDoc->saveXML();
     $xpath = new DomXPath($responseDoc);
     $xpath->registerNamespace('Ping', 'uri:Ping');
     $nodes = $xpath->query('//Ping:Ping/Ping:Status');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertEquals(Syncroton_Command_Ping::STATUS_CHANGES_FOUND, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//Ping:Ping/Ping:Folders/Ping:Folder');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertEquals($folder->serverId, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
     // message needs to be deleted after the test because other tests follow that search for 'text/plain', too
     $emailTest->tearDown();
     Felamimail_Controller_Cache_Message::getInstance()->clear($inbox);
 }