diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2021-01-08 13:29:33 +0300 |
---|---|---|
committer | GretaD <gretadoci@gmail.com> | 2021-01-14 15:11:42 +0300 |
commit | dce93038e51b72600d584e18132291dd8c785ab2 (patch) | |
tree | 925873a62622672374c60ad5768fef7f3c22c2d5 /lib/Controller/MessagesController.php | |
parent | 5d0409edbd154acba559ca24697d90eb6555da7f (diff) |
Sent and request mdn (read confirmation)
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'lib/Controller/MessagesController.php')
-rwxr-xr-x | lib/Controller/MessagesController.php | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index b95c3c2c3..ad49a8275 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -34,6 +34,7 @@ use Exception; use OC\Security\CSP\ContentSecurityPolicyNonceManager; use OCA\Mail\Contracts\IMailManager; use OCA\Mail\Contracts\IMailSearch; +use OCA\Mail\Contracts\IMailTransmission; use OCA\Mail\Contracts\ITrustedSenderService; use OCA\Mail\Db\Message; use OCA\Mail\Exception\ClientException; @@ -96,6 +97,9 @@ class MessagesController extends Controller { /** @var ITrustedSenderService */ private $trustedSenderService; + /** @var IMailTransmission */ + private $mailTransmission; + /** * @param string $appName * @param IRequest $request @@ -111,6 +115,7 @@ class MessagesController extends Controller { * @param IURLGenerator $urlGenerator * @param ContentSecurityPolicyNonceManager $nonceManager * @param ITrustedSenderService $trustedSenderService + * @param IMailTransmission $mailTransmission */ public function __construct(string $appName, IRequest $request, @@ -125,7 +130,8 @@ class MessagesController extends Controller { IMimeTypeDetector $mimeTypeDetector, IURLGenerator $urlGenerator, ContentSecurityPolicyNonceManager $nonceManager, - ITrustedSenderService $trustedSenderService) { + ITrustedSenderService $trustedSenderService, + IMailTransmission $mailTransmission) { parent::__construct($appName, $request); $this->accountService = $accountService; @@ -141,6 +147,7 @@ class MessagesController extends Controller { $this->mailManager = $mailManager; $this->nonceManager = $nonceManager; $this->trustedSenderService = $trustedSenderService; + $this->mailTransmission = $mailTransmission; } /** @@ -338,6 +345,41 @@ class MessagesController extends Controller { /** * @NoAdminRequired + * @TrapError + * + * @param int $id + * + * @return JSONResponse + * + * @throws ClientException + * @throws ServiceException + */ + public function mdn(int $id): JSONResponse { + 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); + } + + if ($message->getFlagMdnsent()) { + return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED); + } + + try { + $this->mailTransmission->sendMdn($account, $mailbox, $message); + $this->mailManager->flagMessage($account, $mailbox->getName(), $message->getUid(), 'mdnsent', true); + } catch (ServiceException $ex) { + $this->logger->error('Sending mdn failed: ' . $ex->getMessage()); + throw $ex; + } + + return new JSONResponse(); + } + + /** + * @NoAdminRequired * @NoCSRFRequired * @TrapError * |