diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-02-20 18:12:11 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-02-24 09:12:16 +0300 |
commit | 46916ee4f396e71075fd228a87ef294e38825dea (patch) | |
tree | fbe43ebdd9862f3992ea60da7af40ea1c627a05e /lib | |
parent | 5be88a693bf7e516b1159f3c0500302c0adbe514 (diff) |
Make envelope lists more versatile
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Contracts/IMailSearch.php | 13 | ||||
-rwxr-xr-x | lib/Controller/MessagesController.php | 40 | ||||
-rw-r--r-- | lib/Service/Search/MailSearch.php | 21 |
3 files changed, 69 insertions, 5 deletions
diff --git a/lib/Contracts/IMailSearch.php b/lib/Contracts/IMailSearch.php index e3bc996c6..85213dc30 100644 --- a/lib/Contracts/IMailSearch.php +++ b/lib/Contracts/IMailSearch.php @@ -27,12 +27,25 @@ use OCA\Mail\Account; use OCA\Mail\Db\Message; use OCA\Mail\Exception\ClientException; use OCA\Mail\Exception\ServiceException; +use OCP\AppFramework\Db\DoesNotExistException; interface IMailSearch { /** * @param Account $account * @param string $mailboxName + * @param int $uid + * + * @return Message + * @throws DoesNotExistException + * @throws ClientException + * @throws ServiceException + */ + public function findMessage(Account $account, string $mailboxName, int $uid): Message; + + /** + * @param Account $account + * @param string $mailboxName * @param string|null $filter * @param string|null $cursor * diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index 9a6fc82de..8726c5be7 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -54,6 +54,7 @@ use OCP\IL10N; use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; +use function array_map; use function base64_decode; class MessagesController extends Controller { @@ -176,23 +177,52 @@ class MessagesController extends Controller { return new JSONResponse(null, Http::STATUS_FORBIDDEN); } + $this->logger->debug("loading message of folder <$folderId>"); + + return new JSONResponse( + $this->mailSearch->findMessage( + $account, + base64_decode($folderId), + $id + ) + ); + } + + /** + * @NoAdminRequired + * @TrapError + * + * @param int $accountId + * @param string $folderId + * @param int $messageId + * + * @return JSONResponse + * @throws ServiceException + */ + public function getBody(int $accountId, string $folderId, int $messageId): JSONResponse { + try { + $account = $this->accountService->find($this->currentUserId, $accountId); + } catch (DoesNotExistException $e) { + return new JSONResponse(null, Http::STATUS_FORBIDDEN); + } + $json = $this->mailManager->getMessage( $account, base64_decode($folderId), - $id, + $messageId, true )->getFullMessage( $accountId, base64_decode($folderId), - $id + $messageId ); $json['itineraries'] = $this->itineraryService->extract( $account, base64_decode($folderId), - $id + $messageId ); - $json['attachments'] = array_map(function ($a) use ($accountId, $folderId, $id) { - return $this->enrichDownloadUrl($accountId, $folderId, $id, $a); + $json['attachments'] = array_map(function ($a) use ($accountId, $folderId, $messageId) { + return $this->enrichDownloadUrl($accountId, $folderId, $messageId, $a); }, $json['attachments']); return new JSONResponse($json); diff --git a/lib/Service/Search/MailSearch.php b/lib/Service/Search/MailSearch.php index 773f7152c..555188826 100644 --- a/lib/Service/Search/MailSearch.php +++ b/lib/Service/Search/MailSearch.php @@ -73,6 +73,27 @@ class MailSearch implements IMailSearch { $this->logger = $logger; } + public function findMessage(Account $account, string $mailboxName, int $uid): Message { + try { + $mailbox = $this->mailboxMapper->find($account, $mailboxName); + } catch (DoesNotExistException $e) { + throw new ServiceException('Mailbox does not exist', 0, $e); + } + + $messages = $this->previewEnhancer->process( + $account, + $mailbox, + $this->messageMapper->findByUids( + $mailbox, + [$uid] + ) + ); + if (empty($messages)) { + throw new DoesNotExistException("Message does not exist"); + } + return $messages[0]; + } + /** * @param Account $account * @param string $mailboxName |