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
path: root/lib/IMAP
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2021-04-14 19:07:33 +0300
committerRichard Steinmetz <richard@steinmetz.cloud>2021-04-26 19:45:50 +0300
commitdaf3cb9d5a18d5ef67f0f7b58c536f84d2138dda (patch)
treebff0487f4b860f69f1c33e137319751d8f550aed /lib/IMAP
parentf83763c8489f2402f77c40af317103dce5b25b9e (diff)
Reintroduce unread counter in app navigation
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'lib/IMAP')
-rw-r--r--lib/IMAP/FolderMapper.php6
-rw-r--r--lib/IMAP/MailboxStats.php (renamed from lib/IMAP/FolderStats.php)17
-rw-r--r--lib/IMAP/MailboxSync.php35
-rw-r--r--lib/IMAP/Sync/Response.php18
4 files changed, 66 insertions, 10 deletions
diff --git a/lib/IMAP/FolderMapper.php b/lib/IMAP/FolderMapper.php
index f12ea3af8..e419adca0 100644
--- a/lib/IMAP/FolderMapper.php
+++ b/lib/IMAP/FolderMapper.php
@@ -139,13 +139,13 @@ class FolderMapper {
*
* @throws Horde_Imap_Client_Exception
*
- * @return FolderStats
+ * @return MailboxStats
*/
public function getFoldersStatusAsObject(Horde_Imap_Client_Socket $client,
- string $mailbox): FolderStats {
+ string $mailbox): MailboxStats {
$status = $client->status($mailbox);
- return new FolderStats(
+ return new MailboxStats(
$status['messages'],
$status['unseen']
);
diff --git a/lib/IMAP/FolderStats.php b/lib/IMAP/MailboxStats.php
index a1e39ed9b..9af3c0452 100644
--- a/lib/IMAP/FolderStats.php
+++ b/lib/IMAP/MailboxStats.php
@@ -6,6 +6,7 @@ declare(strict_types=1);
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author 2021 Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
@@ -27,7 +28,7 @@ namespace OCA\Mail\IMAP;
use JsonSerializable;
-class FolderStats implements JsonSerializable {
+class MailboxStats implements JsonSerializable {
/** @var int */
private $total;
@@ -40,6 +41,20 @@ class FolderStats implements JsonSerializable {
$this->unread = $unread;
}
+ /**
+ * @return int
+ */
+ public function getTotal(): int {
+ return $this->total;
+ }
+
+ /**
+ * @return int
+ */
+ public function getUnread(): int {
+ return $this->unread;
+ }
+
public function jsonSerialize() {
return [
'total' => $this->total,
diff --git a/lib/IMAP/MailboxSync.php b/lib/IMAP/MailboxSync.php
index 343abfa56..4e22d1bf2 100644
--- a/lib/IMAP/MailboxSync.php
+++ b/lib/IMAP/MailboxSync.php
@@ -126,6 +126,33 @@ class MailboxSync {
);
}
+ /**
+ * Sync unread and total message statistics.
+ *
+ * @param Account $account
+ * @param Mailbox $mailbox
+ *
+ * @throws ServiceException
+ */
+ public function syncStats(Account $account, Mailbox $mailbox): void {
+ $client = $this->imapClientFactory->getClient($account);
+
+ try {
+ $stats = $this->folderMapper->getFoldersStatusAsObject($client, $mailbox->getName());
+ } catch (Horde_Imap_Client_Exception $e) {
+ $id = $mailbox->getId();
+ throw new ServiceException(
+ "Could not fetch stats of mailbox $id. IMAP error: " . $e->getMessage(),
+ (int)$e->getCode(),
+ $e
+ );
+ }
+
+ $mailbox->setMessages($stats->getTotal());
+ $mailbox->setUnseen($stats->getUnread());
+ $this->mailboxMapper->update($mailbox);
+ }
+
private function persist(Account $account, array $folders, array $existing): void {
foreach ($folders as $folder) {
if (isset($existing[$folder->getMailbox()])) {
@@ -164,8 +191,8 @@ class MailboxSync {
$mailbox->setDelimiter($folder->getDelimiter());
$mailbox->setAttributes(json_encode($folder->getAttributes()));
$mailbox->setDelimiter($folder->getDelimiter());
- $mailbox->setMessages(0); // TODO
- $mailbox->setUnseen(0); // TODO
+ $mailbox->setMessages($folder->getStatus()['messages']);
+ $mailbox->setUnseen($folder->getStatus()['unseen']);
$mailbox->setSelectable(!in_array('\noselect', $folder->getAttributes()));
$mailbox->setSpecialUse(json_encode($folder->getSpecialUse()));
$this->mailboxMapper->update($mailbox);
@@ -177,8 +204,8 @@ class MailboxSync {
$mailbox->setAccountId($account->getId());
$mailbox->setAttributes(json_encode($folder->getAttributes()));
$mailbox->setDelimiter($folder->getDelimiter());
- $mailbox->setMessages(0); // TODO
- $mailbox->setUnseen(0); // TODO
+ $mailbox->setMessages($folder->getStatus()['messages']);
+ $mailbox->setUnseen($folder->getStatus()['unseen']);
$mailbox->setSelectable(!in_array('\noselect', $folder->getAttributes()));
$mailbox->setSpecialUse(json_encode($folder->getSpecialUse()));
$this->mailboxMapper->insert($mailbox);
diff --git a/lib/IMAP/Sync/Response.php b/lib/IMAP/Sync/Response.php
index 38b94a049..820ef7baf 100644
--- a/lib/IMAP/Sync/Response.php
+++ b/lib/IMAP/Sync/Response.php
@@ -25,6 +25,7 @@ namespace OCA\Mail\IMAP\Sync;
use JsonSerializable;
use OCA\Mail\Db\Message;
+use OCA\Mail\IMAP\MailboxStats;
use OCA\Mail\Model\IMAPMessage;
class Response implements JsonSerializable {
@@ -38,18 +39,23 @@ class Response implements JsonSerializable {
/** @var int[] */
private $vanishedMessageUids;
+ /** @var MailboxStats */
+ private $stats;
+
/**
- * @param string $syncToken
* @param IMAPMessage[]|Message[] $newMessages
* @param IMAPMessage[]|Message[] $changedMessages
* @param int[] $vanishedMessageUids
+ * @param MailboxStats|null $stats
*/
public function __construct(array $newMessages = [],
array $changedMessages = [],
- array $vanishedMessageUids = []) {
+ array $vanishedMessageUids = [],
+ MailboxStats $stats = null) {
$this->newMessages = $newMessages;
$this->changedMessages = $changedMessages;
$this->vanishedMessageUids = $vanishedMessageUids;
+ $this->stats = $stats;
}
/**
@@ -73,11 +79,19 @@ class Response implements JsonSerializable {
return $this->vanishedMessageUids;
}
+ /**
+ * @return MailboxStats
+ */
+ public function getStats(): MailboxStats {
+ return $this->stats;
+ }
+
public function jsonSerialize(): array {
return [
'newMessages' => $this->newMessages,
'changedMessages' => $this->changedMessages,
'vanishedMessages' => $this->vanishedMessageUids,
+ 'stats' => $this->stats,
];
}