/** * Queries an email account for new wmails. If an account id was posted, * only the specified account will be queried. * Sends all newly fetched emails back to the client. * This method will also check beforehand for any IMAP account that's about * to be queried for new emails, if a default inbox folder was configured * for this account. If no valid folder was found, the emthod will not query * any account for new messages, and instead return an additional property * named "missingInboxForAccountId", which holds the account id of the first * account found for which no inbox folder was configured. * * */ public function fetchEmailsAction() { /*@REMOVE@*/ if (!$this->_helper->connectionCheck()) { $this->view->success = true; $this->view->totalCount = 0; $this->view->items = array(); $this->view->error = null; return; } /*@REMOVE@*/ if (isset($_POST['accountId'])) { $accountId = (int) $_POST['accountId']; if ($accountId < 0) { $this->view->success = true; $this->view->totalCount = 0; $this->view->items = array(); $this->view->error = null; return; } else { if ($accountId == 0) { $accountId = null; } } } else { $accountId = null; } require_once 'Conjoon/Keys.php'; require_once 'Conjoon/Modules/Groupware/Email/Letterman.php'; require_once 'Conjoon/BeanContext/Decorator.php'; require_once 'Conjoon/Error.php'; $auth = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT); $userId = $auth->getIdentity()->getId(); $emails = array(); $errorMessages = array(); $time = time(); $currentAccount = null; try { $accountDecorator = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Account_Model_Account'); $noop = false; if ($accountId === null) { $accounts = $accountDecorator->getAccountsForUserAsEntity($userId); if (count($accounts) == 0) { $noop = true; } } else { $account = $accountDecorator->getAccountAsEntity($accountId, $userId); if ($account == null) { $noop = true; } else { $accounts = array($account); } } if ($noop) { $this->view->success = true; $this->view->totalCount = 0; $this->view->items = array(); $this->view->error = null; return; } /** * @see Conjoon_Modules_Groupware_Email_Folder_Facade */ require_once 'Conjoon/Modules/Groupware/Email/Folder/Facade.php'; /** * @see Conjoon_Modules_Groupware_Email_Item_ItemListRequestFacade */ require_once 'Conjoon/Modules/Groupware/Email/Item/ItemListRequestFacade.php'; $itemListRequestFacade = Conjoon_Modules_Groupware_Email_Item_ItemListRequestFacade::getInstance(); //$facade = Conjoon_Modules_Groupware_Email_Folder_Facade::getInstance(); $imapEmails = array(); for ($i = 0, $accLen = count($accounts); $i < $accLen; $i++) { $currentAccount =& $accounts[$i]; // check here if we have an actual INBOX folder configured for the // account. if ($currentAccount->getProtocol() == 'IMAP') { continue; } $tmpEmails = Conjoon_Modules_Groupware_Email_Letterman::fetchEmails($userId, $currentAccount); $emails = array_merge($emails, $tmpEmails['fetched']); $errorMessages = array_merge($errorMessages, $tmpEmails['errors']); } } catch (Zend_Mail_Protocol_Exception $e) { $errorMessages[] = $e->getMessage() . "\n - host: " . $currentAccount->getServerInbox() . ':' . $currentAccount->getPortInbox() . "\n user: "******" (using password: "******"\n", $errorMessages), Conjoon_Error::LEVEL_ERROR); } }
/** * Sets the iconv-internal-encodings, since Zend_Mime does not allow * for passing an indivdual charset for decoding. * This is a simple helper which allows for either setting the encoding * to utf-8 or reset the endoding to the old value. * * @param string $type * */ private static function _setIconvEncoding($type) { if ($type != self::ICONV_UTF_8) { if (!empty(self::$_oldEncodings)) { iconv_set_encoding('input_encoding', self::$_oldEncodings['input_encoding']); iconv_set_encoding('output_encoding', self::$_oldEncodings['output_encoding']); iconv_set_encoding('internal_encoding', self::$_oldEncodings['internal_encoding']); } } else { if (empty(self::$_oldEncodings)) { self::$_oldEncodings = array('input_encoding' => iconv_get_encoding('input_encoding'), 'output_encoding' => iconv_get_encoding('output_encoding'), 'internal_encoding' => iconv_get_encoding('internal_encoding')); } iconv_set_encoding('input_encoding', 'UTF-8'); iconv_set_encoding('output_encoding', 'UTF-8'); iconv_set_encoding('internal_encoding', 'UTF-8'); } }