예제 #1
0
 /**
  * @inheritdoc
  */
 public function __construct($options)
 {
     /**
      * @see \Conjoon\Argument\ArgumentCheck
      */
     require_once 'Conjoon/Argument/ArgumentCheck.php';
     $data = array('path' => $options);
     ArgumentCheck::check(array('path' => array('type' => 'string', 'allowEmpty' => false)), $data);
     $options = $data['path'];
     /**
      * @see Conjoon_Text_Parser_Mail_MailboxFolderPathJsonParser
      */
     require_once 'Conjoon/Text/Parser/Mail/MailboxFolderPathJsonParser.php';
     $parser = new \Conjoon_Text_Parser_Mail_MailboxFolderPathJsonParser();
     try {
         $parts = $parser->parse($options);
     } catch (Conjoon_Text_Parserexception $e) {
         /**
          * @see \Conjoon\Mail\Client\Folder\FolderPathException
          */
         require_once 'Conjoon/Mail/Client/Folder/FolderPathException.php';
         throw new FolderPathException("Could not extract path info from \"{$options}\" - exception " . "triggered by previous exception", 0, $e);
     }
     $this->_path = $parts['path'];
     $this->_nodeId = $parts['nodeId'];
     $this->_rootId = $parts['rootId'];
 }
 /**
  *
  *
  */
 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();
       }*/
 }
 protected function isRemotePath($path, $userId)
 {
     // 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'])) {
         return $imapAccount;
     }
     return null;
 }
 /**
  *
  */
 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 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;
 }