/** * Tries to cast a numeric/associative array into it's representant * entity model as defined in $_entity. * * @param array $data The array data, if numeric, a numeric array * will be returned, with values of the type $className. If an * associative array was submitted, a single object of the type * $className will be returned. * * @return mixed Either an array of objects or a single object. */ protected final function _cast($values, $type) { if ($values instanceof Zend_Db_Table_Rowset_Abstract || $values instanceof Zend_Db_Table_Row_Abstract || is_object($values) && method_exists($values, 'toArray')) { $values = $values->toArray(); } if (!is_array($values) || $type == self::TYPE_ARRAY) { return $values; } $len = count($values); if ($len == 0) { return array(); } $entity = $this->_entity; // simple check to determine if we have a assoc or numeric // array if (!Conjoon_Util_Array::isAssociative($values)) { $data = array(); $TYPE_DTO = $type == self::TYPE_DTO; for ($i = 0; $i < $len; $i++) { Conjoon_Util_Array::camelizeKeys($values[$i]); if ($this->_filter) { $values[$i] = $this->_filter->setData($values[$i])->getProcessedData(); } $data[] = Conjoon_BeanContext_Inspector::create($entity, $values[$i], !$this->_strict); if ($TYPE_DTO) { $data[$i] = $data[$i]->getDto(); if ($this->_filter) { $vv =& $values[$i]; $dd =& $data[$i]; $props = get_class_vars(get_class($data[$i])); foreach ($props as $propname => $propvalue) { if (!array_key_exists($propname, $vv)) { unset($dd->{$propname}); } } } } } return $data; } else { Conjoon_Util_Array::camelizeKeys($values); if ($this->_filter) { $values = $this->_filter->setData($values)->getProcessedData(); } $data = Conjoon_BeanContext_Inspector::create($entity, $values, !$this->_strict); if ($type == self::TYPE_DTO) { return $data->getDto(); } return $data; } }
/** * Helper for setting the properties of an Conjoon_BeanContext-object. * Will throw an exception if the method associated with the property was * not found, or any exception that was thrown by the accessor-method * of <tt>$object</tt>. * The method assumes that <tt>property</tt> is already a valid property name * according to <tt>Conjoon_BeanContext</tt>-conventions. * * @param Object $object The instance to set the property for. Must be of type * <tt>Conjoon_BeanContext</tt> * @param string $property The property name that is about to be set. * @param mixed $value The value to pass as the argument to the * setter-method of <tt>$property</tt> * @param boolean $ignoreMissing when set to true, the method will not throw an error * if the * * @throws Exception * @see Conjoon_BeanContext */ private static function setProperty($object, $property, $value, $ignoreMissing = false) { $method = self::getAccessorForProperty($object, $property, self::SETTER); if ($method === null && $ignoreMissing == false) { throw new Conjoon_BeanContext_Exception("Setter for {$property} not found."); } else { if ($method === null) { return; } } if (is_array($value) && strpos($method, 'add') === 0) { $reflM = new ReflectionMethod($object, $method); $params = $reflM->getParameters(); $cls = $params[0]->getClass()->getName(); /** * @see Conjoon_Util_Array */ require_once 'Conjoon/Util/Array.php'; for ($i = 0, $len = count($value); $i < $len; $i++) { Conjoon_Util_Array::camelizeKeys($value[$i]); $val = Conjoon_BeanContext_Inspector::create($cls, $value[$i], true); $object->{$method}($val); } } else { $object->{$method}($value); } }
/** * Imports and adds the items for the requested feed uri and adds them * to the account specified in $accountId if they do not already exist. * The account's lastUpdated property will also be set, and the item lists * cache will be cleaned, if feed items have been actually added. * * * @param integer $accountId * @param integer $userId * @param boolean $useReaderCache * @param boolean $useConditionalGet * * @return array Returns an array with the recently added * Conjoon_Modules_Groupware_Feeds_Item_Dto * * @throws Exception */ public function importAndAddFeedItems($accountId, $userId, $useReaderCache = false, $useConditionalGet = false) { $accountId = (int) $accountId; $userId = (int) $userId; if ($accountId <= 0 || $userId <= 0) { throw new InvalidArgumentException("Invalid argument supplied, accountId was \"{$accountId}\", " . "userId was \"{$userId}\""); } $accountDto = $this->_getAccountFacade()->getAccount($accountId, $userId); $uri = $accountDto->uri; $requestTimeout = $accountDto->requestTimeout; /** * @see Conjoon_Modules_Groupware_Feeds_ImportHelper */ require_once 'Conjoon/Modules/Groupware/Feeds/ImportHelper.php'; // get the feeds metadata try { $import = Conjoon_Modules_Groupware_Feeds_ImportHelper::importFeedItems($uri, $requestTimeout, $useReaderCache, $useConditionalGet); } catch (Exception $e) { Conjoon_Log::log(get_class($this) . "::importAndAddFeedItems could not import " . "feed items from {$uri}: \"" . get_class($e) . "\" - \"" . $e->getMessage() . "\"", Zend_Log::INFO); // return an empty array, do not delete cache for the account and do not // update last_updated timestamp! return array(); } /** * @see Conjoon_Modules_Groupware_Feeds_Item_Filter_Item */ require_once 'Conjoon/Modules/Groupware/Feeds/Item/Filter/Item.php'; $filter = new Conjoon_Modules_Groupware_Feeds_Item_Filter_Item(array(), Conjoon_Filter_Input::CONTEXT_CREATE); $itemResponseFilter = new Conjoon_Modules_Groupware_Feeds_Item_Filter_Item(array(), Conjoon_Filter_Input::CONTEXT_RESPONSE); /** * @see Conjoon_Util_Array */ require_once 'Conjoon/Util/Array.php'; /** * @see Conjoon_BeanContext_Inspector */ require_once 'Conjoon/BeanContext/Inspector.php'; $added = array(); $cCache = false; foreach ($import as $item) { $normalized = Conjoon_Modules_Groupware_Feeds_ImportHelper::normalizeFeedItem($item); $normalized['groupwareFeedsAccountsId'] = $accountId; $filter->setData($normalized); try { $fillIn = $filter->getProcessedData(); } catch (Zend_Filter_Exception $e) { /** * @see Conjoon_Error */ require_once 'Conjoon/Error.php'; Conjoon_Log::log(Conjoon_Error::fromFilter($filter, $e), Zend_Log::ERR); continue; } $dtoData = $fillIn; Conjoon_Util_Array::underscoreKeys($fillIn); $isAdded = $this->_addItemIfNotExists($fillIn, $accountId, false); if ($isAdded > 0) { $cCache = true; $dtoData['id'] = $isAdded; $dtoData['name'] = $accountDto->name; $itemResponseFilter->setData($dtoData); $dtoData = $itemResponseFilter->getProcessedData(); $added[] = Conjoon_BeanContext_Inspector::create('Conjoon_Modules_Groupware_Feeds_Item', $dtoData)->getDto(); } } if ($cCache) { $this->_removeListCacheForAccountIds(array($accountId)); } $this->_getAccountFacade()->setLastUpdated(array($accountId), time()); return $added; }
/** * Saves a draft into the outbox folder of the user. */ public function moveToOutboxAction() { /** * @see Conjoon_Modules_Groupware_Email_Draft_Filter_DraftInput */ require_once 'Conjoon/Modules/Groupware/Email/Draft/Filter/DraftInput.php'; $data = array(); try { // the filter will transform the "message" into bodyHtml and bodyText, depending // on the passed format. both will only be filled if format equals to "multipart" $filter = new Conjoon_Modules_Groupware_Email_Draft_Filter_DraftInput($_POST, Conjoon_Filter_Input::CONTEXT_CREATE); $data = $filter->getProcessedData(); $postedPath = $data['path']; } catch (Exception $e) { require_once 'Conjoon/Error.php'; $error = Conjoon_Error::fromFilter($filter, $e); $this->view->success = false; $this->view->error = $error->getDto(); $this->view->item = null; return; } /** * @see Conjoon_Modules_Groupware_Email_Address */ require_once 'Conjoon/Modules/Groupware/Email/Address.php'; /** * @see Conjoon_Modules_Groupware_Email_Draft */ require_once 'Conjoon/Modules/Groupware/Email/Draft.php'; /** * @see Conjoon_BeanContext_Inspector */ require_once 'Conjoon/BeanContext/Inspector.php'; // create the message object here $to = array(); $cc = array(); $bcc = array(); $postedAttachments = $data['attachments']; $data['attachments'] = array(); $removeAttachmentIds = $data['removedAttachments']; unset($data['removedAttachments']); foreach ($data['cc'] as $dcc) { $add = new Conjoon_Modules_Groupware_Email_Address($dcc); $cc[] = $add; } foreach ($data['bcc'] as $dbcc) { $add = new Conjoon_Modules_Groupware_Email_Address($dbcc); $bcc[] = $add; } foreach ($data['to'] as $dto) { $add = new Conjoon_Modules_Groupware_Email_Address($dto); $to[] = $add; } $data['cc'] = $cc; $data['to'] = $to; $data['bcc'] = $bcc; // get the specified account for the user require_once 'Conjoon/BeanContext/Decorator.php'; require_once 'Conjoon/Keys.php'; $accountDecorator = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Account_Model_Account'); $auth = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT); $userId = $auth->getIdentity()->getId(); $account = $accountDecorator->getAccountAsEntity($data['groupwareEmailAccountsId'], $userId); // no account found? if (!$account) { $this->view->error = $this->getErrorDto('Error while moving email to the outbox folder', 'Could not find specified account.', Conjoon_Error::LEVEL_ERROR); $this->view->success = false; $this->view->item = null; return; } $draft = Conjoon_BeanContext_Inspector::create('Conjoon_Modules_Groupware_Email_Draft', $data, true); if ($account->getProtocol() == 'IMAP') { return $this->moveImapToOutbox($account, $draft, $userId, $postedAttachments, $removeAttachmentIds); } $draft = Conjoon_BeanContext_Inspector::create('Conjoon_Modules_Groupware_Email_Draft', $data, true); $updateCache = false; // check whether we need to apply attachments for a previously saved // draft if ($draft->getId() > 0) { $updateCache = true; /** * @see Conjoon_Modules_Groupware_Email_Attachment_Filter_AttachmentResponse */ require_once 'Conjoon/Modules/Groupware/Email/Attachment/Filter/AttachmentResponse.php'; $attDecorator = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Attachment_Model_Attachment', new Conjoon_Modules_Groupware_Email_Attachment_Filter_AttachmentResponse(array(), Conjoon_Modules_Groupware_Email_Attachment_Filter_AttachmentResponse::CONTEXT_RESPONSE)); $atts = $attDecorator->getAttachmentsForItemAsEntity($draft->getId()); $draft->setAttachments($atts); } /** * @see Conjoon_BeanContext_Decorator */ require_once 'Conjoon/BeanContext/Decorator.php'; /** * @see Conjoon_Modules_Groupware_Email_Item_Filter_ItemResponse */ require_once 'Conjoon/Modules/Groupware/Email/Item/Filter/ItemResponse.php'; $itemDecorator = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Item_Model_Item', new Conjoon_Modules_Groupware_Email_Item_Filter_ItemResponse(array(), Conjoon_Filter_Input::CONTEXT_RESPONSE), false); $item = $itemDecorator->moveDraftToOutboxAsDto($draft, $account, $userId, $data['type'], $data['referencesId'], $postedAttachments, $removeAttachmentIds); if (!$item) { $this->view->error = $this->getErrorDto('Error while saving email', 'The email could not be stored into the database.', Conjoon_Error::LEVEL_ERROR); $this->view->success = false; $this->view->item = null; return; } if ($updateCache) { /** * @see Conjoon_Modules_Groupware_Email_Message_Facade */ require_once 'Conjoon/Modules/Groupware/Email/Message/Facade.php'; // update cache Conjoon_Modules_Groupware_Email_Message_Facade::getInstance()->removeMessageFromCache($item->id, $this->_helper->registryAccess()->getUserId(), $postedPath); } $this->view->error = null; $this->view->success = true; $this->view->item = $item; }
/** * Adds an email account to the database, assigning it to the currently * logged in user. * The following key/value pairs will be submitted via POST: * * <ul> * <li>name : The name of the account</li> * <li>address : The email address for this account</li> * <li>isStandard : <tt>true</tt>, if this should become the standard email account, * otherwise <tt>false</tt></li> * <li>server_inbox : The address of the inbox-server</li> * <li>server_outbox : The address of the outbox server</li> * <li>username_inbox : The username for the inbox-server</li> * <li>username_outbox: The username for the outbox-server. If <tt>outbox_auth</tt> * equals to <tt>false</tt>, the value will be empty</li> * <li>user_name : The full name of the user who owns this account</li> * <li>outbox_auth : <tt>true</tt> if the outbox-server needs authentication, * otherwise <tt>false</tt></li> * <li>password_inbox : The password for the inbox-server</li> * <li>password_outbox: The password for the outbox-server. If <tt>outbox_auth</tt> * equals to <tt>false</tt>, the value will be empty</li> * </ul> * <li>inbox_connection_type: Secure connection type for the incoming * mail server. Empty for unsecure connection, or SSL or TLS</li> * <li>outbox_connection_type: Secure connection type for the outgoing mail * server. Empty for unsecure connection, or SSL or TLS. If <tt>outbox_auth</tt> * equals to <tt>false</tt>, the value will be empty</li> * </ul> * * Upon success, the following view variables will be assigned: * <ul> * <li>success: <tt>true</tt>, if the account was added to the database, * otherwise <tt>false></tt></li> * <li>account: a fully configured instance of <tt>Conjoon_Groupware_Email_Account</tt>. * <br /><strong>NOTE:</strong> If the user submitted passwords, those will be replaced by strings * containing only blanks, matching the length of the originally submitted * passwords.</li> * <li>rootFolder: The root folder that saves the tree hierarchy for this * account.</li> * <li>error: An object of the type <tt>Conjoon_Groupware_ErrorObject</tt>, if any error * occured, otherwise <tt>null</tt></li> * <ul> * * <strong>Note:</strong> The properties <tt>account</tt> and <tt>error</tt> will * be returned in the format based on the passed context the action was called. * For example, if an array was assigned to <tt>account</tt> and the context is <tt>json</tt>, * this array will become json-encoded and returned as a string. This happens transparently. * * @todo FACADE! */ public function addEmailAccountAction() { require_once 'Conjoon/Util/Array.php'; require_once 'Conjoon/Keys.php'; require_once 'Conjoon/BeanContext/Inspector.php'; require_once 'Conjoon/Modules/Groupware/Email/Account/Model/Account.php'; require_once 'Conjoon/Modules/Groupware/Email/Account/Filter/Account.php'; $model = new Conjoon_Modules_Groupware_Email_Account_Model_Account(); $filter = new Conjoon_Modules_Groupware_Email_Account_Filter_Account(array(), Conjoon_Filter_Input::CONTEXT_CREATE); $auth = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT); $userId = $auth->getIdentity()->getId(); /** * @see Conjoon_Builder_Factory */ require_once 'Conjoon/Builder/Factory.php'; // clean cache in any case Conjoon_Builder_Factory::getBuilder(Conjoon_Keys::CACHE_EMAIL_ACCOUNTS, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray())->cleanCacheForTags(array('userId' => $userId)); $classToCreate = 'Conjoon_Modules_Groupware_Email_Account'; $this->view->success = true; $this->view->error = null; try { $filter->setData($_POST); $processedData = $filter->getProcessedData(); } catch (Zend_Filter_Exception $e) { /** * @see Conjoon_Error */ require_once 'Conjoon/Error.php'; $error = Conjoon_Error::fromFilter($filter, $e); $accountData = $_POST; $accountData['passwordOutbox'] = isset($accountData['passwordOutbox']) ? str_pad("", strlen($accountData['passwordOutbox']), '*') : ''; $accountData['passwordInbox'] = isset($accountData['passwordInbox']) ? str_pad("", strlen($accountData['passwordInbox']), '*') : ''; $this->view->account = Conjoon_BeanContext_Inspector::create($classToCreate, $accountData)->getDto(); $this->view->success = false; $this->view->error = $error->getDto(); return; } $data = $processedData; // check for duplicates $duplicates = $model->getAccountWithNameForUser($data['name'], $userId); if (!empty($duplicates)) { /** * @see Conjoon_Error */ require_once 'Conjoon/Error.php'; $error = new Conjoon_Error(); $error->setMessage("There is already an account with " . "the name \"" . $data['name'] . "\"!"); $error->setLevel(Conjoon_Error::LEVEL_WARNING); $this->view->success = false; $this->view->error = $error->getDto(); return; } // add account here Conjoon_Util_Array::underscoreKeys($data); $addedId = $model->addAccount($userId, $data); /** * @see Conjoon_BeanContext_Decorator */ require_once 'Conjoon/BeanContext/Decorator.php'; $decoratedModel = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Account_Model_Account'); $dto = $decoratedModel->getAccountAsDto($addedId, $userId); $dto->folderMappings = array(); // ADD FOLDER MAPPINGS if ($dto->protocol == 'IMAP') { /** * @see \Conjoon\Data\Entity\Mail\DefaultFolderMappingEntity */ require_once 'Conjoon/Data/Entity/Mail/DefaultFolderMappingEntity.php'; $entityManager = Zend_Registry::get(Conjoon_Keys::DOCTRINE_ENTITY_MANAGER); $accRep = $entityManager->getRepository('\\Conjoon\\Data\\Entity\\Mail\\DefaultMailAccountEntity'); $fmRep = $entityManager->getRepository('\\Conjoon\\Data\\Entity\\Mail\\DefaultFolderMappingEntity'); $types = array('INBOX', 'SENT', 'JUNK', 'DRAFT', 'TRASH', 'OUTBOX'); $accountEnt = $accRep->findById($addedId); foreach ($types as $type) { $newEnt = new \Conjoon\Data\Entity\Mail\DefaultFolderMappingEntity(); $newEnt->setType($type); $newEnt->setGlobalName(""); $newEnt->setMailAccount($accountEnt); $fmRep->register($newEnt); $fmRep->flush(); $dto->folderMappings[] = array('id' => $newEnt->getId(), 'type' => $type, 'globalName' => "", 'path' => array()); } } if (!$dto->isOutboxAuth) { $dto->usernameOutbox = ""; $dto->passwordOutbox = ""; } $dto->passwordOutbox = str_pad("", strlen($dto->passwordOutbox), '*'); $dto->passwordInbox = str_pad("", strlen($dto->passwordInbox), '*'); // read out root folder for account require_once 'Conjoon/BeanContext/Decorator.php'; $decoratedFolderModel = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Folder_Model_Folder', null, false); $rootId = $decoratedFolderModel->getAccountsRootOrRootFolderId($addedId, $userId); $dto->localRootMailFolder = array(); if ($rootId != 0) { $dto->localRootMailFolder = $decoratedFolderModel->getFolderBaseDataAsDto($rootId); } $this->view->account = $dto; }
/** * Adds an account to the data storage. * * Fields required in $data: * - deleteInterval * - name * - requestTimeout * - updateInterval * - uri * * * @param Array $data * @param integer $userId * * @return Conjoon_Modules_Groupware_Feeds_Account_Dto The recently added * account, or null if not created * * @throws Exception */ public function addAccount(array $data, $userId) { $userId = (int) $userId; if ($userId <= 0) { throw new InvalidArgumentException("Invalid argument supplied, userId was \"{$userId}\""); } /** * @see Conjoon_Modules_Groupware_Feeds_Account_Filter_Account */ require_once 'Conjoon/Modules/Groupware/Feeds/Account/Filter/Account.php'; $filter = new Conjoon_Modules_Groupware_Feeds_Account_Filter_Account($data, Conjoon_Filter_Input::CONTEXT_CREATE); $data = $filter->getProcessedData(); $dtoData = $data; /** * @see Conjoon_Util_Array */ require_once 'Conjoon/Util/Array.php'; Conjoon_Util_Array::underscoreKeys($data); $result = $this->_getAccountModel()->addAccount($data, $userId); $addedAccount = null; if ($result > 0) { $dtoData['id'] = $result; /** * @see Conjoon_BeanContext_Inspector */ require_once 'Conjoon/BeanContext/Inspector.php'; $addedAccount = Conjoon_BeanContext_Inspector::create('Conjoon_Modules_Groupware_Feeds_Account', $dtoData)->getDto(); $this->_getListBuilder()->cleanCacheForTags(array('userId' => $userId)); } return $addedAccount; }
/** * Bulk sends emails. Awaits the parameter ids as a numeric array with the ids of * the emails which should get send. * */ public function bulkSendAction() { /*@REMOVE@*/ if (!$this->_helper->connectionCheck()) { /** * @see Conjoon_Error_Factory */ require_once 'Conjoon/Error/Factory.php'; $this->view->success = false; $this->view->sentItems = array(); $this->view->error = null; $this->view->contextReferencedItems = array(); $this->view->error = Conjoon_Error_Factory::createError("Unexpected connection failure while trying to bulk-send emails. " . "Please try again.", Conjoon_Error::LEVEL_WARNING, Conjoon_Error::DATA)->getDto(); return; } /*@REMOVE@*/ $toSend = $_POST['ids']; if ($this->_helper->conjoonContext()->getCurrentContext() == self::CONTEXT_JSON) { require_once 'Zend/Json.php'; $toSend = Zend_Json::decode($toSend, Zend_Json::TYPE_ARRAY); } $date = null; if (isset($_POST['date'])) { require_once 'Conjoon/Filter/DateIso8601.php'; $dateFilter = new Conjoon_Filter_DateIso8601(); $date = $dateFilter->filter((int) $_POST['date']); } /** * @see Conjoon_Filter_EmailRecipients */ require_once 'Conjoon/Filter/EmailRecipients.php'; /** * @see Conjoon_Modules_Groupware_Email_Item_Filter_ItemResponse */ require_once 'Conjoon/Modules/Groupware/Email/Item/Filter/ItemResponse.php'; /** * @see Conjoon_Modules_Groupware_Email_Address */ require_once 'Conjoon/Modules/Groupware/Email/Address.php'; /** * @see Conjoon_Modules_Groupware_Email_Draft */ require_once 'Conjoon/Modules/Groupware/Email/Draft.php'; /** * @see Conjoon_BeanContext_Inspector */ require_once 'Conjoon/BeanContext/Inspector.php'; /** * @see Conjoon_BeanContext_Decorator */ require_once 'Conjoon/BeanContext/Decorator.php'; /** * @see Conjoon_Util_Array */ require_once 'Conjoon/Util/Array.php'; /** * @see Conjoon_Keys */ require_once 'Conjoon/Keys.php'; /** * @see Conjoon_Modules_Groupware_Email_Draft_Model_Draft */ require_once 'Conjoon/Modules/Groupware/Email/Draft/Model/Draft.php'; /** * @see Conjoon_Modules_Groupware_Email_Draft_Filter_DraftInput */ require_once 'Conjoon/Modules/Groupware/Email/Draft/Filter/DraftInput.php'; /** * @see Conjoon_Modules_Groupware_Email_Sender */ require_once 'Conjoon/Modules/Groupware/Email/Sender.php'; $auth = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT); $userId = $auth->getIdentity()->getId(); $draftFilter = new Conjoon_Modules_Groupware_Email_Draft_Filter_DraftInput(array(), Conjoon_Filter_Input::CONTEXT_CREATE); $draftModel = new Conjoon_Modules_Groupware_Email_Draft_Model_Draft(); $accountDecorator = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Account_Model_Account'); $recipientsFilter = new Conjoon_Filter_EmailRecipients(); $newVersions = array(); $sendItems = array(); $contextReferencedItems = array(); $errors = array(); foreach ($toSend as $pathInfo) { $remoteInfo = array(); $id = $pathInfo['id']; $path = $pathInfo['path']; $account = null; $remoteAttachments = array(); // check if path is remote! $isRemote = $this->isRemotePath($path, $userId); if ($isRemote) { $rawDraft = $this->getRawImapMessage($id, $path); if (empty($rawDraft)) { continue; } //we have to post the existing attachments of the remote draft // again when assembling the message to send. // Otherwise the sender would not know which attachments should get send // along with the message $remoteAttachments = $rawDraft['attachments']; foreach ($remoteAttachments as &$remoteAttachment) { $remoteAttachment['metaType'] = 'emailAttachment'; $remoteAttachment['name'] = $remoteAttachment['fileName']; } $remoteInfo = array('uid' => $id, 'account' => $isRemote, 'path' => $path); $rawDraft['groupwareEmailAccountsId'] = $isRemote->id; $account = $accountDecorator->getAccountAsEntity($rawDraft['groupwareEmailAccountsId'], $userId); } else { $rawDraft = $draftModel->getDraft($id, $userId); $account = $accountDecorator->getAccountAsEntity($rawDraft['groupware_email_accounts_id'], $userId); } // no account found? if (!$account) { /** * @todo think about using the standard account as a fallback or use at last * an error message to inform the user that the account used to write this email * is not available anymore */ continue; } $id = (int) $id; if ($id <= 0) { continue; } if (empty($rawDraft)) { continue; } Conjoon_Util_Array::camelizeKeys($rawDraft); $rawDraft['to'] = $recipientsFilter->filter($rawDraft['to']); $rawDraft['cc'] = $recipientsFilter->filter($rawDraft['cc']); $rawDraft['bcc'] = $recipientsFilter->filter($rawDraft['bcc']); // create the message object here $to = array(); $cc = array(); $bcc = array(); foreach ($rawDraft['cc'] as $dcc) { $add = new Conjoon_Modules_Groupware_Email_Address($dcc); $cc[] = $add; } foreach ($rawDraft['bcc'] as $dbcc) { $add = new Conjoon_Modules_Groupware_Email_Address($dbcc); $bcc[] = $add; } foreach ($rawDraft['to'] as $dto) { $add = new Conjoon_Modules_Groupware_Email_Address($dto); $to[] = $add; } $rawDraft['to'] = $to; $rawDraft['cc'] = $cc; $rawDraft['bcc'] = $bcc; $message = Conjoon_BeanContext_Inspector::create('Conjoon_Modules_Groupware_Email_Draft', $rawDraft, true); if ($date !== null) { $message->setDate($date); } try { $transport = $this->getTransportForAccount($account); $assembleInformation = Conjoon_Modules_Groupware_Email_Sender::getAssembledMail($message, $account, $remoteAttachments, array(), $this->getCurrentAppUser()->getId(), $transport); $assembledMail = $assembleInformation['message']; $postedAttachments = $assembleInformation['postedAttachments']; $mail = Conjoon_Modules_Groupware_Email_Sender::send($assembledMail); } catch (Exception $e) { $errors[] = array('subject' => $message->getSubject(), 'accountName' => $account->getName(), 'reason' => $e->getMessage()); continue; } if ($isRemote) { /** * @see Conjoon_Modules_Groupware_Email_ImapHelper */ require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php'; $uId = $remoteInfo['uid']; $account = $remoteInfo['account']; $path = $remoteInfo['path']; // check if folder is remote folder /** * @see Conjoon_Text_Parser_Mail_MailboxFolderPathJsonParser */ require_once 'Conjoon/Text/Parser/Mail/MailboxFolderPathJsonParser.php'; $parser = new Conjoon_Text_Parser_Mail_MailboxFolderPathJsonParser(); $pathInfo = $parser->parse(json_encode($path)); /** * @see Conjoon_Modules_Groupware_Email_Folder_Facade */ require_once 'Conjoon/Modules/Groupware/Email/Folder/Facade.php'; $facade = Conjoon_Modules_Groupware_Email_Folder_Facade::getInstance(); // get the account for the root folder first $imapAccount = $facade->getImapAccountForFolderIdAndUserId($pathInfo['rootId'], $userId); if ($imapAccount && !empty($pathInfo) && $facade->isRemoteFolder($pathInfo['rootId'])) { // if remote, where is the referenced mail stored? $globalName = $facade->getAssembledGlobalNameForAccountAndPath($imapAccount, $pathInfo['path']); /** * @see Conjoon_Modules_Groupware_Email_ImapHelper */ require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php'; /** * @see Conjoon_Mail_Storage_Imap */ require_once 'Conjoon/Mail/Storage/Imap.php'; $protocol = Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($imapAccount); $storage = new Conjoon_Mail_Storage_Imap($protocol); // get the number of the message by it's unique id $storage->selectFolder($globalName); $messageNumber = $storage->getNumberByUniqueId($uId); // move from sent folder $sentGlobalName = $this->getGlobalNameForFolderType($imapAccount, 'SENT'); if (!$sentGlobalName) { continue; } $storage->copyMessage($messageNumber, $sentGlobalName); $storage->selectFolder($sentGlobalName); $newMessageNumber = $storage->countMessages(); $storage->selectFolder($globalName); $storage->removeMessage($storage->getNumberByUniqueId($uId)); $storage->close(); } // put email into sent folder $protocol = Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($imapAccount); $storage = new Conjoon_Mail_Storage_Imap($protocol); // read out single item $item = $this->getSingleImapListItem($account, $userId, $newMessageNumber, $sentGlobalName); $newVersions[$uId] = $item['id']; $sendItems[] = $item; } else { // if the email was send successfully, save it into the db and // return the params savedId (id of the newly saved email) // and savedFolderId (id of the folder where the email was saved in) $itemDecorator = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Item_Model_Item', new Conjoon_Modules_Groupware_Email_Item_Filter_ItemResponse(array(), Conjoon_Filter_Input::CONTEXT_RESPONSE), false); $item = $itemDecorator->saveSentEmailAsDto($message, $account, $userId, $mail, ''); if (!$item) { continue; } $sendItems[] = $item; $cri = $itemDecorator->getReferencedItemAsDto($item->id, $userId); if (!empty($cri)) { $contextReferencedItems[] = $cri; } } } if (!empty($errors)) { /** * @see Conjoon_Error */ require_once 'Conjoon/Error.php'; $m = array(); $m[] = "One or more messages could not be sent:"; for ($i = 0, $len = count($errors); $i < $len; $i++) { $m[] = "Message " . ($i + 1) . ":"; $m[] = "Subject: \"" . $errors[$i]['subject'] . "\""; $m[] = "Account: " . $errors[$i]['accountName']; $m[] = "Failure reason: " . $errors[$i]['reason']; } $errorMessage = implode("\n", $m); $error = new Conjoon_Error(); $error->setLevel(Conjoon_Error::LEVEL_WARNING); $error->setType(Conjoon_Error::DATA); $error->setMessage($errorMessage); } $this->view->newVersions = $newVersions; $this->view->success = true; $this->view->sentItems = $sendItems; $this->view->error = isset($error) ? $error->getDto() : null; $this->view->contextReferencedItems = $contextReferencedItems; }