コード例 #1
0
 /**
  * Queries an email account for new wmails. If an account id was posted,
  * only the specified account will be queried.
  * Sends all newly fetched emails back to the client.
  * This method will also check beforehand for any IMAP account that's about
  * to be queried for new emails, if a default inbox folder was configured
  * for this account. If no valid folder was found, the emthod will not query
  * any account for new messages, and instead return an additional property
  * named "missingInboxForAccountId", which holds the account id of the first
  * account found for which no inbox folder was configured.
  *
  *
  */
 public function fetchEmailsAction()
 {
     /*@REMOVE@*/
     if (!$this->_helper->connectionCheck()) {
         $this->view->success = true;
         $this->view->totalCount = 0;
         $this->view->items = array();
         $this->view->error = null;
         return;
     }
     /*@REMOVE@*/
     if (isset($_POST['accountId'])) {
         $accountId = (int) $_POST['accountId'];
         if ($accountId < 0) {
             $this->view->success = true;
             $this->view->totalCount = 0;
             $this->view->items = array();
             $this->view->error = null;
             return;
         } else {
             if ($accountId == 0) {
                 $accountId = null;
             }
         }
     } else {
         $accountId = null;
     }
     require_once 'Conjoon/Keys.php';
     require_once 'Conjoon/Modules/Groupware/Email/Letterman.php';
     require_once 'Conjoon/BeanContext/Decorator.php';
     require_once 'Conjoon/Error.php';
     $auth = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT);
     $userId = $auth->getIdentity()->getId();
     $emails = array();
     $errorMessages = array();
     $time = time();
     $currentAccount = null;
     try {
         $accountDecorator = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Account_Model_Account');
         $noop = false;
         if ($accountId === null) {
             $accounts = $accountDecorator->getAccountsForUserAsEntity($userId);
             if (count($accounts) == 0) {
                 $noop = true;
             }
         } else {
             $account = $accountDecorator->getAccountAsEntity($accountId, $userId);
             if ($account == null) {
                 $noop = true;
             } else {
                 $accounts = array($account);
             }
         }
         if ($noop) {
             $this->view->success = true;
             $this->view->totalCount = 0;
             $this->view->items = array();
             $this->view->error = null;
             return;
         }
         /**
          * @see Conjoon_Modules_Groupware_Email_Folder_Facade
          */
         require_once 'Conjoon/Modules/Groupware/Email/Folder/Facade.php';
         /**
          * @see Conjoon_Modules_Groupware_Email_Item_ItemListRequestFacade
          */
         require_once 'Conjoon/Modules/Groupware/Email/Item/ItemListRequestFacade.php';
         $itemListRequestFacade = Conjoon_Modules_Groupware_Email_Item_ItemListRequestFacade::getInstance();
         //$facade = Conjoon_Modules_Groupware_Email_Folder_Facade::getInstance();
         $imapEmails = array();
         for ($i = 0, $accLen = count($accounts); $i < $accLen; $i++) {
             $currentAccount =& $accounts[$i];
             // check here if we have an actual INBOX folder configured for the
             // account.
             if ($currentAccount->getProtocol() == 'IMAP') {
                 continue;
             }
             $tmpEmails = Conjoon_Modules_Groupware_Email_Letterman::fetchEmails($userId, $currentAccount);
             $emails = array_merge($emails, $tmpEmails['fetched']);
             $errorMessages = array_merge($errorMessages, $tmpEmails['errors']);
         }
     } catch (Zend_Mail_Protocol_Exception $e) {
         $errorMessages[] = $e->getMessage() . "\n - host: " . $currentAccount->getServerInbox() . ':' . $currentAccount->getPortInbox() . "\n user: "******" (using password: "******"\n", $errorMessages), Conjoon_Error::LEVEL_ERROR);
     }
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * Bulk sends emails. Awaits the parameter ids as a numeric array with the ids of
  * the emails which should get send.
  *
  */
 public function bulkSendAction()
 {
     /*@REMOVE@*/
     if (!$this->_helper->connectionCheck()) {
         /**
          * @see Conjoon_Error_Factory
          */
         require_once 'Conjoon/Error/Factory.php';
         $this->view->success = false;
         $this->view->sentItems = array();
         $this->view->error = null;
         $this->view->contextReferencedItems = array();
         $this->view->error = Conjoon_Error_Factory::createError("Unexpected connection failure while trying to bulk-send emails. " . "Please try again.", Conjoon_Error::LEVEL_WARNING, Conjoon_Error::DATA)->getDto();
         return;
     }
     /*@REMOVE@*/
     $toSend = $_POST['ids'];
     if ($this->_helper->conjoonContext()->getCurrentContext() == self::CONTEXT_JSON) {
         require_once 'Zend/Json.php';
         $toSend = Zend_Json::decode($toSend, Zend_Json::TYPE_ARRAY);
     }
     $date = null;
     if (isset($_POST['date'])) {
         require_once 'Conjoon/Filter/DateIso8601.php';
         $dateFilter = new Conjoon_Filter_DateIso8601();
         $date = $dateFilter->filter((int) $_POST['date']);
     }
     /**
      * @see Conjoon_Filter_EmailRecipients
      */
     require_once 'Conjoon/Filter/EmailRecipients.php';
     /**
      * @see Conjoon_Modules_Groupware_Email_Item_Filter_ItemResponse
      */
     require_once 'Conjoon/Modules/Groupware/Email/Item/Filter/ItemResponse.php';
     /**
      * @see Conjoon_Modules_Groupware_Email_Address
      */
     require_once 'Conjoon/Modules/Groupware/Email/Address.php';
     /**
      * @see Conjoon_Modules_Groupware_Email_Draft
      */
     require_once 'Conjoon/Modules/Groupware/Email/Draft.php';
     /**
      * @see Conjoon_BeanContext_Inspector
      */
     require_once 'Conjoon/BeanContext/Inspector.php';
     /**
      * @see Conjoon_BeanContext_Decorator
      */
     require_once 'Conjoon/BeanContext/Decorator.php';
     /**
      * @see Conjoon_Util_Array
      */
     require_once 'Conjoon/Util/Array.php';
     /**
      * @see Conjoon_Keys
      */
     require_once 'Conjoon/Keys.php';
     /**
      * @see Conjoon_Modules_Groupware_Email_Draft_Model_Draft
      */
     require_once 'Conjoon/Modules/Groupware/Email/Draft/Model/Draft.php';
     /**
      * @see Conjoon_Modules_Groupware_Email_Draft_Filter_DraftInput
      */
     require_once 'Conjoon/Modules/Groupware/Email/Draft/Filter/DraftInput.php';
     /**
      * @see Conjoon_Modules_Groupware_Email_Sender
      */
     require_once 'Conjoon/Modules/Groupware/Email/Sender.php';
     $auth = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT);
     $userId = $auth->getIdentity()->getId();
     $draftFilter = new Conjoon_Modules_Groupware_Email_Draft_Filter_DraftInput(array(), Conjoon_Filter_Input::CONTEXT_CREATE);
     $draftModel = new Conjoon_Modules_Groupware_Email_Draft_Model_Draft();
     $accountDecorator = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Account_Model_Account');
     $recipientsFilter = new Conjoon_Filter_EmailRecipients();
     $newVersions = array();
     $sendItems = array();
     $contextReferencedItems = array();
     $errors = array();
     foreach ($toSend as $pathInfo) {
         $remoteInfo = array();
         $id = $pathInfo['id'];
         $path = $pathInfo['path'];
         $account = null;
         $remoteAttachments = array();
         // check if path is remote!
         $isRemote = $this->isRemotePath($path, $userId);
         if ($isRemote) {
             $rawDraft = $this->getRawImapMessage($id, $path);
             if (empty($rawDraft)) {
                 continue;
             }
             //we have to post the existing attachments of the remote draft
             // again when assembling the message to send.
             // Otherwise the sender would not know which attachments should get send
             // along with the message
             $remoteAttachments = $rawDraft['attachments'];
             foreach ($remoteAttachments as &$remoteAttachment) {
                 $remoteAttachment['metaType'] = 'emailAttachment';
                 $remoteAttachment['name'] = $remoteAttachment['fileName'];
             }
             $remoteInfo = array('uid' => $id, 'account' => $isRemote, 'path' => $path);
             $rawDraft['groupwareEmailAccountsId'] = $isRemote->id;
             $account = $accountDecorator->getAccountAsEntity($rawDraft['groupwareEmailAccountsId'], $userId);
         } else {
             $rawDraft = $draftModel->getDraft($id, $userId);
             $account = $accountDecorator->getAccountAsEntity($rawDraft['groupware_email_accounts_id'], $userId);
         }
         // no account found?
         if (!$account) {
             /**
              * @todo think about using the standard account as a fallback or use at last
              * an error message to inform the user that the account used to write this email
              * is not available anymore
              */
             continue;
         }
         $id = (int) $id;
         if ($id <= 0) {
             continue;
         }
         if (empty($rawDraft)) {
             continue;
         }
         Conjoon_Util_Array::camelizeKeys($rawDraft);
         $rawDraft['to'] = $recipientsFilter->filter($rawDraft['to']);
         $rawDraft['cc'] = $recipientsFilter->filter($rawDraft['cc']);
         $rawDraft['bcc'] = $recipientsFilter->filter($rawDraft['bcc']);
         // create the message object here
         $to = array();
         $cc = array();
         $bcc = array();
         foreach ($rawDraft['cc'] as $dcc) {
             $add = new Conjoon_Modules_Groupware_Email_Address($dcc);
             $cc[] = $add;
         }
         foreach ($rawDraft['bcc'] as $dbcc) {
             $add = new Conjoon_Modules_Groupware_Email_Address($dbcc);
             $bcc[] = $add;
         }
         foreach ($rawDraft['to'] as $dto) {
             $add = new Conjoon_Modules_Groupware_Email_Address($dto);
             $to[] = $add;
         }
         $rawDraft['to'] = $to;
         $rawDraft['cc'] = $cc;
         $rawDraft['bcc'] = $bcc;
         $message = Conjoon_BeanContext_Inspector::create('Conjoon_Modules_Groupware_Email_Draft', $rawDraft, true);
         if ($date !== null) {
             $message->setDate($date);
         }
         try {
             $transport = $this->getTransportForAccount($account);
             $assembleInformation = Conjoon_Modules_Groupware_Email_Sender::getAssembledMail($message, $account, $remoteAttachments, array(), $this->getCurrentAppUser()->getId(), $transport);
             $assembledMail = $assembleInformation['message'];
             $postedAttachments = $assembleInformation['postedAttachments'];
             $mail = Conjoon_Modules_Groupware_Email_Sender::send($assembledMail);
         } catch (Exception $e) {
             $errors[] = array('subject' => $message->getSubject(), 'accountName' => $account->getName(), 'reason' => $e->getMessage());
             continue;
         }
         if ($isRemote) {
             /**
              * @see Conjoon_Modules_Groupware_Email_ImapHelper
              */
             require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php';
             $uId = $remoteInfo['uid'];
             $account = $remoteInfo['account'];
             $path = $remoteInfo['path'];
             // check if folder is remote folder
             /**
              * @see Conjoon_Text_Parser_Mail_MailboxFolderPathJsonParser
              */
             require_once 'Conjoon/Text/Parser/Mail/MailboxFolderPathJsonParser.php';
             $parser = new Conjoon_Text_Parser_Mail_MailboxFolderPathJsonParser();
             $pathInfo = $parser->parse(json_encode($path));
             /**
              * @see Conjoon_Modules_Groupware_Email_Folder_Facade
              */
             require_once 'Conjoon/Modules/Groupware/Email/Folder/Facade.php';
             $facade = Conjoon_Modules_Groupware_Email_Folder_Facade::getInstance();
             // get the account for the root folder first
             $imapAccount = $facade->getImapAccountForFolderIdAndUserId($pathInfo['rootId'], $userId);
             if ($imapAccount && !empty($pathInfo) && $facade->isRemoteFolder($pathInfo['rootId'])) {
                 // if remote, where is the referenced mail stored?
                 $globalName = $facade->getAssembledGlobalNameForAccountAndPath($imapAccount, $pathInfo['path']);
                 /**
                  * @see Conjoon_Modules_Groupware_Email_ImapHelper
                  */
                 require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php';
                 /**
                  * @see Conjoon_Mail_Storage_Imap
                  */
                 require_once 'Conjoon/Mail/Storage/Imap.php';
                 $protocol = Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($imapAccount);
                 $storage = new Conjoon_Mail_Storage_Imap($protocol);
                 // get the number of the message by it's unique id
                 $storage->selectFolder($globalName);
                 $messageNumber = $storage->getNumberByUniqueId($uId);
                 // move from sent folder
                 $sentGlobalName = $this->getGlobalNameForFolderType($imapAccount, 'SENT');
                 if (!$sentGlobalName) {
                     continue;
                 }
                 $storage->copyMessage($messageNumber, $sentGlobalName);
                 $storage->selectFolder($sentGlobalName);
                 $newMessageNumber = $storage->countMessages();
                 $storage->selectFolder($globalName);
                 $storage->removeMessage($storage->getNumberByUniqueId($uId));
                 $storage->close();
             }
             // put email into sent folder
             $protocol = Conjoon_Modules_Groupware_Email_ImapHelper::reuseImapProtocolForAccount($imapAccount);
             $storage = new Conjoon_Mail_Storage_Imap($protocol);
             // read out single item
             $item = $this->getSingleImapListItem($account, $userId, $newMessageNumber, $sentGlobalName);
             $newVersions[$uId] = $item['id'];
             $sendItems[] = $item;
         } else {
             // if the email was send successfully, save it into the db and
             // return the params savedId (id of the newly saved email)
             // and savedFolderId (id of the folder where the email was saved in)
             $itemDecorator = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Item_Model_Item', new Conjoon_Modules_Groupware_Email_Item_Filter_ItemResponse(array(), Conjoon_Filter_Input::CONTEXT_RESPONSE), false);
             $item = $itemDecorator->saveSentEmailAsDto($message, $account, $userId, $mail, '');
             if (!$item) {
                 continue;
             }
             $sendItems[] = $item;
             $cri = $itemDecorator->getReferencedItemAsDto($item->id, $userId);
             if (!empty($cri)) {
                 $contextReferencedItems[] = $cri;
             }
         }
     }
     if (!empty($errors)) {
         /**
          * @see Conjoon_Error
          */
         require_once 'Conjoon/Error.php';
         $m = array();
         $m[] = "One or more messages could not be sent:";
         for ($i = 0, $len = count($errors); $i < $len; $i++) {
             $m[] = "Message " . ($i + 1) . ":";
             $m[] = "Subject: \"" . $errors[$i]['subject'] . "\"";
             $m[] = "Account: " . $errors[$i]['accountName'];
             $m[] = "Failure reason: " . $errors[$i]['reason'];
         }
         $errorMessage = implode("\n", $m);
         $error = new Conjoon_Error();
         $error->setLevel(Conjoon_Error::LEVEL_WARNING);
         $error->setType(Conjoon_Error::DATA);
         $error->setMessage($errorMessage);
     }
     $this->view->newVersions = $newVersions;
     $this->view->success = true;
     $this->view->sentItems = $sendItems;
     $this->view->error = isset($error) ? $error->getDto() : null;
     $this->view->contextReferencedItems = $contextReferencedItems;
 }