Ejemplo n.º 1
0
 /**
  * @NoAdminRequired
  * @param $accountId
  * @param $folders
  * @return JSONResponse
  */
 public function detectChanges($accountId, $folders)
 {
     try {
         $query = [];
         foreach ($folders as $folder) {
             $folderId = base64_decode($folder['id']);
             $parts = explode('/', $folderId);
             if (count($parts) > 1 && $parts[1] === 'FLAGGED') {
                 continue;
             }
             if (isset($folder['error'])) {
                 continue;
             }
             $query[$folderId] = $folder;
         }
         $account = $this->accountService->find($this->currentUserId, $accountId);
         $mailBoxes = $account->getChangedMailboxes($query);
         return new JSONResponse($mailBoxes);
     } catch (\Horde_Imap_Client_Exception $e) {
         $response = new JSONResponse();
         $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
         return $response;
     } catch (DoesNotExistException $e) {
         return new JSONResponse();
     }
 }
Ejemplo n.º 2
0
 /**
  * @param int $accountId
  * @return \OCA\Mail\Service\IAccount
  */
 private function getAccount($accountId)
 {
     if (!array_key_exists($accountId, $this->accounts)) {
         $this->accounts[$accountId] = $this->accountService->find($this->currentUserId, $accountId);
     }
     return $this->accounts[$accountId];
 }
Ejemplo n.º 3
0
 /**
  * @NoAdminRequired
  * 
  * @param int $accountId
  * @param string $subject
  * @param string $body
  * @param string $to
  * @param string $cc
  * @param string $bcc
  * @param int $uid
  * @param string $messageId
  * @return JSONResponse
  */
 public function draft($accountId, $subject, $body, $to, $cc, $bcc, $uid, $messageId)
 {
     if (is_null($uid)) {
         $this->logger->info("Saving a new draft in account <{$accountId}>");
     } else {
         $this->logger->info("Updating draft <{$uid}> in account <{$accountId}>");
     }
     $account = $this->accountService->find($this->currentUserId, $accountId);
     if ($account instanceof UnifiedAccount) {
         list($account) = $account->resolve($messageId);
     }
     if (!$account instanceof Account) {
         return new JSONResponse(array('message' => 'Invalid account'), Http::STATUS_BAD_REQUEST);
     }
     $message = $account->newMessage();
     $message->setTo(Message::parseAddressList($to));
     $message->setSubject($subject ?: '');
     $message->setFrom($account->getEMailAddress());
     $message->setCC(Message::parseAddressList($cc));
     $message->setBcc(Message::parseAddressList($bcc));
     $message->setContent($body);
     // create transport and save message
     try {
         $newUID = $account->saveDraft($message, $uid);
     } catch (\Horde_Exception $ex) {
         $this->logger->error('Saving draft failed: ' . $ex->getMessage());
         return new JSONResponse(['message' => $ex->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
     }
     return new JSONResponse(['uid' => $newUID]);
 }
Ejemplo n.º 4
0
 /**
  * @param $messageId
  * @return array
  */
 public function resolve($messageId)
 {
     $data = json_decode(base64_decode($messageId), true);
     $account = $this->accountService->find($this->userId, $data[0]);
     $inbox = $account->getInbox();
     $messageId = $data[1];
     return [$account, base64_encode($inbox->getFolderId()), $messageId];
 }
Ejemplo n.º 5
0
 /**
  * @NoAdminRequired
  * 
  * @param int $accountId
  * @param string $subject
  * @param string $body
  * @param string $to
  * @param string $cc
  * @param string $bcc
  * @param int $uid
  * @param string $messageId
  * @return JSONResponse
  */
 public function draft($accountId, $subject, $body, $to, $cc, $bcc, $uid, $messageId)
 {
     if (is_null($uid)) {
         $this->logger->info("Saving a new draft in account <{$accountId}>");
     } else {
         $this->logger->info("Updating draft <{$uid}> in account <{$accountId}>");
     }
     $account = $this->accountService->find($this->currentUserId, $accountId);
     if ($account instanceof UnifiedAccount) {
         list($account) = $account->resolve($messageId);
     }
     if (!$account instanceof Account) {
         return new JSONResponse(array('message' => 'Invalid account'), Http::STATUS_BAD_REQUEST);
     }
     // get sender data
     $headers = [];
     $from = new Horde_Mail_Rfc822_Address($account->getEMailAddress());
     $from->personal = $account->getName();
     $headers['From'] = $from;
     $headers['Subject'] = $subject;
     if (trim($cc) !== '') {
         $headers['Cc'] = trim($cc);
     }
     if (trim($bcc) !== '') {
         $headers['Bcc'] = trim($bcc);
     }
     $headers['To'] = $to;
     $headers['Date'] = Horde_Mime_Headers_Date::create();
     // build mime body
     $mail = new Horde_Mime_Mail();
     $mail->addHeaders($headers);
     $bodyPart = new Horde_Mime_Part();
     $bodyPart->appendContents($body, ['encoding' => \Horde_Mime_Part::ENCODE_8BIT]);
     $mail->setBasePart($bodyPart);
     // create transport and save message
     try {
         // save the message in the drafts folder
         $draftsFolder = $account->getDraftsFolder();
         /** @var resource $raw */
         $raw = $mail->getRaw();
         $raw = stream_get_contents($raw);
         $newUid = $draftsFolder->saveDraft($raw);
         // delete old version if one exists
         if (!is_null($uid)) {
             $folderId = $draftsFolder->getFolderId();
             $this->logger->debug("deleting outdated draft <{$uid}> in folder <{$folderId}>");
             $draftsFolder->setMessageFlag($uid, \Horde_Imap_Client::FLAG_DELETED, true);
             $account->deleteDraft($uid);
             $this->logger->debug("draft <{$uid}> deleted");
         }
     } catch (\Horde_Exception $ex) {
         $this->logger->error('Saving draft failed: ' . $ex->getMessage());
         return new JSONResponse(['message' => $ex->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
     }
     return new JSONResponse(['uid' => $newUid]);
 }
Ejemplo n.º 6
0
 /**
  * @param int $accountId
  * @return \OCA\Mail\Service\IAccount
  */
 private function getAccount($accountId)
 {
     return $this->accountService->find($this->currentUserId, $accountId);
 }