Example #1
0
 /**
  * the singleton pattern
  *
  * @return Felamimail_Controller_Account
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Felamimail_Controller_Account();
     }
     return self::$_instance;
 }
Example #2
0
 /**
  * update function (-> 3.2)
  * - check all users with 'userEmailAccount' and update their accounts / preferences
  */
 public function update_1()
 {
     // update account types for users with userEmailAccount preference
     $imapConfig = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::IMAP);
     if (array_key_exists('host', $imapConfig)) {
         $accounts = Felamimail_Controller_Account::getInstance()->getAll();
         $accountBackend = new Felamimail_Backend_Account();
         foreach ($accounts as $account) {
             try {
                 if (Tinebase_Core::getPreference('Felamimail')->getValueForUser('userEmailAccount', $account->user_id)) {
                     $user = Tinebase_User::getInstance()->getFullUserById($account->user_id);
                     // account email == user->emailAddress && account->host == system account host -> type = system
                     if ($account->email == $user->accountEmailAddress && $account->host == $imapConfig['host']) {
                         $account->type = Felamimail_Model_Account::TYPE_SYSTEM;
                         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Switching to system account: ' . $account->name);
                         $accountBackend->update($account);
                     }
                 }
             } catch (Exception $e) {
                 // do nothing
             }
         }
     }
     // rename preference
     $this->_db->query('UPDATE ' . SQL_TABLE_PREFIX . "preferences SET name = 'useSystemAccount' WHERE name = 'userEmailAccount'");
     $this->setApplicationVersion('Felamimail', '3.2');
 }
Example #3
0
 /**
  * process the XML file and add, change, delete or fetches data 
  *
  * @return resource
  */
 public function handle()
 {
     $defaultAccountId = Tinebase_Core::getPreference('Felamimail')->{Felamimail_Preference::DEFAULTACCOUNT};
     try {
         $this->_account = Felamimail_Controller_Account::getInstance()->get($defaultAccountId);
     } catch (Tinebase_Exception_NotFound $ten) {
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " no email account configured");
         }
         throw new ActiveSync_Exception('no email account configured');
     }
     if (empty(Tinebase_Core::getUser()->accountEmailAddress)) {
         throw new ActiveSync_Exception('no email address set for current user');
     }
     $this->_saveInSent = isset($_GET['SaveInSent']) && (bool) $_GET['SaveInSent'] == 'T';
     if (!is_resource($this->_inputStream)) {
         $this->_inputStream = fopen("php://input", 'r');
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         $debugStream = fopen("php://temp", 'r+');
         stream_copy_to_stream($this->_inputStream, $debugStream);
         rewind($debugStream);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " email to send:" . stream_get_contents($debugStream));
         }
         // replace original stream wirh debug stream, as php://input can't be rewinded
         $this->_inputStream = $debugStream;
         rewind($this->_inputStream);
     }
     $this->_incomingMessage = new Zend_Mail_Message(array('file' => $this->_inputStream));
 }
 /**
  * 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];
 }
 /**
  * @see 0011810: credential cache decode fails sometimes
  */
 public function testSaveAccountAndCredentialCache()
 {
     $account = new Felamimail_Model_Account(array('from' => 'Admin Account, Tine 2.0', 'port' => '143', 'smtp_port' => '25', 'smtp_ssl' => 'none', 'sieve_port' => '2000', 'sieve_ssl' => 'none', 'signature' => 'Sent with love from the Tine 2.0 email client ...<br>Please visit <a href="http://www.tine20.com">http://www.tine20.com</a>', 'sent_folder' => 'Sent', 'trash_folder' => 'Trash', 'name' => 'test', 'user' => '*****@*****.**', 'host' => 'mail.abc.de', 'email' => '*****@*****.**', 'password' => 'abcde', 'organization' => '', 'ssl' => 'none', 'display_format' => 'html', 'signature_position' => 'below', 'smtp_auth' => 'login'));
     $savedAccount = $this->_controller->create($account);
     $savedAccount->resolveCredentials();
     $this->assertEquals('*****@*****.**', $savedAccount->user);
     $this->assertEquals('abcde', $savedAccount->password);
 }
Example #6
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_account = Felamimail_Controller_Account::getInstance()->search()->getFirstRecord();
     $this->_controller = Felamimail_Controller_Folder::getInstance();
     $this->_imap = Felamimail_Backend_ImapFactory::factory($this->_account);
     // fill folder cache first
     $this->_controller->search($this->_getFolderFilter(''));
 }
 /**
  * test create trash on the fly
  */
 public function testCreateTrashOnTheFly()
 {
     // set another trash folder
     $this->_account->trash_folder = 'newtrash';
     $this->_foldersToDelete[] = 'newtrash';
     $accountBackend = new Felamimail_Backend_Account();
     $account = $accountBackend->update($this->_account);
     $newtrash = $this->_controller->getSystemFolder($account, Felamimail_Model_Folder::FOLDER_TRASH);
 }
Example #8
0
 /**
  * event handler function
  * 
  * all events get routed through this function
  *
  * @param Tinebase_Event_Abstract $_eventObject the eventObject
  */
 protected function _handleEvent(Tinebase_Event_Abstract $_eventObject)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . ' (' . __LINE__ . ') handle event of type ' . get_class($_eventObject));
     }
     switch (get_class($_eventObject)) {
         case 'Tinebase_Event_User_ChangeCredentialCache':
             Felamimail_Controller_Account::getInstance()->updateCredentialsOfAllUserAccounts($_eventObject->oldCredentialCache);
             break;
     }
 }
 /**
  * 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];
 }
Example #10
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
  */
 public function search(Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Model_Pagination $_pagination = NULL, $_cols = '*')
 {
     $filters = $_filter->getFilterObjects();
     //        TODO: implement this folder filter
     //        $folderFilter = new Felamimail_Model_FolderFilter(array(
     //                        array('field' => 'account_id',  'operator' => 'in',     'value' => $accounts->getArrayOfIds()),
     //                        array('field' => 'localname',   'operator' => 'equals', 'value' => 'INBOX')
     //        ));
     foreach ($filters as $filter) {
         switch ($filter->getField()) {
             case 'account_id':
                 $accountId = $filter->getValue();
                 break;
             case 'parent':
                 $globalName = $filter->getValue();
                 $parent = true;
                 break;
             case 'id':
                 $felamimailAccount = Felamimail_Controller_Account::getInstance()->search()->toArray();
                 $accountId = $felamimailAccount[0]['id'];
                 $globalName = $filter->getValue();
                 $parent = true;
                 break;
             case 'globalname':
                 $globalName = $filter->getValue();
                 if ($filter->getOperator() == 'startswith') {
                     $parent = true;
                     $globalName = substr($globalName, 0, -1);
                 }
                 break;
         }
     }
     $resultArray = array();
     $accountId = (array) $accountId;
     foreach ($accountId as $id) {
         $account = Felamimail_Controller_Account::getInstance()->get($id);
         if ($parent === true) {
             $folders = $this->_getFoldersFromIMAP($account, $globalName);
             foreach ($folders as $folder) {
                 $resultArray[] = $this->get(self::encodeFolderUid($folder['globalName'], $id));
             }
         } else {
             $resultArray[] = $this->get(self::encodeFolderUid(Felamimail_Model_Folder::encodeFolderName($globalName), $id));
         }
     }
     $result = new Tinebase_Record_RecordSet('Felamimail_Model_Folder', $resultArray, true);
     return $result;
 }
 /**
  * process the XML file and add, change, delete or fetches data 
  *
  * @return resource
  */
 public function handle()
 {
     $defaultAccountId = Tinebase_Core::getPreference('Felamimail')->{Felamimail_Preference::DEFAULTACCOUNT};
     try {
         $this->_account = Felamimail_Controller_Account::getInstance()->get($defaultAccountId);
     } catch (Tinebase_Exception_NotFound $ten) {
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " no email account configured");
         }
         throw new ActiveSync_Exception('no email account configured');
     }
     list($this->_messageId, $this->_partId) = explode('-', $_GET['AttachmentName'], 2);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " messageId: " . $this->_messageId . ' partId: ' . $this->_partId);
     }
 }
Example #12
0
 /**
  * get folder status and return all folders where something needs to be done
  *
  * @param Felamimail_Model_FolderFilter  $_filter
  * @return Tinebase_Record_RecordSet
  */
 public function getFolderStatus(Felamimail_Model_FolderFilter $_filter)
 {
     $this->_availableUpdateTime = NULL;
     // add user account ids to filter and use the folder backend to search as the folder controller has some special handling in its search function
     $_filter->createFilter(array('field' => 'account_id', 'operator' => 'in', 'value' => Felamimail_Controller_Account::getInstance()->search()->getArrayOfIds()));
     $folderBackend = Felamimail_Backend_Folder::getInstance();
     $folders = $folderBackend->search($_filter);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_filter->toArray(), TRUE));
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Checking status of " . count($folders) . ' folders.');
     }
     $result = new Tinebase_Record_RecordSet('Felamimail_Model_Folder');
     foreach ($folders as $folder) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Checking folder ' . $folder->globalname);
         }
         if ($this->_doNotUpdateCache($folder, FALSE)) {
             continue;
         }
         $imap = Felamimail_Backend_ImapFactory::factory($folder->account_id);
         $folder = Felamimail_Controller_Cache_Folder::getInstance()->getIMAPFolderCounter($folder);
         if ($this->_cacheIsInvalid($folder) || $this->_messagesInCacheButNotOnIMAP($folder)) {
             $result->addRecord($folder);
             continue;
         }
         if ($folder->imap_totalcount > 0) {
             try {
                 $this->_updateMessageSequence($folder, $imap);
             } catch (Felamimail_Exception_IMAPMessageNotFound $feimnf) {
                 $result->addRecord($folder);
                 continue;
             }
             if ($this->_messagesDeletedOnIMAP($folder) || $this->_messagesToBeAddedToCache($folder) || $this->_messagesMissingFromCache($folder)) {
                 $result->addRecord($folder);
                 continue;
             }
         }
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Found " . count($result) . ' folders that need an update.');
     }
     return $result;
 }
Example #13
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     // get (or create) test accout
     $this->_account = Felamimail_Controller_Account::getInstance()->search()->getFirstRecord();
     // init controller and imap backend
     $this->_controller = Felamimail_Controller_Cache_Message::getInstance();
     $this->_imap = Felamimail_Backend_ImapFactory::factory($this->_account);
     try {
         $this->_imap->createFolder($this->_testFolderName, '', $this->_account->delimiter);
     } catch (Zend_Mail_Storage_Exception $zmse) {
         // exists
     }
     $this->_imap->selectFolder($this->_testFolderName);
     // init folder cache and get INBOX
     Felamimail_Controller_Cache_Folder::getInstance()->update($this->_account->getId());
     $this->_folder = $this->_getFolder($this->_testFolderName);
     $this->_emailTestClass = new Felamimail_Controller_MessageTest();
     $this->_emailTestClass->setup();
 }
 /**
  * get folder ids of all inboxes for accounts of current user
  *
  * @return array
  */
 protected function _getFolderIdsOfAllInboxes()
 {
     $accounts = Felamimail_Controller_Account::getInstance()->search();
     $folderFilter = new Felamimail_Model_FolderFilter(array(array('field' => 'account_id', 'operator' => 'in', 'value' => $accounts->getArrayOfIds()), array('field' => 'localname', 'operator' => 'equals', 'value' => 'INBOX')));
     $folderBackend = Felamimail_Backend_Folder::getInstance();
     $folderIds = $folderBackend->search($folderFilter, NULL, TRUE);
     return $folderIds;
 }
 /**
  * set and get vacation sieve script
  *
  * @see 0007768: Sieve - Vacation notify frequency not being set (Cyrus)
  */
 public function testGetSetVacation()
 {
     $vacationData = $this->_getVacationData();
     $this->_sieveTestHelper($vacationData);
     // check if script was activated
     $activeScriptName = Felamimail_Controller_Sieve::getInstance()->getActiveScriptName($this->_account->getId());
     $this->assertEquals($this->_testSieveScriptName, $activeScriptName);
     $updatedAccount = Felamimail_Controller_Account::getInstance()->get($this->_account->getId());
     $this->assertTrue((bool) $updatedAccount->sieve_vacation_active);
     $result = $this->_json->getVacation($this->_account->getId());
     $this->assertEquals($this->_account->email, $result['addresses'][0]);
     $sieveBackend = Felamimail_Backend_SieveFactory::factory($this->_account->getId());
     if (preg_match('/dbmail/i', $sieveBackend->getImplementation())) {
         $translate = Tinebase_Translation::getTranslation('Felamimail');
         $vacationData['subject'] = sprintf($translate->_('Out of Office reply from %1$s'), Tinebase_Core::getUser()->accountFullName);
     }
     foreach (array('reason', 'enabled', 'subject', 'from', 'days') as $field) {
         $this->assertEquals($vacationData[$field], $result[$field], 'vacation data mismatch: ' . $field);
     }
 }
 /**
  * change account pwd / username
  *
  * @param string $id
  * @param string $username
  * @param string $password
  * @return array
  */
 public function changeCredentials($id, $username, $password)
 {
     $result = Felamimail_Controller_Account::getInstance()->changeCredentials($id, $username, $password);
     return array('status' => $result ? 'success' : 'failure');
 }
 /**
  * send Zend_Mail message via smtp
  * 
  * @param  mixed      $accountId
  * @param  Zend_Mail  $mail
  * @param  boolean    $saveInSent
  * @param  Felamimail_Model_Message $originalMessage
  * @return Zend_Mail
  */
 public function sendZendMail($accountId, Zend_Mail $mail, $saveInSent = false, $originalMessage = NULL)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Sending message with subject ' . $mail->getSubject());
     }
     if ($originalMessage !== NULL) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Original Message subject: ' . $originalMessage->subject . ' / Flag to set: ' . var_export($originalMessage->flags, TRUE));
         }
         // this is required for adding the reply/forward flag in _sendMailViaTransport()
         $originalMessage->original_id = $originalMessage;
     }
     // increase execution time (sending message with attachments can take a long time)
     $oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(300);
     // 5 minutes
     // get account
     $account = $accountId instanceof Felamimail_Model_Account ? $accountId : Felamimail_Controller_Account::getInstance()->get($accountId);
     $this->_setMailFrom($mail, $account);
     $this->_setMailHeaders($mail, $account);
     $this->_sendMailViaTransport($mail, $account, $originalMessage, $saveInSent);
     // reset max execution time to old value
     Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime);
     return $mail;
 }
Example #18
0
 /**
  * get special options
  *
  * @param string $_value
  * @return array
  */
 protected function _getSpecialOptions($_value)
 {
     $result = array();
     switch ($_value) {
         case self::DEFAULTACCOUNT:
             // get all user accounts
             $accounts = Felamimail_Controller_Account::getInstance()->search();
             foreach ($accounts as $account) {
                 $result[] = array($account->getId(), $account->name);
             }
             break;
         default:
             $result = parent::_getSpecialOptions($_value);
     }
     return $result;
 }
Example #19
0
 /**
  * check the rules
  * 
  * @param Felamimail_Model_Sieve_Rule $_rule
  * @param string|Felamimail_Model_Account $_accountId
  * @throws Felamimail_Exception_Sieve
  */
 protected function _checkRule($_rule, $_accountId)
 {
     $account = $_accountId instanceof Felamimail_Model_Account ? $_accountId : Felamimail_Controller_Account::getInstance()->get($_accountId);
     if ($_rule->action_type === Felamimail_Sieve_Rule_Action::REDIRECT && $_rule->enabled) {
         if ($account->email === $_rule->action_argument) {
             throw new Felamimail_Exception_Sieve('It is not allowed to redirect emails to self (' . $account->email . ')! Please change the recipient.');
         }
     }
 }
 /**
  * testEmptySignature
  * 
  * @see 0006666: Signature delimeter not removed if no Signature is used
  */
 public function testEmptySignature()
 {
     $this->_account->signature = '<html><body><div><br /></div><p>   </p>&nbsp;<br /></body></html>';
     $account = $this->_controller->update($this->_account);
     $this->assertEquals('', $account->signature, 'did not save empty signature');
 }
 /**
  * check if account of message is belonging to user
  * 
  * @param Felamimail_Model_Message $message
  * @param Felamimail_Model_Account $account
  * @throws Tinebase_Exception_AccessDenied
  * 
  * @todo think about moving this to get() / _checkGrant()
  */
 protected function _checkMessageAccount($message, $account = NULL)
 {
     $account = $account ? $account : Felamimail_Controller_Account::getInstance()->get($message->account_id);
     if ($account->user_id !== Tinebase_Core::getUser()->getId()) {
         throw new Tinebase_Exception_AccessDenied('You are not allowed to access this message');
     }
 }
 /**
  * get subfolders
  * 
  * @param string|Felamimail_Model_Account $_account
  * @param string $_globalname
  * @return Tinebase_Record_RecordSet
  */
 public function getSubfolders($_account, $_globalname)
 {
     $account = $_account instanceof Felamimail_Model_Account ? $_account : Felamimail_Controller_Account::getInstance()->get($_account);
     $globalname = empty($_globalname) ? '' : $_globalname . $account->delimiter;
     $filter = new Felamimail_Model_FolderFilter(array(array('field' => 'globalname', 'operator' => 'startswith', 'value' => $globalname), array('field' => 'account_id', 'operator' => 'equals', 'value' => $account->getId())));
     return $this->_backend->search($filter);
 }
 /**
  * returns TRUE if account has capability (i.e. QUOTA, CONDSTORE, ...)
  * 
  * @param $_capability
  * @return boolean
  */
 public function hasCapability($_capability)
 {
     $capabilities = Felamimail_Controller_Account::getInstance()->updateCapabilities($this);
     return in_array($_capability, $capabilities['capabilities']);
 }
 /**
  * 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;
 }
Example #25
0
 protected function _getAllFolders()
 {
     $return = array();
     $accounts = Felamimail_Controller_Account::getInstance()->search()->getArrayOfIds();
     foreach ($accounts as $account) {
         $return = array_merge($return, $this->_getAllFoldersByAccountId($account));
     }
     return $return;
 }
 /**
  * get felamimail account
  * 
  * @return Felamimail_Model_Account|NULL
  */
 protected function _getAccount()
 {
     if ($this->_account === NULL) {
         $defaultAccountId = Tinebase_Core::getPreference('Felamimail')->{Felamimail_Preference::DEFAULTACCOUNT};
         if (empty($defaultAccountId)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " no default account set. Can't sync any folders.");
             }
             return NULL;
         }
         try {
             $this->_account = Felamimail_Controller_Account::getInstance()->get($defaultAccountId);
         } catch (Tinebase_Exception_NotFound $ten) {
             return NULL;
         }
     }
     return $this->_account;
 }
Example #27
0
 /**
  * clones the account
  *
  * @return Felamimail_Model_Account
  */
 protected function _cloneAccount()
 {
     $account = clone $this->_account;
     unset($account->id);
     $this->_accountsToDelete[] = $account;
     $account = Felamimail_Controller_Account::getInstance()->create($account);
     return $account;
 }
 /**
  * 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));
     }
 }
 /**
  * Send the reading confirmation in a message who has the correct header and is not seen yet
  *
  * @return void
  */
 public function sendReadingConfirmation()
 {
     if (!is_array($this->headers)) {
         $this->headers = Felamimail_Controller_Message::getInstance()->getMessageHeaders($this->getId(), NULL, TRUE);
     }
     if ((isset($this->headers['disposition-notification-to']) || array_key_exists('disposition-notification-to', $this->headers)) && $this->headers['disposition-notification-to']) {
         $translate = Tinebase_Translation::getTranslation($this->_application);
         $from = Felamimail_Controller_Account::getInstance()->get($this->account_id);
         $message = new Felamimail_Model_Message();
         $message->account_id = $this->account_id;
         $punycodeConverter = Felamimail_Controller_Message::getInstance()->getPunycodeConverter();
         $to = Felamimail_Message::convertAddresses($this->headers['disposition-notification-to'], $punycodeConverter);
         if (empty($to)) {
             throw new Felamimail_Exception('disposition-notification-to header does not contain a valid email address');
         }
         $message->content_type = Felamimail_Model_Message::CONTENT_TYPE_HTML;
         $message->to = $to[0]['email'];
         $message->subject = $translate->_('Reading Confirmation:') . ' ' . $this->subject;
         $message->body = $translate->_('Your message:') . ' ' . $this->subject . "\n" . $translate->_('Received on') . ' ' . $this->received . "\n" . $translate->_('Was read by:') . ' ' . $from->from . ' <' . $from->email . '> ' . $translate->_('on') . ' ' . date('Y-m-d H:i:s');
         $message->body = Tinebase_Mail::convertFromTextToHTML($message->body, 'felamimail-body-blockquote');
         Felamimail_Controller_Message_Send::getInstance()->sendMessage($message);
     }
 }
 /**
  * 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;
 }