Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-08-11 22:10:49 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-08-24 21:21:40 +0300
commit9498ebac6eccde201526b9a6131a76c02ca5db62 (patch)
tree7256f1fc6de4dee185f5cc116e45247cf27f28cb /lib/Controller
parent430500712496242526eed2aedb5afc42d60ca1b9 (diff)
Rework the routing
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/AccountsController.php126
-rw-r--r--lib/Controller/AliasesController.php8
-rw-r--r--lib/Controller/MailboxesController.php (renamed from lib/Controller/FoldersController.php)97
-rwxr-xr-xlib/Controller/MessagesController.php243
-rw-r--r--lib/Controller/PageController.php56
5 files changed, 325 insertions, 205 deletions
diff --git a/lib/Controller/AccountsController.php b/lib/Controller/AccountsController.php
index e5c8a94bb..94221eb09 100644
--- a/lib/Controller/AccountsController.php
+++ b/lib/Controller/AccountsController.php
@@ -30,8 +30,10 @@ declare(strict_types=1);
namespace OCA\Mail\Controller;
use Exception;
+use Horde_Imap_Client;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Contracts\IMailTransmission;
+use OCA\Mail\Db\Mailbox;
use OCA\Mail\Exception\ClientException;
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\Http\JsonResponse as MailJsonResponse;
@@ -41,6 +43,7 @@ use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\AliasesService;
use OCA\Mail\Service\GroupsIntegration;
use OCA\Mail\Service\SetupService;
+use OCA\Mail\Service\Sync\SyncService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
@@ -77,17 +80,37 @@ class AccountsController extends Controller {
/** @var IMailManager */
private $mailManager;
+ /** @var SyncService */
+ private $syncService;
+
+ /**
+ * AccountsController constructor.
+ *
+ * @param string $appName
+ * @param IRequest $request
+ * @param AccountService $accountService
+ * @param GroupsIntegration $groupsIntegration
+ * @param $UserId
+ * @param ILogger $logger
+ * @param IL10N $l10n
+ * @param AliasesService $aliasesService
+ * @param IMailTransmission $mailTransmission
+ * @param SetupService $setup
+ * @param IMailManager $mailManager
+ * @param SyncService $syncService
+ */
public function __construct(string $appName,
- IRequest $request,
- AccountService $accountService,
- GroupsIntegration $groupsIntegration,
- $UserId,
- ILogger $logger,
- IL10N $l10n,
- AliasesService $aliasesService,
- IMailTransmission $mailTransmission,
- SetupService $setup,
- IMailManager $mailManager
+ IRequest $request,
+ AccountService $accountService,
+ GroupsIntegration $groupsIntegration,
+ $UserId,
+ ILogger $logger,
+ IL10N $l10n,
+ AliasesService $aliasesService,
+ IMailTransmission $mailTransmission,
+ SetupService $setup,
+ IMailManager $mailManager,
+ SyncService $syncService
) {
parent::__construct($appName, $request);
$this->accountService = $accountService;
@@ -99,6 +122,7 @@ class AccountsController extends Controller {
$this->mailTransmission = $mailTransmission;
$this->setup = $setup;
$this->mailManager = $mailManager;
+ $this->syncService = $syncService;
}
/**
@@ -123,13 +147,13 @@ class AccountsController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
+ * @param int $id
*
* @return JSONResponse
* @throws ClientException
*/
- public function show($accountId): JSONResponse {
- return new JSONResponse($this->accountService->find($this->currentUserId, $accountId));
+ public function show(int $id): JSONResponse {
+ return new JSONResponse($this->accountService->find($this->currentUserId, $id));
}
/**
@@ -198,7 +222,7 @@ class AccountsController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
+ * @param int $id
* @param string|null $editorMode
* @param int|null $order
* @param bool|null $showSubscribedOnly
@@ -207,11 +231,11 @@ class AccountsController extends Controller {
*
* @throws ClientException
*/
- public function patchAccount(int $accountId,
+ public function patchAccount(int $id,
string $editorMode = null,
int $order = null,
bool $showSubscribedOnly = null): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ $account = $this->accountService->find($this->currentUserId, $id);
if ($account === null) {
return new JSONResponse(null, Http::STATUS_FORBIDDEN);
@@ -236,7 +260,7 @@ class AccountsController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
+ * @param int $id
* @param string|null $signature
*
* @return JSONResponse
@@ -244,8 +268,8 @@ class AccountsController extends Controller {
* @throws ClientException
* @throws ServiceException
*/
- public function updateSignature(int $accountId, string $signature = null): JSONResponse {
- $this->accountService->updateSignature($accountId, $this->currentUserId, $signature);
+ public function updateSignature(int $id, string $signature = null): JSONResponse {
+ $this->accountService->updateSignature($id, $this->currentUserId, $signature);
return new JSONResponse();
}
@@ -259,7 +283,7 @@ class AccountsController extends Controller {
*
* @throws ClientException
*/
- public function destroy($id): JSONResponse {
+ public function destroy(int $id): JSONResponse {
$this->accountService->delete($this->currentUserId, $id);
return new JSONResponse();
}
@@ -315,13 +339,13 @@ class AccountsController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
+ * @param int $id
* @param string $subject
* @param string $body
* @param string $to
* @param string $cc
* @param string $bcc
- * @param int|null $draftUID
+ * @param int|null $draftId
* @param string|null $folderId
* @param int|null $messageId
* @param mixed $attachments
@@ -332,19 +356,19 @@ class AccountsController extends Controller {
* @throws ClientException
* @throws ServiceException
*/
- public function send(int $accountId,
+ public function send(int $id,
string $subject,
string $body,
string $to,
string $cc,
string $bcc,
bool $isHtml = true,
- int $draftUID = null,
+ int $draftId = null,
string $folderId = null,
int $messageId = null,
array $attachments = [],
int $aliasId = null): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ $account = $this->accountService->find($this->currentUserId, $id);
$alias = $aliasId ? $this->aliasesService->find($aliasId, $this->currentUserId) : null;
$expandedTo = $this->groupsIntegration->expand($to);
@@ -357,8 +381,16 @@ class AccountsController extends Controller {
$repliedMessageData = new RepliedMessageData($account, base64_decode($folderId), $messageId);
}
+ $draft = null;
+ if ($draftId !== null) {
+ try {
+ $draft = $this->mailManager->getMessage($this->currentUserId, $draftId);
+ } catch (ClientException $e) {
+ $this->logger->info("Draft " . $draftId . " could not be loaded: " . $e->getMessage());
+ }
+ }
try {
- $this->mailTransmission->sendMessage($messageData, $repliedMessageData, $alias, $draftUID);
+ $this->mailTransmission->sendMessage($messageData, $repliedMessageData, $alias, $draft);
return new JSONResponse();
} catch (ServiceException $ex) {
$this->logger->error('Sending mail failed: ' . $ex->getMessage());
@@ -370,7 +402,7 @@ class AccountsController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
+ * @param int $id
* @param string $subject
* @param string $body
* @param string $to
@@ -382,27 +414,43 @@ class AccountsController extends Controller {
*
* @throws ClientException
*/
- public function draft(int $accountId,
- string $subject = null,
+ public function draft(int $id,
+ string $subject,
string $body,
string $to,
string $cc,
string $bcc,
bool $isHtml = true,
- int $draftUID = null): JSONResponse {
- if ($draftUID === null) {
- $this->logger->info("Saving a new draft in account <$accountId>");
+ int $draftId = null): JSONResponse {
+ if ($draftId === null) {
+ $this->logger->info("Saving a new draft in account <$id>");
} else {
- $this->logger->info("Updating draft <$draftUID> in account <$accountId>");
+ $this->logger->info("Updating draft <$draftId> in account <$id>");
}
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ $account = $this->accountService->find($this->currentUserId, $id);
+ $previousDraft = null;
+ if ($draftId !== null) {
+ try {
+ $previousDraft = $this->mailManager->getMessage($this->currentUserId, $draftId);
+ } catch (ClientException $e) {
+ $this->logger->info("Draft " . $draftId . " could not be loaded: " . $e->getMessage());
+ }
+ }
$messageData = NewMessageData::fromRequest($account, $to, $cc, $bcc, $subject, $body, [], $isHtml);
try {
- $newUID = $this->mailTransmission->saveDraft($messageData, $draftUID);
+ /** @var Mailbox $draftsMailbox */
+ [, $draftsMailbox, $newUID] = $this->mailTransmission->saveDraft($messageData, $previousDraft);
+ $this->syncService->syncMailbox(
+ $account,
+ $draftsMailbox,
+ Horde_Imap_Client::SYNC_NEWMSGS,
+ [],
+ false
+ );
return new JSONResponse([
- 'uid' => $newUID,
+ 'id' => $this->mailManager->getMessageIdForUid($draftsMailbox, $newUID)
]);
} catch (ServiceException $ex) {
$this->logger->error('Saving draft failed: ' . $ex->getMessage());
@@ -413,13 +461,13 @@ class AccountsController extends Controller {
/**
* @NoAdminRequired
*
- * @param int $accountId
+ * @param int $id
*
* @return JSONResponse
* @throws ClientException
*/
- public function getQuota(int $accountId): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ public function getQuota(int $id): JSONResponse {
+ $account = $this->accountService->find($this->currentUserId, $id);
$quota = $this->mailManager->getQuota($account);
if ($quota === null) {
diff --git a/lib/Controller/AliasesController.php b/lib/Controller/AliasesController.php
index cda86bd65..ca9d61589 100644
--- a/lib/Controller/AliasesController.php
+++ b/lib/Controller/AliasesController.php
@@ -54,9 +54,10 @@ class AliasesController extends Controller {
* @TrapError
*
* @param int $accountId
+ *
* @return JSONResponse
*/
- public function index($accountId): JSONResponse {
+ public function index(int $accountId): JSONResponse {
return new JSONResponse($this->aliasService->findAll($accountId, $this->currentUser->getUID()));
}
@@ -83,7 +84,7 @@ class AliasesController extends Controller {
* @param int $id
* @return JSONResponse
*/
- public function destroy($id): JSONResponse {
+ public function destroy(int $id): JSONResponse {
return new JSONResponse($this->aliasService->delete($id, $this->currentUser->getUID()));
}
@@ -94,9 +95,10 @@ class AliasesController extends Controller {
* @param int $accountId
* @param string $alias
* @param string $aliasName
+ *
* @return JSONResponse
*/
- public function create($accountId, $alias, $aliasName): JSONResponse {
+ public function create(int $accountId, string $alias, string $aliasName): JSONResponse {
return new JSONResponse($this->aliasService->create($accountId, $alias, $aliasName), Http::STATUS_CREATED);
}
}
diff --git a/lib/Controller/FoldersController.php b/lib/Controller/MailboxesController.php
index 2527658e5..c7ad55007 100644
--- a/lib/Controller/FoldersController.php
+++ b/lib/Controller/MailboxesController.php
@@ -31,8 +31,6 @@ use OCA\Mail\Exception\IncompleteSyncException;
use OCA\Mail\Exception\MailboxNotCachedException;
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\Service\Sync\SyncService;
-use function base64_decode;
-use function is_array;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Exception\NotImplemented;
use OCA\Mail\Service\AccountService;
@@ -41,7 +39,7 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
-class FoldersController extends Controller {
+class MailboxesController extends Controller {
/** @var AccountService */
private $accountService;
@@ -66,7 +64,7 @@ class FoldersController extends Controller {
public function __construct(string $appName,
IRequest $request,
AccountService $accountService,
- $UserId,
+ ?string $UserId,
IMailManager $mailManager,
SyncService $syncService) {
parent::__construct($appName, $request);
@@ -94,7 +92,7 @@ class FoldersController extends Controller {
return new JSONResponse([
'id' => $accountId,
'email' => $account->getEmail(),
- 'folders' => $mailboxes,
+ 'mailboxes' => $mailboxes,
'delimiter' => reset($mailboxes)->getDelimiter(),
]);
}
@@ -103,30 +101,28 @@ class FoldersController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
- * @param string $syncToken
- * @param int[] $uids
+ * @param int $id
+ * @param int[] $ids
+ *
+ * @param bool $init
+ * @param string|null $query
*
* @return JSONResponse
* @throws ClientException
* @throws ServiceException
*/
- public function sync(int $accountId, string $folderId, array $uids = [], bool $init = false, string $query = null): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
-
- if (empty($accountId) || empty($folderId) || !is_array($uids)) {
- return new JSONResponse(null, Http::STATUS_BAD_REQUEST);
- }
+ public function sync(int $id, array $ids = [], bool $init = false, string $query = null): JSONResponse {
+ $mailbox = $this->mailManager->getMailbox($this->currentUserId, $id);
+ $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
try {
$syncResponse = $this->syncService->syncMailbox(
$account,
- base64_decode($folderId),
+ $mailbox,
Horde_Imap_Client::SYNC_NEWMSGSUIDS | Horde_Imap_Client::SYNC_FLAGSUIDS | Horde_Imap_Client::SYNC_VANISHEDUIDS,
- array_map(function ($uid) {
- return (int) $uid;
- }, $uids),
+ array_map(function ($id) {
+ return (int) $id;
+ }, $ids),
!$init,
$query
);
@@ -143,21 +139,17 @@ class FoldersController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
+ * @param string $id
*
* @return JSONResponse
* @throws ClientException
* @throws ServiceException
*/
- public function clearCache(int $accountId, string $folderId): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ public function clearCache(int $id): JSONResponse {
+ $mailbox = $this->mailManager->getMailbox($this->currentUserId, $id);
+ $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
- if (empty($accountId) || empty($folderId)) {
- return new JSONResponse(null, Http::STATUS_BAD_REQUEST);
- }
-
- $this->syncService->clearCache($account, base64_decode($folderId));
+ $this->syncService->clearCache($account, $mailbox);
return new JSONResponse(null);
}
@@ -165,43 +157,37 @@ class FoldersController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
+ * @param int $id
+ *
* @return JSONResponse
*
* @throws ClientException
*/
- public function markAllAsRead(int $accountId, string $folderId): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
-
- if (empty($accountId) || empty($folderId)) {
- return new JSONResponse(null, Http::STATUS_BAD_REQUEST);
- }
+ public function markAllAsRead(int $id): JSONResponse {
+ $mailbox = $this->mailManager->getMailbox($this->currentUserId, $id);
+ $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
- $syncResponse = $this->mailManager->markFolderAsRead($account, base64_decode($folderId));
+ $this->mailManager->markFolderAsRead($account, $mailbox);
- return new JSONResponse($syncResponse);
+ return new JSONResponse(null);
}
/**
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
+ * @param int $id
*
* @return JSONResponse
*
* @throws ClientException
+ * @throws ServiceException
*/
- public function stats(int $accountId, string $folderId): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
-
- if (empty($accountId) || empty($folderId)) {
- return new JSONResponse(null, Http::STATUS_BAD_REQUEST);
- }
+ public function stats(int $id): JSONResponse {
+ $mailbox = $this->mailManager->getMailbox($this->currentUserId, $id);
+ $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
- $stats = $this->mailManager->getFolderStats($account, base64_decode($folderId));
+ $stats = $this->mailManager->getMailboxStats($account, $mailbox);
return new JSONResponse($stats);
}
@@ -232,19 +218,24 @@ class FoldersController extends Controller {
public function create(int $accountId, string $name) {
$account = $this->accountService->find($this->currentUserId, $accountId);
- return new JSONResponse($this->mailManager->createFolder($account, $name));
+ return new JSONResponse($this->mailManager->createMailbox($account, $name));
}
/**
* @NoAdminRequired
* @TrapError
- * @param int $accountId
- * @param string $folderId
+ *
+ * @param int $id
+ *
+ * @return JSONResponse
+ * @throws ClientException
* @throws ServiceException
*/
- public function delete(int $accountId, string $folderId): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
- $this->mailManager->deleteMailbox($account, base64_decode($folderId));
+ public function destroy(int $id): JSONResponse {
+ $mailbox = $this->mailManager->getMailbox($this->currentUserId, $id);
+ $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
+
+ $this->mailManager->deleteMailbox($account, $mailbox);
return new JSONResponse();
}
}
diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php
index ef6357835..df602bf94 100755
--- a/lib/Controller/MessagesController.php
+++ b/lib/Controller/MessagesController.php
@@ -39,7 +39,6 @@ use OCA\Mail\Http\AttachmentDownloadResponse;
use OCA\Mail\Http\HtmlResponse;
use OCA\Mail\Model\IMAPMessage;
use OCA\Mail\Service\AccountService;
-use OCA\Mail\Service\IMailBox;
use OCA\Mail\Service\ItineraryService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
@@ -55,7 +54,6 @@ use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use function array_map;
-use function base64_decode;
class MessagesController extends Controller {
@@ -131,29 +129,33 @@ class MessagesController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
+ * @param int $mailboxId
* @param int $cursor
* @param string $filter
+ * @param int|null $limit
*
* @return JSONResponse
*
* @throws ClientException
* @throws ServiceException
*/
- public function index(int $accountId, string $folderId, int $cursor = null, string $filter = null, int $limit = null): JSONResponse {
+ public function index(int $mailboxId,
+ int $cursor = null,
+ string $filter = null,
+ int $limit = null): JSONResponse {
try {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ $mailbox = $this->mailManager->getMailbox($this->currentUserId, $mailboxId);
+ $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
} catch (DoesNotExistException $e) {
return new JSONResponse(null, Http::STATUS_FORBIDDEN);
}
- $this->logger->debug("loading messages of folder <$folderId>");
+ $this->logger->debug("loading messages of folder <$mailboxId>");
return new JSONResponse(
$this->mailSearch->findMessages(
$account,
- base64_decode($folderId),
+ $mailbox,
$filter === '' ? null : $filter,
$cursor,
$limit
@@ -174,20 +176,22 @@ class MessagesController extends Controller {
* @throws ClientException
* @throws ServiceException
*/
- public function show(int $accountId, string $folderId, int $id): JSONResponse {
+ public function show(int $id): JSONResponse {
try {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ $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(null, Http::STATUS_FORBIDDEN);
}
- $this->logger->debug("loading message of folder <$folderId>");
+ $this->logger->debug("loading message <$id>");
return new JSONResponse(
$this->mailSearch->findMessage(
$account,
- base64_decode($folderId),
- $id
+ $mailbox,
+ $message
)
);
}
@@ -196,40 +200,40 @@ class MessagesController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
- * @param int $messageId
+ * @param int $id
*
* @return JSONResponse
*
* @throws ClientException
* @throws ServiceException
*/
- public function getBody(int $accountId, string $folderId, int $messageId): JSONResponse {
+ public function getBody(int $id): JSONResponse {
try {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ $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(null, Http::STATUS_FORBIDDEN);
}
- $json = $this->mailManager->getMessage(
+ $json = $this->mailManager->getImapMessage(
$account,
- base64_decode($folderId),
- $messageId,
+ $mailbox,
+ $message->getUid(),
true
- )->getFullMessage(
- $accountId,
- base64_decode($folderId),
- $messageId
- );
+ )->getFullMessage($id);
$json['itineraries'] = $this->itineraryService->extract(
$account,
- base64_decode($folderId),
- $messageId
+ $mailbox->getName(),
+ $message->getUid()
);
- $json['attachments'] = array_map(function ($a) use ($accountId, $folderId, $messageId) {
- return $this->enrichDownloadUrl($accountId, $folderId, $messageId, $a);
+ $json['attachments'] = array_map(function ($a) use ($id) {
+ return $this->enrichDownloadUrl(
+ $id,
+ $a
+ );
}, $json['attachments']);
+ $json['databaseId'] = $message->getId();
return new JSONResponse($json);
}
@@ -239,14 +243,19 @@ class MessagesController extends Controller {
* @NoCSRFRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
+ * @param int $id
*
* @return JSONResponse
* @throws ClientException
*/
- public function getThread(int $accountId, int $id): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ public function getThread(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(null, Http::STATUS_FORBIDDEN);
+ }
return new JSONResponse($this->mailManager->getThread($account, $id));
}
@@ -255,10 +264,7 @@ class MessagesController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
* @param int $id
- * @param int $destAccountId
* @param string $destFolderId
*
* @return JSONResponse
@@ -266,12 +272,24 @@ class MessagesController extends Controller {
* @throws ClientException
* @throws ServiceException
*/
- public function move($accountId, $folderId, $id, $destAccountId, $destFolderId): JSONResponse {
- $srcAccount = $this->accountService->find($this->currentUserId, $accountId);
- $dstAccount = $this->accountService->find($this->currentUserId,
- $destAccountId);
- $this->mailManager->moveMessage($srcAccount, base64_decode($folderId), $id,
- $dstAccount, base64_decode($destFolderId));
+ public function move(int $id, int $destFolderId): JSONResponse {
+ try {
+ $message = $this->mailManager->getMessage($this->currentUserId, $id);
+ $srcMailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId());
+ $dstMailbox = $this->mailManager->getMailbox($this->currentUserId, $destFolderId);
+ $srcAccount = $this->accountService->find($this->currentUserId, $srcMailbox->getAccountId());
+ $dstAccount = $this->accountService->find($this->currentUserId, $dstMailbox->getAccountId());
+ } catch (DoesNotExistException $e) {
+ return new JSONResponse(null, Http::STATUS_FORBIDDEN);
+ }
+
+ $this->mailManager->moveMessage(
+ $srcAccount,
+ $srcMailbox->getName(),
+ $message->getUid(),
+ $dstAccount,
+ $dstMailbox->getName()
+ );
return new JSONResponse();
}
@@ -284,17 +302,23 @@ class MessagesController extends Controller {
* @param string $folderId
* @param int $messageId
*
- * @return HtmlResponse|TemplateResponse
+ * @return JSONResponse
* @throws ServiceException
*/
- public function getSource(int $accountId, string $folderId, int $messageId): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ public function getSource(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(null, Http::STATUS_FORBIDDEN);
+ }
$response = new JSONResponse([
'source' => $this->mailManager->getSource(
$account,
- base64_decode($folderId),
- $messageId
+ $mailbox->getName(),
+ $message->getUid()
)
]);
@@ -309,18 +333,18 @@ class MessagesController extends Controller {
* @NoCSRFRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
- * @param int $messageId
+ * @param int $id
*
* @return HtmlResponse|TemplateResponse
*
* @throws ClientException
*/
- public function getHtmlBody(int $accountId, string $folderId, int $messageId): Response {
+ public function getHtmlBody(int $id): Response {
try {
try {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ $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 TemplateResponse(
$this->appName,
@@ -331,12 +355,14 @@ class MessagesController extends Controller {
}
$htmlResponse = new HtmlResponse(
- $this->mailManager->getMessage(
+ $this->mailManager->getImapMessage(
$account,
- base64_decode($folderId),
- $messageId,
+ $mailbox,
+ $message->getUid(),
true
- )->getHtmlBody($accountId, base64_decode($folderId), $messageId)
+ )->getHtmlBody(
+ $id
+ )
);
// Harden the default security policy
@@ -369,19 +395,25 @@ class MessagesController extends Controller {
*
* @param int $accountId
* @param string $folderId
- * @param int $messageId
+ * @param int $id
* @param int $attachmentId
*
- * @return AttachmentDownloadResponse
+ * @return Response
*
* @throws ClientException
* @throws ServiceException
*/
- public function downloadAttachment(int $accountId, string $folderId, int $messageId,
- string $attachmentId) {
- $mailBox = $this->getFolder($accountId, $folderId);
-
- $attachment = $mailBox->getAttachment($messageId, $attachmentId);
+ public function downloadAttachment(int $id,
+ string $attachmentId): 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(null, Http::STATUS_FORBIDDEN);
+ }
+ $folder = $account->getMailbox($mailbox->getName());
+ $attachment = $folder->getAttachment($message->getUid(), $attachmentId);
// Body party and embedded messages do not have a name
if ($attachment->getName() === null) {
@@ -404,9 +436,7 @@ class MessagesController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
- * @param int $messageId
+ * @param int $id
* @param int $attachmentId
* @param string $targetPath
*
@@ -415,14 +445,22 @@ class MessagesController extends Controller {
* @throws ClientException
* @throws ServiceException
*/
- public function saveAttachment(int $accountId, string $folderId, int $messageId,
- string $attachmentId, string $targetPath) {
- $mailBox = $this->getFolder($accountId, $folderId);
+ public function saveAttachment(int $id,
+ string $attachmentId,
+ string $targetPath) {
+ 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(null, Http::STATUS_FORBIDDEN);
+ }
+ $folder = $account->getMailbox($mailbox->getName());
if ($attachmentId === '0') {
// Save all attachments
/* @var $m IMAPMessage */
- $m = $mailBox->getMessage($messageId);
+ $m = $folder->getMessage($id);
$attachmentIds = array_map(function ($a) {
return $a['id'];
}, $m->attachments);
@@ -430,11 +468,11 @@ class MessagesController extends Controller {
$attachmentIds = [$attachmentId];
}
- foreach ($attachmentIds as $attachmentId) {
- $attachment = $mailBox->getAttachment($messageId, $attachmentId);
+ foreach ($attachmentIds as $aid) {
+ $attachment = $folder->getAttachment($message->getUid(), $attachmentId);
$fileName = $attachment->getName() ?? $this->l10n->t('Embedded message %s', [
- $attachmentId,
+ $aid,
]) . '.eml';
$fileParts = pathinfo($fileName);
$fileName = $fileParts['filename'];
@@ -456,9 +494,7 @@ class MessagesController extends Controller {
* @NoAdminRequired
* @TrapError
*
- * @param int $accountId
- * @param string $folderId
- * @param string $messageId
+ * @param string $id
* @param array $flags
*
* @return JSONResponse
@@ -466,12 +502,18 @@ class MessagesController extends Controller {
* @throws ClientException
* @throws ServiceException
*/
- public function setFlags(int $accountId, string $folderId, int $messageId, array $flags): JSONResponse {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ public function setFlags(int $id, array $flags): 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(null, Http::STATUS_FORBIDDEN);
+ }
foreach ($flags as $flag => $value) {
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
- $this->mailManager->flagMessage($account, base64_decode($folderId), $messageId, $flag, $value);
+ $this->mailManager->flagMessage($account, $mailbox->getName(), $message->getUid(), $flag, $value);
}
return new JSONResponse();
}
@@ -489,49 +531,36 @@ class MessagesController extends Controller {
* @throws ClientException
* @throws ServiceException
*/
- public function destroy(int $accountId, string $folderId, int $id): JSONResponse {
- $this->logger->debug("deleting message <$id> of folder <$folderId>, account <$accountId>");
-
+ public function destroy(int $id): JSONResponse {
try {
- $account = $this->accountService->find($this->currentUserId, $accountId);
+ $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(null, Http::STATUS_FORBIDDEN);
}
- $this->mailManager->deleteMessage($account, base64_decode($folderId), $id);
- return new JSONResponse();
- }
+ $this->logger->debug("deleting message <$id>");
- /**
- * @param int $accountId
- * @param string $folderId
- *
- * @return IMailBox
- * @deprecated
- *
- * @throws ClientException
- * @throws ServiceException
- */
- private function getFolder(int $accountId, string $folderId): IMailBox {
- $account = $this->accountService->find($this->currentUserId, $accountId);
- return $account->getMailbox(base64_decode($folderId));
+ $this->mailManager->deleteMessage(
+ $account,
+ $mailbox->getName(),
+ $message->getUid()
+ );
+ return new JSONResponse();
}
/**
- * @param int $accountId
- * @param string $folderId
- * @param int $messageId
+ * @param int $id
* @param array $attachment
*
* @return array
*/
- private function enrichDownloadUrl(int $accountId, string $folderId, int $messageId,
+ private function enrichDownloadUrl(int $id,
array $attachment) {
$downloadUrl = $this->urlGenerator->linkToRoute('mail.messages.downloadAttachment',
[
- 'accountId' => $accountId,
- 'folderId' => $folderId,
- 'messageId' => $messageId,
+ 'id' => $id,
'attachmentId' => $attachment['id'],
]);
$downloadUrl = $this->urlGenerator->getAbsoluteURL($downloadUrl);
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 219bb16ff..fe9181760 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -117,13 +117,13 @@ class PageController extends Controller {
$this->currentUserId);
try {
$mailboxes = $this->mailManager->getMailboxes($mailAccount);
- $json['folders'] = $mailboxes;
+ $json['mailboxes'] = $mailboxes;
} catch (Exception $ex) {
$this->logger->logException($ex, [
- 'message' => 'Could not load account folders: ' . $ex->getMessage(),
+ 'message' => 'Could not load account mailboxes: ' . $ex->getMessage(),
'level' => ILogger::FATAL,
]);
- $json['folders'] = [];
+ $json['mailboxes'] = [];
$json['error'] = true;
}
$accountsJson[] = $json;
@@ -160,6 +160,56 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*
+ * @return TemplateResponse
+ */
+ public function setup(): TemplateResponse {
+ return $this->index();
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * @return TemplateResponse
+ */
+ public function keyboardShortcuts(): TemplateResponse {
+ return $this->index();
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * @return TemplateResponse
+ */
+ public function accountSettings(int $id): TemplateResponse {
+ return $this->index();
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * @return TemplateResponse
+ */
+ public function mailbox(int $id): TemplateResponse {
+ return $this->index();
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * @return TemplateResponse
+ */
+ public function thread(int $mailboxId, int $id): TemplateResponse {
+ return $this->index();
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
* @param string $uri
*
* @return RedirectResponse