diff options
Diffstat (limited to 'lib/Controller/MessagesController.php')
-rwxr-xr-x | lib/Controller/MessagesController.php | 33 |
1 files changed, 33 insertions, 0 deletions
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 @@ -438,6 +438,39 @@ class MessagesController extends Controller { } /** + * 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 * @TrapError |