From 23399752fb7db380cf9462e965d1d0ce14d956e8 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Tue, 2 Aug 2022 15:35:15 +0200 Subject: Add envelope action links to download whole message Signed-off-by: Richard Steinmetz --- lib/Controller/MessagesController.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lib/Controller/MessagesController.php') diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index 36945b46c..68ecfe2c7 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -437,6 +437,39 @@ class MessagesController extends Controller { return $response; } + /** + * Export a whole message as an .eml file. + * + * @NoAdminRequired + * @NoCSRFRequired + * @TrapError + * + * @param int $id + * @return Response + * @throws ClientException + * @throws ServiceException + */ + public function export(int $id): Response { + try { + $message = $this->mailManager->getMessage($this->currentUserId, $id); + $mailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId()); + $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId()); + } catch (DoesNotExistException $e) { + return new JSONResponse([], Http::STATUS_FORBIDDEN); + } + + $source = $this->mailManager->getSource( + $account, + $mailbox->getName(), + $message->getUid() + ); + return new AttachmentDownloadResponse( + $source, + $message->getSubject() . '.eml', + 'message/rfc822', + ); + } + /** * @NoAdminRequired * @NoCSRFRequired -- cgit v1.2.3