/**
  *
  *
  */
 protected function moveImapToOutbox($account, $draft, $userId, $postedAttachments, $removeAttachmentIds)
 {
     // check ifmapping is okay
     $accountId = $account->getId();
     $em = Zend_Registry::get(Conjoon_Keys::DOCTRINE_ENTITY_MANAGER);
     $rep = $em->getRepository('\\Conjoon\\Data\\Entity\\Mail\\DefaultMailAccountEntity');
     $accountEntity = $rep->findById($accountId);
     $mappings = $accountEntity->getFolderMappings();
     $globalName = "";
     for ($i = 0, $len = count($mappings); $i < $len; $i++) {
         if ($mappings[$i]->getType() == 'OUTBOX') {
             $globalName = $mappings[$i]->getGlobalName();
             break;
         }
     }
     if ($globalName == "") {
         $this->view->error = $this->getErrorDto('Missing folder mapping', 'The message cannot be moved into the outbox folder, since no valid outbox folder was found. Did you configure the folder mappings of the account?', Conjoon_Error::LEVEL_ERROR);
         $this->view->success = false;
         $this->view->item = null;
         return;
     }
     // assemble mail
     /**
      * @see Conjoon_Modules_Groupware_Email_Sender
      */
     require_once 'Conjoon/Modules/Groupware/Email/Sender.php';
     $assembleInformation = Conjoon_Modules_Groupware_Email_Sender::getAssembledMail($draft, $account, $postedAttachments, $removeAttachmentIds, $userId, $this->getTransportForAccount($account));
     $mail = $assembleInformation['message'];
     /**
      * @see Conjoon_Mail_Storage_Imap
      */
     require_once 'Conjoon/Mail/Storage/Imap.php';
     /**
      * @see Conjoon_Modules_Groupware_Email_ImapHelper
      */
     require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php';
     /*REMOVE DRAFT!*/
     if ($draft->getId() > 0) {
         $uId = $draft->getId();
         $path = $draft->getPath();
         // 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?
             $prevGlobalName = $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($prevGlobalName);
             $messageNumber = $storage->getNumberByUniqueId($uId);
             $storage->removeMessage($messageNumber);
             $storage->close();
         }
     }
     /* ^^EO REMOVE DRAFT */
     $protocol = Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($account->getDto());
     $storage = new Conjoon_Mail_Storage_Imap($protocol);
     $storage->selectFolder($globalName);
     $response = $storage->appendMessage($mail->getExpectedHeaderText() . "\n\n" . $mail->getExpectedBodyText(), $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.");
     }
     $protocol->store(array('\\Seen'), $lastMessage, null, '+');
     $item = $this->getSingleImapListItem($account->getDto(), $userId, $lastMessage, $globalName);
     $this->view->error = null;
     $this->view->success = true;
     $this->view->item = $item;
     /*$this->view->newVersion    = $newVersion;
       if ($newVersion) {
           $this->view->previousId = $draft->getId();
       }*/
 }
Example #2
0
 /**
  * Gathers all needed information to tranform an imap folder to a
  * Conjoon_Modules_Groupware_Email_Folder_Dto obejct.
  *
  * @param Zend_Mail_Storage_Folder $folder
  * @param Conjoon_Modules_Groupware_Email_Account_Dto $account
  * @param Zend_Mail_Protocol_Imap $protocol
  * @param boolean $isRootLevel Whether the folder is on the first level of
  * the mailbox hierarchy
  *
  * @return Conjoon_Modules_Groupware_Email_Folder_Dto
  */
 private function _transformImapFolder(Zend_Mail_Storage_Folder $folder, Conjoon_Modules_Groupware_Email_Account_Dto $account, Zend_Mail_Protocol_Imap $protocol, $isRootLevel = false, $type = 'folder')
 {
     $delim = Conjoon_Modules_Groupware_Email_ImapHelper::getFolderDelimiterForImapAccount($account);
     $globalName = $folder->getGlobalName();
     $path = explode($delim, $globalName);
     $path = $path[count($path) - 1];
     $pendingCount = 0;
     if (!$this->itemListRequestFacade) {
         $this->itemListRequestFacade = Conjoon_Modules_Groupware_Email_Item_ItemListRequestFacade::getInstance();
     }
     if ($folder->isSelectable()) {
         try {
             $pendingCount = $this->itemListRequestFacade->getPendingCountForGlobalName($account, $globalName);
         } catch (Exception $e) {
             // ignore
         }
     }
     $childCount = 0;
     if (!$folder->isLeaf()) {
         $protocol = Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($account);
         /**
          * @see Zend_Mail_Storage_Imap
          */
         require_once 'Zend/Mail/Storage/Imap.php';
         $imap = new Zend_Mail_Storage_Imap($protocol);
         /**
          * @ticket CN-595
          */
         if ($globalName === "INBOX") {
             $iFolders = $imap->getFolders(null)->getChildren();
         } else {
             $iFolders = $imap->getFolders($globalName)->getChildren();
         }
         foreach ($iFolders as $tmpFolder) {
             $childCount++;
         }
     }
     return Conjoon_Modules_Groupware_Email_ImapHelper::transformToFolderDto($folder, $isRootLevel, array('id' => $account->id . '_' . $globalName, 'idForPath' => $path, 'pendingCount' => $pendingCount, 'type' => $type, 'childCount' => $childCount));
 }
 /**
  * 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;
 }
 /**
  *
  * @param $accountName
  * @param $globalName
  */
 public function getPendingCountForGlobalName($accountDto, $globalName)
 {
     /**
      * @see Zend_Registry
      */
     require_once 'Zend/Registry.php';
     /**
      * @see Conjoon_Keys
      */
     require_once 'Conjoon/Keys.php';
     $em = Zend_Registry::get(Conjoon_Keys::DOCTRINE_ENTITY_MANAGER);
     $rep = $em->getRepository('\\Conjoon\\Data\\Entity\\Mail\\DefaultMailAccountEntity');
     $entity = $rep->findById($accountDto->id);
     if (!$entity) {
         return 0;
     }
     $mappings = $entity->getFolderMappings();
     /**
      * @see Conjoon_Modules_Groupware_Email_ImapHelper
      */
     require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php';
     $protocol = Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($accountDto);
     /**
      * @see Zend_Mail_Storage_Imap
      */
     require_once 'Conjoon/Mail/Storage/Imap.php';
     $storage = new Conjoon_Mail_Storage_Imap($protocol);
     // return unsee for all except outbox and draft, where we will return
     // the total count
     try {
         for ($i = 0, $len = count($mappings); $i < $len; $i++) {
             if (($mappings[$i]->getType() == 'DRAFT' || $mappings[$i]->getType() == 'OUTBOX') && $mappings[$i]->getGlobalName() == $globalName) {
                 $storage->selectFolder($globalName);
                 return $storage->countMessages();
             }
         }
         $protocol->select($globalName);
         $res = $protocol->requestAndResponse('SEARCH', array('UNSEEN'));
         if (is_array($res)) {
             $res = $res[0];
             if ($res[0] === 'SEARCH') {
                 array_shift($res);
             }
             return count($res);
         }
     } catch (Exception $e) {
         // ignore
     }
     return 0;
 }
Example #5
0
 /**
  * Returns either a cached list of email accounts for a user, or
  * the accounts out of the database.
  *
  * @param array $options An associative array with the following
  * key value/pairs:
  *   - userId: the id of the user to fetch all email accounts for
  * @param Conjoon_BeanContext_Decoratable $model
  *
  * @return Array an array with instances of
  * Conjoon_Modules_Groupware_Feeds_Account_Model_Account
  */
 protected function _build(array $options, Conjoon_BeanContext_Decoratable $model)
 {
     $userId = $options['userId'];
     /**
      * @see Conjoon_BeanContext_Decorator
      */
     require_once 'Conjoon/BeanContext/Decorator.php';
     $decoratedModel = new Conjoon_BeanContext_Decorator($model);
     $accounts = $decoratedModel->getAccountsForUserAsDto($userId);
     /**
      * @see Conjoon_Modules_Groupware_Email_ImapHelper
      */
     require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php';
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Facade
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Facade.php';
     $facade = Conjoon_Modules_Groupware_Email_Folder_Facade::getInstance();
     for ($i = 0, $len = count($accounts); $i < $len; $i++) {
         $dto =& $accounts[$i];
         if ($dto->protocol == 'IMAP') {
             $folderMappings =& $dto->folderMappings;
             $folder = null;
             try {
                 $folder = $facade->getRootFolderForAccountId($dto, $userId);
                 $folder = $folder[0];
             } catch (Exception $e) {
                 // connection exception ignore
             }
             for ($a = 0, $lena = count($folderMappings); $a < $lena; $a++) {
                 if (!$folder) {
                     // connection exception, ignore
                     $folderMappings[$a]['globalName'] = "";
                     $folderMappings[$a]['delimiter'] = "";
                     $folderMappings[$a]['path'] = array();
                     continue;
                 }
                 try {
                     $folderMappings[$a]['delimiter'] = Conjoon_Modules_Groupware_Email_ImapHelper::getFolderDelimiterForImapAccount($dto);
                     $folderMappings[$a]['path'] = array_merge(array('root', $folder['id']), Conjoon_Modules_Groupware_Email_ImapHelper::splitFolderForImapAccount($folderMappings[$a]['globalName'], $dto));
                 } catch (Exception $e) {
                     // connection exception, ignore
                     $folderMappings[$a]['globalName'] = "";
                     $folderMappings[$a]['delimiter'] = "";
                     $folderMappings[$a]['path'] = array();
                 }
             }
         }
         if (!$dto->isOutboxAuth) {
             $dto->usernameOutbox = "";
             $dto->passwordOutbox = "";
         }
         $dto->passwordOutbox = str_pad("", strlen($dto->passwordOutbox), '*');
         $dto->passwordInbox = str_pad("", strlen($dto->passwordInbox), '*');
     }
     return $accounts;
 }
 /**
  *
  */
 protected function imapItemsMoved(array $toMove, $fromPath, $toPath)
 {
     require_once 'Conjoon/Keys.php';
     $auth = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT);
     $userId = $auth->getIdentity()->getId();
     // 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($fromPath);
     $pathInfoTo = $parser->parse($toPath);
     /**
      * @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'])) {
         return false;
     }
     $globalNameFrom = $facade->getAssembledGlobalNameForAccountAndPath($imapAccount, $pathInfo['path']);
     $globalNameTo = $facade->getAssembledGlobalNameForAccountAndPath($imapAccount, $pathInfoTo['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);
     foreach ($toMove as $values) {
         $uId = $values['id'];
         $storage->selectFolder($globalNameFrom);
         $messageNumber = $storage->getNumberByUniqueId($uId);
         $storage->copyMessage($messageNumber, $globalNameTo);
         // go to target folder and flag message as seen
         $storage->selectFolder($globalNameTo);
         $num = $storage->countMessages();
         $protocol->store(array('\\Seen'), $num, null, '+');
     }
     $storage->selectFolder($globalNameFrom);
     foreach ($toMove as $values) {
         $uId = $values['id'];
         $messageNumber = $storage->getNumberByUniqueId($uId);
         $protocol->store(array('\\Deleted'), $messageNumber, null, '+');
     }
     $protocol->expunge();
     $storage->close();
     return true;
 }
 /**
  *
  */
 protected function getSingleImapListItem($accountDto, $userId, $messageNumber, $globalName)
 {
     /**
      * @see Conjoon_Modules_Groupware_Email_Item_ItemListRequestFacade
      */
     require_once 'Conjoon/Modules/Groupware/Email/Item/ItemListRequestFacade.php';
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Facade
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Facade.php';
     $folderFacade = Conjoon_Modules_Groupware_Email_Folder_Facade::getInstance();
     $rootFolder = $folderFacade->getRootFolderForAccountId($accountDto, $userId);
     $itemFacade = Conjoon_Modules_Groupware_Email_Item_ItemListRequestFacade::getInstance();
     $delimiter = Conjoon_Modules_Groupware_Email_ImapHelper::getFolderDelimiterForImapAccount($accountDto);
     $list = $itemFacade->getEmailItemList(array('rootId' => $rootFolder[0]->id, 'path' => explode($delimiter, $globalName)), $userId, array(), false, $messageNumber, $messageNumber);
     return $list[0];
 }
 /**
  *
  */
 protected function imapFolderDeleted($path)
 {
     require_once 'Conjoon/Keys.php';
     $auth = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT);
     $userId = $auth->getIdentity()->getId();
     // 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($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'])) {
         return false;
     }
     $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);
     $storage->removeFolder($globalName);
     $storage->close();
     return true;
 }