/**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * Sets the specified keys in $data to theri mapped values.
  *
  * @param array $data A numeric array with associative entries, i.e.
  *    [[ 'key' => '/somekey/anotherkey', 'value' => 1]]
  * @param integer $userId The id of the user for which the entries should
  * be set. If those entries do not already exist for the specified
  * userId, this entries will be created.
  *
  * @return array Returns an associative array with the following keys:
  * - updated: A list of keys that were actually updated
  * - failed: list with keys that could not be updated
  *
  * @throws InvalidArgumentException throws an InvalidArgumentException if
  * the specified $userId was noit valid
  * or Conjoon_Filter_Exception if the submitted data could not be sanitized
  */
 public function setEntriesFromDataForUserId(array $data, $userId)
 {
     if ($userId <= 0) {
         throw new InvalidArgumentException("Invalid argument supplied for userId - was \"{$userId}\"");
     }
     $filter = $this->_getUpdateEntriesFilter();
     $sanitized = array();
     try {
         for ($i = 0, $len = count($data); $i < $len; $i++) {
             $filter->setData($data[$i]);
             $sanitized[] = $filter->getProcessedData();
         }
     } catch (Zend_Filter_Exception $e) {
         /**
          * @see Conjoon_Error
          */
         require_once 'Conjoon/Error.php';
         $error = Conjoon_Error::fromFilter($filter, $e);
         /**
          * @see Conjoon_Filter_Exception
          */
         require_once 'Conjoon/Filter/Exception.php';
         throw new Conjoon_Filter_Exception($error->getMessage());
     }
     $registry = $this->getRegistryForUserId($userId, false);
     $updated = array();
     $failed = array();
     for ($i = 0, $len = count($sanitized); $i < $len; $i++) {
         $failed[$sanitized[$i]['key']] = true;
     }
     for ($i = 0, $len = count($sanitized); $i < $len; $i++) {
         $key = $sanitized[$i]['key'];
         $value = $sanitized[$i]['value'];
         $keys = explode('/', $key);
         $valueName = array_pop($keys);
         $keys = implode('/', $keys);
         $path = $this->_pathToIndex($keys, $registry);
         if (!empty($path)) {
             $parent = $registry[$path[count($path) - 1]];
             $valueConfig = $parent['values'];
             $registryId = $parent['id'];
             for ($a = 0, $lena = count($valueConfig); $a < $lena; $a++) {
                 if ($valueConfig[$a]['is_editable'] && $valueConfig[$a]['name'] == $valueName) {
                     $type = $valueConfig[$a]['type'];
                     switch ($type) {
                         case 'STRING':
                             $value = (string) $value;
                             break;
                         case 'BOOLEAN':
                             $value = (int) (bool) $value;
                             break;
                         case 'INTEGER':
                             $value = (int) $value;
                             break;
                         case 'FLOAT':
                             $value = (double) $value;
                             break;
                     }
                     $succ = $this->_getRegistryValuesModel()->updateValueForUser($registryId, $valueName, $value, $type, $userId);
                     if ($succ) {
                         $updated[] = $key;
                         unset($failed[$key]);
                     }
                 }
             }
         }
     }
     return array('updated' => $updated, 'failed' => array_keys($failed));
 }
 /**
  * This action will update email accounts according to the POST params
  * that come along with the request.
  * Depending of the current context the action was called, the format of the
  * POST params will differ: For json, it will be an array holding json-encoded parameters.
  * Despite all different formats the POST params may come in, each request sends
  * values for 'updated' and 'deleted' accounts: 'deleted' as an array, holding all
  * ids that should become deleted, and 'updated' an array holding information about
  * the records that get edited, represented by specific associative array, representing
  * the fields of the record.
  * The view will await values assigned to 'updated_failed' and 'deleted_failed', whereas
  * 'deleted_failed' is an array containing all ids that couldn't be deleted, and
  * 'updated_failed' an array containing the records (in associative array notation)
  * that could not be updated.
  *
  * Note: If any error in the user-input was detected, no update-action will happen, but
  * deltes may already have been submitted to the underlying datastore.
  * The first error found in the passed data will be returned as an error of the type
  * Conjoon_Error_Form, containing the fields that where errorneous.
  *
  */
 public function updateEmailAccountsAction()
 {
     require_once 'Conjoon/Modules/Groupware/Email/Account/Filter/Account.php';
     require_once 'Conjoon/Util/Array.php';
     require_once 'Conjoon/Modules/Groupware/Email/Account/Model/Account.php';
     $toDelete = array();
     $toUpdate = array();
     $deletedFailed = array();
     $updatedFailed = array();
     $model = new Conjoon_Modules_Groupware_Email_Account_Model_Account();
     $data = array();
     $error = null;
     if ($this->_helper->conjoonContext()->getCurrentContext() == self::CONTEXT_JSON) {
         require_once 'Zend/Json.php';
         $toDelete = Zend_Json::decode($_POST['deleted'], Zend_Json::TYPE_ARRAY);
         $toUpdate = Zend_Json::decode($_POST['updated'], Zend_Json::TYPE_ARRAY);
     }
     $numToUpdate = count($toUpdate);
     $numToDelete = count($toDelete);
     if ($numToUpdate != 0 || $numToDelete != 0) {
         /**
          * @see Conjoon_Builder_Factory
          */
         require_once 'Conjoon/Builder/Factory.php';
         Conjoon_Builder_Factory::getBuilder(Conjoon_Keys::CACHE_EMAIL_ACCOUNTS, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray())->cleanCacheForTags(array('userId' => Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT)->getIdentity()->getId()));
     }
     $userId = $this->_helper->registryAccess()->getUserId();
     for ($i = 0; $i < $numToDelete; $i++) {
         $affected = $model->deleteAccount($toDelete[$i], $userId);
         if ($affected == 0) {
             $deletedFailed[] = $toDelete[$i];
         }
     }
     $folderMappingData = array();
     for ($i = 0; $i < $numToUpdate; $i++) {
         $_ = $toUpdate[$i];
         $folderMappingData[$toUpdate[$i]['id']] = $toUpdate[$i]['folderMappings'];
         $filter = new Conjoon_Modules_Groupware_Email_Account_Filter_Account($_, Conjoon_Filter_Input::CONTEXT_UPDATE);
         try {
             $data[$i] = $filter->getProcessedData();
             Conjoon_Util_Array::underscoreKeys($data[$i]);
         } catch (Zend_Filter_Exception $e) {
             require_once 'Conjoon/Error.php';
             $error = Conjoon_Error::fromFilter($filter, $e);
             $this->view->success = false;
             $this->view->updatedFailed = array($_['id']);
             $this->view->deletedFailed = $deletedFailed;
             $this->view->error = $error->getDto();
             return;
         }
     }
     $createdLocalRootMailFolders = array();
     $removedLocalRootMailFolders = array();
     /**
      * @see Conjoon_BeanContext_Decorator
      */
     require_once 'Conjoon/BeanContext/Decorator.php';
     $decoratedFolderModel = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Folder_Model_Folder', null, false);
     $decoratedAccountModel = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Account_Model_Account');
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Model_Folder
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Model/Folder.php';
     $folderModel = new Conjoon_Modules_Groupware_Email_Folder_Model_Folder();
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Model_FoldersAccounts
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Model/FoldersAccounts.php';
     $foldersAccounts = new Conjoon_Modules_Groupware_Email_Folder_Model_FoldersAccounts();
     for ($i = 0, $len = count($data); $i < $len; $i++) {
         $id = $data[$i]['id'];
         unset($data[$i]['id']);
         // check here for duplicates
         $duplicates = $model->getAccountWithNameForUser($data[$i]['name'], $userId);
         $affected = 0;
         if (!empty($duplicates)) {
             for ($a = 0, $lena = count($duplicates); $a < $lena; $a++) {
                 if ($duplicates[$a]['id'] != $id) {
                     $affected = -1;
                     break;
                 }
             }
         }
         if ($affected != -1) {
             $affected = $model->updateAccount($id, $data[$i]);
             $entityManager = Zend_Registry::get(Conjoon_Keys::DOCTRINE_ENTITY_MANAGER);
             // update folderMappings
             if (isset($folderMappingData[$id])) {
                 $fmRep = $entityManager->getRepository('\\Conjoon\\Data\\Entity\\Mail\\DefaultFolderMappingEntity');
                 for ($u = 0, $lenu = count($folderMappingData[$id]); $u < $lenu; $u++) {
                     if (isset($folderMappingData[$id][$u]['id']) && empty($folderMappingData[$id][$u]['path'])) {
                         $updEnt = $fmRep->findById($folderMappingData[$id][$u]['id']);
                         $updEnt->setGlobalName("");
                         $fmRep->register($updEnt);
                     } else {
                         if (isset($folderMappingData[$id][$u]['id']) && !empty($folderMappingData[$id][$u]['path'])) {
                             /**
                              * @see \Conjoon\Data\Entity\Mail\DefaultFolderMappingEntity
                              */
                             require_once 'Conjoon/Data/Entity/Mail/DefaultFolderMappingEntity.php';
                             /**
                              * @see Conjoon_Modules_Groupware_Email_ImapHelper
                              */
                             require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php';
                             $accDto = $decoratedAccountModel->getAccountAsDto($id, $userId);
                             $delim = Conjoon_Modules_Groupware_Email_ImapHelper::getFolderDelimiterForImapAccount($accDto);
                             $p = $folderMappingData[$id][$u]['path'];
                             array_shift($p);
                             array_shift($p);
                             $globalName = implode($delim, $p);
                             $updEnt = $fmRep->findById($folderMappingData[$id][$u]['id']);
                             $updEnt->setGlobalName($globalName);
                             $fmRep->register($updEnt);
                             continue;
                         }
                     }
                 }
                 $fmRep->flush();
             }
             // take care of folder heirarchies
             if ($affected != -1) {
                 /**
                  * @todo Facade
                  */
                 $hasSeparateFolderHierarchy = array_key_exists('has_separate_folder_hierarchy', $data[$i]) ? (bool) (int) $data[$i]['has_separate_folder_hierarchy'] : null;
                 // get org protocol of account so it cannot be changed from
                 // the outside
                 $orgAccount = $model->getAccount($id, $userId);
                 $orgProtocol = $orgAccount['protocol'];
                 if ($hasSeparateFolderHierarchy !== null && strtolower($orgProtocol) !== 'imap') {
                     // the original folder ids, before remapping occures
                     $oldAccountFolderIds = $foldersAccounts->getFolderIdsForAccountId($id);
                     // read out folder base data of folder for associated account
                     $rootFolderBaseData = $decoratedFolderModel->getAnyRootMailFolderBaseDataAsDto($id, $userId);
                     if (!$rootFolderBaseData) {
                         throw new RuntimeException("No root folder base data available.");
                     }
                     if (!$hasSeparateFolderHierarchy) {
                         // do nothing if type is already accounts_root and
                         // separateFolderHierarchy = false is submitted;
                         // but if the type is root and the folderHierarchy
                         // (i.e. "root) should be removed,
                         // we need to switch from root to accounts_root
                         if ($rootFolderBaseData->type == 'root') {
                             // check first if accounts_root exist!
                             $accountsRootFolderId = $folderModel->getAccountsRootMailFolderBaseData($userId);
                             // accounts root not yet existing
                             if (!$accountsRootFolderId) {
                                 $folderModel->createFolderBaseHierarchyAndMapAccountIdForUserId($id, $userId);
                             } else {
                                 $newFolderIds = $folderModel->getFoldersForAccountsRoot($userId);
                                 // accounts root already existing.
                                 // remove the root and remap to accounts_root
                                 foreach ($oldAccountFolderIds as $oldFolderId) {
                                     $folderModel->deleteFolder($oldFolderId, $userId, false);
                                 }
                                 $removedLocalRootMailFolders[$id] = $rootFolderBaseData;
                                 $foldersAccounts->mapFolderIdsToAccountId($newFolderIds, $id);
                             }
                             $createdLocalRootMailFolders[$id] = $decoratedFolderModel->getAnyRootMailFolderBaseDataAsDto($id, $userId);
                         }
                     } else {
                         // do nothing if the type is already root which means
                         // there already exists a separate folder hierarchy
                         // if the type is accounts_root, we need to switch
                         // to a root hierarchy
                         if ($rootFolderBaseData->type == 'accounts_root') {
                             // remove old mappings
                             $foldersAccounts->deleteForAccountId($id);
                             $folderModel->createFolderHierarchyAndMapAccountIdForUserId($id, $userId, $data[$i]['name']);
                             $createdLocalRootMailFolders[$id] = $decoratedFolderModel->getAnyRootMailFolderBaseDataAsDto($id, $userId);
                         }
                     }
                 }
             }
         }
         if ($affected == -1) {
             $updatedFailed[] = $id;
         }
     }
     $this->view->success = empty($updatedFailed) ? true : false;
     $this->view->updatedFailed = $updatedFailed;
     $this->view->deletedFailed = $deletedFailed;
     $this->view->error = null;
     $this->view->createdLocalRootMailFolders = $createdLocalRootMailFolders;
     $this->view->removedLocalRootMailFolders = $removedLocalRootMailFolders;
 }
Esempio n. 5
0
 /**
  * Updates a single account with the data from $data for the specified
  * $userId.
  *
  * @param integer $accountId the id of the account to update.
  * @param Array $data
  * @param integer $userId
  *
  * @return boolean true, if updating the account was successfull, otherwise
  * false
  *
  * @throws Exception
  */
 public function updateAccount($accountId, array $data, $userId)
 {
     $accountId = (int) $accountId;
     $userId = (int) $userId;
     if ($userId <= 0 || $accountId <= 0) {
         throw new InvalidArgumentException("Invalid argument supplied, userId was \"{$userId}\", " . "accountId was \"{$accountId}\"");
     }
     $filter = $this->_getUpdateAccountFilter();
     $filter->setData($data);
     try {
         $data = $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);
         return false;
     }
     if (array_key_exists('id', $data)) {
         unset($data['id']);
     }
     /**
      * @see Conjoon_Util_Array
      */
     require_once 'Conjoon/Util/Array.php';
     Conjoon_Util_Array::underscoreKeys($data);
     $affected = $this->_getAccountModel()->updateAccount($accountId, $data);
     if ($affected === true) {
         $this->_getBuilder()->remove(array('accountId' => $accountId));
         $this->_getListBuilder()->cleanCacheForTags(array('userId' => $userId));
     }
     return $affected === true ? true : false;
 }
Esempio n. 6
0
 /**
  * Saves the email and it's attachments. Uses the default db adapter as
  * configured by the application. If an exception occurs, the exception's
  * message will be stored in an array (together with other exceptions that
  * may have occured) and returned later on. Any db operation that failed will
  * be rolled back.
  *
  * @param array $emailItem An associative array with the data to insert into the
  * different tables. All attachments will be stored in the key/value pair "attachments",
  * which is itself a numeric array
  *
  * @return mixed Return the id of the last inserted email item, or an
  * error message if an error occured.
  */
 private function _saveEmail(array $emailItem)
 {
     $filterAttachment = $this->_filterAttachment;
     $filterFlag = $this->_filterFlag;
     $filterItem = $this->_filterItem;
     $filterInbox = $this->_filterInbox;
     $modelAttachment = $this->_modelAttachment;
     $modelFlag = $this->_modelFlag;
     $modelItem = $this->_modelItem;
     $modelInbox = $this->_modelInbox;
     $dbAdapter = Zend_Db_Table::getDefaultAdapter();
     if (!$this->_maxAllowedPacket) {
         $config = Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT);
         $this->_maxAllowedPacket = $config->database->variables->max_allowed_packet;
         if (!$this->_maxAllowedPacket) {
             $this->_maxAllowedPacket = Conjoon_Db_Util::getMaxAllowedPacket($dbAdapter);
         }
     }
     $this->_setPlainFromHtml($emailItem);
     // filter and insert into groupware_email_items
     $filterItem->setData($emailItem);
     $itemData = $filterItem->getProcessedData();
     if ($this->_maxAllowedPacket < strlen($emailItem['rawBody'])) {
         return 'Could not save message with subject "' . $itemData['subject'] . '" - message is larger than available packet size (' . $this->_maxAllowedPacket . ' bytes).';
     }
     $dbAdapter->beginTransaction();
     $currFilter = null;
     try {
         Conjoon_Util_Array::underscoreKeys($itemData);
         try {
             $id = (int) $modelItem->insert($itemData);
         } catch (Zend_Db_Statement_Exception $zdse) {
             // in very rare cases, there are 4-byte characters in a utf-8
             // string, and mysql cannot handle them right since we use
             // utf-8 collations. We'll strip those 4-byte characters away.
             // see CN-619
             $content = $itemData['content_text_plain'];
             $i = 0;
             $len = strlen($content);
             $fourByteDetected = false;
             while ($i < $len) {
                 $ord = ord($content[$i]);
                 switch (true) {
                     case $ord <= 127:
                         $i += 1;
                         break;
                     case $ord < 224:
                         $i += 2;
                         break;
                     case $ord < 240:
                         $i += 3;
                         break;
                     default:
                         $fourByteDetected = true;
                         $content = substr($content, 0, $i) . substr($content, $i + 4);
                         $len -= 4;
                         break;
                 }
             }
             if ($fourByteDetected === true) {
                 $lastResortData = $emailItem;
                 $lastResortData['contentTextPlain'] = $content;
                 $filterItem->setData($lastResortData);
                 $lastResortItemData = $filterItem->getProcessedData();
                 Conjoon_Util_Array::underscoreKeys($lastResortItemData);
                 $id = (int) $modelItem->insert($lastResortItemData);
                 /**
                  * @see Conjoon_Log
                  */
                 require_once 'Conjoon/Log.php';
                 Conjoon_Log::log("Detected 4-byte character in content_text_plain for " . "Email message with id {$id}", Zend_Log::NOTICE);
             }
         }
         if ($id <= 0) {
             return null;
         }
         // assign needed (reference) keys
         $emailItem['isRead'] = 0;
         $emailItem['id'] = $id;
         $emailItem['groupwareEmailItemsId'] = $id;
         // filter and insert into groupware_email_items_inbox
         $currFilter = $filterInbox;
         $filterInbox->setData($emailItem);
         $itemData = $filterInbox->getProcessedData();
         Conjoon_Util_Array::underscoreKeys($itemData);
         $modelInbox->addInboxData($itemData);
         // filter and insert into groupware_email_items_flag
         $currFilter = $filterFlag;
         $filterFlag->setData($emailItem);
         $itemData = $filterFlag->getProcessedData();
         Conjoon_Util_Array::underscoreKeys($itemData);
         $modelFlag->insert($itemData);
         // loop through attachments and insert into groupware_email_items_attachments
         $attachmentCount = count($emailItem['attachments']);
         $currFilter = $filterAttachment;
         for ($i = 0; $i < $attachmentCount; $i++) {
             $emailItem['attachments'][$i]['groupwareEmailItemsId'] = $id;
             $filterAttachment->setData($emailItem['attachments'][$i]);
             $itemData = $filterAttachment->getProcessedData();
             Conjoon_Util_Array::underscoreKeys($itemData);
             $modelAttachment->addAttachmentForItem($itemData, $id);
         }
         $dbAdapter->commit();
         return $id;
     } catch (Exception $e) {
         if ($e instanceof Zend_Filter_Exception) {
             $error = Conjoon_Error::fromFilter($currFilter, $e);
             $error = $error->getMessage();
         } else {
             $error = $e->getMessage();
         }
         try {
             $dbAdapter->rollBack();
         } catch (Exception $m) {
             $error .= '; ' . $m->getMessage();
         }
         return $error;
     }
 }
 /**
  * Sends an email to the specified recipients.
  * The action expects the following arguments to be passed:
  *
  * - format: The format the email should be send. Can default to
  *           "text/plain", "text/html" - or "multipart" if the email should
  *           be send both as html and plain-text.
  * - id: The id of the messge if this was loaded from an already existing
  *       draft (i.e. a draft, an email that is being replied to which is being forwarded).
  * -type: The type of teh action: if this equals to "reply", "reply_all" or "forward",
  * this message references an existing one
  * Can default to 0 or -1 if the emil was created from the scratch
  * - groupwareEmailAccountsId: An integer specifying the id of the email account of the
  *              user which will be used to send the message
  * - groupwareEmailFoldersId: The id of the folder from which this email was opened. Equals
  *             to -1 or 0 if the messge was created from scratch
  * - subject: The subject of the message
  * - message: The message as edited in the browser. Will most likely have
  *            HTML tags in it depending on the editor used
  * - to: An json encoded array with all addresses being specified in the "to"
  *       field. Addresses may be separated by a comma "," or a semicolon ";"
  * - cc: An json encoded array with all addresses being specified in the "cc"
  *       field. Addresses may be separated by a comma "," or a semicolon ";"
  * - bcc: An json encoded array with all addresses being specified in the "bcc"
  *        field. Addresses may be separated by a comma "," or a semicolon ";"
  * - attachments: An array with attachments, structure according to
  * com.conjoon.cudgets.data.FileRecord. ids for files will be stored in
  * the orgId property
  * The view awaits a fully configured email item as the response.
  */
 public function sendAction()
 {
     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();
     } 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;
     }
     // input filter does not work properly sometimes with refrenced data
     // check here for referencedData, throw an exception if not set
     if (!isset($data['referencedData']) || !is_array($data['referencedData'])) {
         throw new Exception("referencedData missing.");
     }
     /**
      * @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';
     $postedAttachments = $data['attachments'];
     $data['attachments'] = array();
     $removeAttachmentIds = $data['removedAttachments'];
     unset($data['removedAttachments']);
     // create the message object here
     $to = array();
     $cc = array();
     $bcc = array();
     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
     /**
      * @see Conjoon_BeanContext_Decorator
      */
     require_once 'Conjoon/BeanContext/Decorator.php';
     /**
      * @see Conjoon_Keys
      */
     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 sending email', 'Could not find specified account.', Conjoon_Error::LEVEL_ERROR);
         $this->view->success = false;
         $this->view->item = null;
         return;
     }
     $message = 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 ($message->getId() > 0 && !$this->isRemotePath($data['path'], $userId)) {
         $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($message->getId());
         $message->setAttachments($atts);
     }
     /**
      * @see Conjoon_Modules_Groupware_Email_Sender
      */
     require_once 'Conjoon/Modules/Groupware/Email/Sender.php';
     try {
         $transport = $this->getTransportForAccount($account);
         $assembleInformation = Conjoon_Modules_Groupware_Email_Sender::getAssembledMail($message, $account, $postedAttachments, $removeAttachmentIds, $this->getCurrentAppUser()->getId(), $transport, $data['type']);
         $assembledMail = $assembleInformation['message'];
         $postedAttachments = $assembleInformation['postedAttachments'];
         $mail = Conjoon_Modules_Groupware_Email_Sender::send($assembledMail);
     } catch (Exception $e) {
         $errorMessage = $e->getMessage();
         // check here if a message is set. We rely heavily on stream_socket_client
         // in Zend_Mail_Protocol_Abstract which may not set the error message all
         // the time. If no internet conn is available, the message will be missing
         // on windows systems, for example
         if ($errorMessage == "") {
             $errorMessage = "The message with the subject \"" . $message->getSubject() . "\" could not be sent. " . "Please check the internet connection of " . "the server this software runs on.";
         }
         $this->view->error = $this->getErrorDto('Error while sending email', $errorMessage, Conjoon_Error::LEVEL_ERROR);
         $this->view->success = false;
         $this->view->item = null;
         return;
     }
     // check here if the referenced data contains an IMAP message.
     // if this is the case, update the message with the \Answered
     // flag if applicable
     $referencedData = $message->getReferencedData();
     $referencedRemoteItem = null;
     $contextReferencedItem = null;
     $isRemoteItemReferenced = false;
     // check if the mesage was loaded from a remote draft
     // if this is the case, remove the draft from the rmeote server
     $imapAccount = $message->getId() > 0 ? $this->isRemotePath($message->getPath(), $userId) : null;
     if ($message->getId() > 0 && $imapAccount) {
         $uId = $message->getId();
         $path = $message->getPath();
         /**
          * @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();
         // 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);
         $storage->removeMessage($messageNumber);
         $storage->close();
     }
     if (!empty($referencedData) && isset($referencedData['uId']) && $referencedData['uId'] > 0) {
         $uId = $referencedData['uId'];
         $referencedPath = $referencedData['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($referencedPath));
         /**
          * @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'])) {
             $isRemoteItemReferenced = true;
             // 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);
             $flags = array('\\Seen');
             if ($data['type'] == 'reply' || $data['type'] == 'reply_all') {
                 $flags = array('\\Seen', '\\Answered');
             } else {
                 if ($data['type'] == 'forward') {
                     $flags = array('\\Seen', '$Forwarded');
                 }
             }
             $protocol->store($flags, $messageNumber, null, '+');
             $referencedRemoteItem = $this->getSingleImapListItem($imapAccount, $userId, $messageNumber, $globalName);
             // force a reconnect if internal noop fails
             Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($imapAccount);
         }
     }
     $folderMappingError = null;
     if ($account->getProtocol() == 'IMAP') {
         /**
          * @see Conjoon_Modules_Groupware_Email_ImapHelper
          */
         require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php';
         /**
          * @see Zend_Registry
          */
         require_once 'Zend/Registry.php';
         /**
          *@see Conjoon_Keys
          */
         require_once 'Conjoon/Keys.php';
         $entityManager = Zend_Registry::get(Conjoon_Keys::DOCTRINE_ENTITY_MANAGER);
         $mailAccountRepository = $entityManager->getRepository('\\Conjoon\\Data\\Entity\\Mail\\DefaultMailAccountEntity');
         $accEntity = $mailAccountRepository->findById($account->getId());
         $mappings = $accEntity->getFolderMappings();
         $globalName = "";
         for ($i = 0, $len = count($mappings); $i < $len; $i++) {
             if ($mappings[$i]->getType() == 'SENT') {
                 $globalName = $mappings[$i]->getGlobalName();
             }
         }
         if ($globalName != "") {
             /**
              * @see Conjoon_Mail_Storage_Imap
              */
             require_once 'Conjoon/Mail/Storage/Imap.php';
             $protocol = Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($account->getDto());
             $storage = new Conjoon_Mail_Storage_Imap($protocol);
             try {
                 $storage->selectFolder($globalName);
                 $response = $storage->appendMessage($mail->getSentHeaderText() . "\n\n" . $mail->getSentBodyText(), $globalName);
                 $lastMessage = -1;
                 $ret = null;
                 if (is_array($response) && isset($response[0])) {
                     $ret = explode(' ', $response[0]);
                 }
                 if (is_array($ret) && count($ret) == 2 && is_numeric($ret[0]) && trim(strtolower($ret[1])) == 'exists') {
                     $lastMessage = $ret[0];
                 }
                 if ($lastMessage == -1) {
                     $lastMessage = $storage->countMessages();
                 }
                 if ($lastMessage == -1) {
                     throw new RuntimeException("Could not find message id.");
                 }
                 // immediately setting the \Seen flag does not seemt
                 // to work. Do so by hand.
                 $storage->setFlags($lastMessage, array('\\Seen'));
             } catch (\Exception $e) {
                 $folderMappingError = true;
             }
         } else {
             $folderMappingError = true;
         }
         if ($folderMappingError) {
             $folderMappingError = $this->getErrorDto('Missing folder mapping', 'The email was sent, but a "sent" version could not be stored to the configured IMAP account. Make sure you have configured the folder mappings for this account properly.', Conjoon_Error::LEVEL_ERROR);
         } else {
             $item = $this->getSingleImapListItem($account->getDto(), $userId, $lastMessage, $globalName);
         }
         // check here if a remote item was referenced.
         // if this is not the case, get the local itemand update it's
         // references
         if (!$isRemoteItemReferenced && !$referencedRemoteItem && isset($referencedData) && isset($referencedData['uId']) && $referencedData['uId'] > 0) {
             $uId = $referencedData['uId'];
             $localFolder = $referencedData['path'][count($referencedData['path']) - 1];
             /**
              * @see Conjoon_Modules_Groupware_Email_Item_Model_Item
              */
             require_once 'Conjoon/Modules/Groupware/Email/Item/Model/Item.php';
             $iModel = new Conjoon_Modules_Groupware_Email_Item_Model_Item();
             $iModel->updateReferenceFromARemoteItem($uId, $localFolder, $userId, $data['type']);
             /**
              * @see Conjoon_Modules_Groupware_Email_Item_Filter_ItemResponse
              */
             require_once 'Conjoon/Modules/Groupware/Email/Item/Filter/ItemResponse.php';
             // 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);
             $contextReferencedItem = $itemDecorator->getItemForUserAsDto($uId, $userId);
         }
         $this->view->error = null;
         $this->view->newVersion = $message->getId() > 0;
         if ($message->getId() > 0) {
             $this->view->previousId = $message->getId();
         }
         $this->view->folderMappingError = $folderMappingError;
         $this->view->success = true;
         $this->view->item = isset($item) ? $item : null;
         $this->view->contextReferencedItem = $contextReferencedItem ? $contextReferencedItem : $referencedRemoteItem;
         return;
     }
     /**
      * @see Conjoon_Modules_Groupware_Email_Item_Filter_ItemResponse
      */
     require_once 'Conjoon/Modules/Groupware/Email/Item/Filter/ItemResponse.php';
     // 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, $data['type'], $referencedRemoteItem ? -1 : $data['referencedData']['uId'], $postedAttachments, $removeAttachmentIds);
     if (!$item) {
         $this->view->error = $this->getErrorDto('Error while saving email', 'The email was sent, but it 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(), $data['path']);
     }
     // if the sent email referenced an existing message, tr to fetch this message
     // and send it along as context-referenced item
     if (!$referencedRemoteItem) {
         $contextReferencedItem = $itemDecorator->getReferencedItemAsDto($item->id, $userId);
     }
     $this->view->error = null;
     $this->view->foldermappingError = $folderMappingError;
     $this->view->success = true;
     $this->view->item = $item;
     $this->view->contextReferencedItem = $referencedRemoteItem ? $referencedRemoteItem : (empty($contextReferencedItem) ? null : $contextReferencedItem);
 }
 public function preDispatch()
 {
     if (!$this->getRequest()->isDispatched()) {
         return;
     }
     $action = $this->getRequest()->getActionName();
     $class = get_class($this->getActionController());
     if (!isset($this->_filterKeys[$class][$action])) {
         return;
     }
     $filter = $this->_getFilter($this->_filterKeys[$class][$action]);
     $actionController = $this->getActionController();
     $data = $this->getRequest()->getParams();
     if (isset($this->_extractFromExtDirect[$class][$action])) {
         /**
          * @see Conjoon_Keys
          */
         require_once 'Conjoon/Keys.php';
         try {
             $extRequest = Zend_Registry::get(Conjoon_Keys::EXT_REQUEST_OBJECT);
         } catch (Zend_Exception $e) {
             $extRequest = null;
         }
         if ($extRequest && $extRequest->isExtRequest()) {
             $data = $this->getRequest()->getParam('data');
             $data = $data[0];
         }
     }
     $filter->setData($data);
     try {
         $filteredData = $filter->getProcessedData();
     } catch (Zend_Filter_Exception $e) {
         /**
          * @see Conjoon_Error
          */
         require_once 'Conjoon/Error.php';
         $error = Conjoon_Error::fromFilter($filter, $e);
         /**
          * @see Conjoon_Filter_Exception
          */
         require_once 'Conjoon/Filter/Exception.php';
         throw new Conjoon_Filter_Exception($error->getMessage());
     }
     foreach ($filteredData as $key => $value) {
         $this->getRequest()->setParam($key, $value);
     }
 }
 /**
  * Deletes a folder permanently
  *
  * POST:
  * - integer id : the id of the folder to delete
  */
 public function deleteFolderAction()
 {
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Filter/Folder.php';
     $filter = new Conjoon_Modules_Groupware_Email_Folder_Filter_Folder($_POST, Conjoon_Modules_Groupware_Email_Folder_Filter_Folder::CONTEXT_DELETE);
     if ($this->imapFolderDeleted($_POST['path'])) {
         $this->view->success = true;
         $this->view->error = null;
         return;
     }
     $filteredData = array();
     try {
         $filteredData = $filter->getProcessedData();
     } catch (Zend_Filter_Exception $e) {
         require_once 'Conjoon/Error.php';
         $error = Conjoon_Error::fromFilter($filter, $e);
         $this->view->success = false;
         $this->view->error = $error->getDto();
         return;
     }
     require_once 'Conjoon/Keys.php';
     $user = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT)->getIdentity();
     $userId = $user->getId();
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Facade
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Facade.php';
     $facade = Conjoon_Modules_Groupware_Email_Folder_Facade::getInstance();
     $ret = $facade->deleteLocalFolderForUser($filteredData['id'], $userId);
     if (!$ret) {
         require_once 'Conjoon/Error.php';
         $error = new Conjoon_Error();
         $error = $error->getDto();
         $error->title = 'Error';
         $error->level = Conjoon_Error::LEVEL_WARNING;
         $error->message = 'Could not delete the specified folder.';
         $this->view->success = false;
         $this->view->error = $error;
         return;
     }
     $this->view->ret = $ret;
     $this->view->success = true;
     $this->view->error = null;
 }