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>2019-10-02 12:47:00 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-01-31 18:43:51 +0300
commitc287787f8df599b567f399f6022ffc88db3a0582 (patch)
tree6d1863eff65f5c43db73c1e36df6938c505ef58e /lib/Controller
parent31f89d71f860c8c2f75234537a8d64f38da696ab (diff)
Add a cache for IMAP message in the database
Co-authored-by: Roeland Jago Douma <roeland@famdouma.nl> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at> Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/FoldersController.php35
-rwxr-xr-xlib/Controller/MessagesController.php11
2 files changed, 41 insertions, 5 deletions
diff --git a/lib/Controller/FoldersController.php b/lib/Controller/FoldersController.php
index 5316bfb1c..ca1b10f93 100644
--- a/lib/Controller/FoldersController.php
+++ b/lib/Controller/FoldersController.php
@@ -25,6 +25,10 @@ declare(strict_types=1);
namespace OCA\Mail\Controller;
+use Horde_Imap_Client;
+use OCA\Mail\Exception\MailboxNotCachedException;
+use OCA\Mail\Exception\ServiceException;
+use OCA\Mail\Service\SyncService;
use function base64_decode;
use function is_array;
use OCA\Mail\Contracts\IMailManager;
@@ -47,6 +51,9 @@ class FoldersController extends Controller {
/** @var IMailManager */
private $mailManager;
+ /** @var SyncService */
+ private $syncService;
+
/**
* @param string $appName
* @param IRequest $request
@@ -54,13 +61,18 @@ class FoldersController extends Controller {
* @param string $UserId
* @param IMailManager $mailManager
*/
- public function __construct(string $appName, IRequest $request,
- AccountService $accountService, $UserId, IMailManager $mailManager) {
+ public function __construct(string $appName,
+ IRequest $request,
+ AccountService $accountService,
+ $UserId,
+ IMailManager $mailManager,
+ SyncService $syncService) {
parent::__construct($appName, $request);
$this->accountService = $accountService;
$this->currentUserId = $UserId;
$this->mailManager = $mailManager;
+ $this->syncService = $syncService;
}
/**
@@ -91,15 +103,28 @@ class FoldersController extends Controller {
* @param string $syncToken
* @param int[] $uids
* @return JSONResponse
+ * @throws ServiceException
*/
- public function sync(int $accountId, string $folderId, string $syncToken, array $uids = []): JSONResponse {
+ public function sync(int $accountId, string $folderId, array $uids): JSONResponse {
$account = $this->accountService->find($this->currentUserId, $accountId);
- if (empty($accountId) || empty($folderId) || empty($syncToken) || !is_array($uids)) {
+ if (empty($accountId) || empty($folderId) || !is_array($uids)) {
return new JSONResponse(null, Http::STATUS_BAD_REQUEST);
}
- $syncResponse = $this->mailManager->syncMessages($account, new SyncRequest(base64_decode($folderId), $syncToken, $uids));
+ try {
+ $syncResponse = $this->syncService->syncMailbox(
+ $account,
+ base64_decode($folderId),
+ Horde_Imap_Client::SYNC_NEWMSGSUIDS | Horde_Imap_Client::SYNC_FLAGSUIDS | Horde_Imap_Client::SYNC_VANISHEDUIDS,
+ array_map(function($uid) {
+ return (int) $uid;
+ }, $uids),
+ true
+ );
+ } catch (MailboxNotCachedException $e) {
+ return new JSONResponse(null, Http::STATUS_PRECONDITION_REQUIRED);
+ }
return new JSONResponse($syncResponse);
}
diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php
index 2764bbb3c..7e075621e 100755
--- a/lib/Controller/MessagesController.php
+++ b/lib/Controller/MessagesController.php
@@ -40,6 +40,7 @@ use OCA\Mail\Model\IMAPMessage;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\IMailBox;
use OCA\Mail\Service\ItineraryService;
+use OCA\Mail\Service\SyncService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
@@ -69,6 +70,9 @@ class MessagesController extends Controller {
/** @var ItineraryService */
private $itineraryService;
+ /** @var SyncService */
+ private $syncService;
+
/** @var string */
private $currentUserId;
@@ -104,6 +108,7 @@ class MessagesController extends Controller {
IMailManager $mailManager,
IMailSearch $mailSearch,
ItineraryService $itineraryService,
+ SyncService $syncService,
string $UserId,
$userFolder,
ILogger $logger,
@@ -116,6 +121,7 @@ class MessagesController extends Controller {
$this->mailManager = $mailManager;
$this->mailSearch = $mailSearch;
$this->itineraryService = $itineraryService;
+ $this->syncService = $syncService;
$this->currentUserId = $UserId;
$this->userFolder = $userFolder;
$this->logger = $logger;
@@ -144,6 +150,11 @@ class MessagesController extends Controller {
return new JSONResponse(null, Http::STATUS_FORBIDDEN);
}
+ $this->syncService->ensurePopulated(
+ $account,
+ base64_decode($folderId)
+ );
+
$this->logger->debug("loading messages of folder <$folderId>");
return new JSONResponse(