EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
fix imap unseen
Yurii076483e4f2c7
diff --git a/application/Espo/Core/Mail/Account/Fetcher.php b/application/Espo/Core/Mail/Account/Fetcher.phpindex 29f5a0caae..e770b9ff83 100644--- a/application/Espo/Core/Mail/Account/Fetcher.php+++ b/application/Espo/Core/Mail/Account/Fetcher.php@@ -275,7 +275,12 @@ class Fetcher->withGroupEmailFolderId($groupEmailFolderId);try {- $message = new MessageWrapper($id, $storage, $parser);+ $message = new MessageWrapper(+ id: $id,+ storage: $storage,+ parser: $parser,+ peek: $account->keepFetchedEmailsUnread(),+ );$hookResult = null;diff --git a/application/Espo/Core/Mail/Account/Storage.php b/application/Espo/Core/Mail/Account/Storage.phpindex 332f2ca40d..eaba7b0d70 100644--- a/application/Espo/Core/Mail/Account/Storage.php+++ b/application/Espo/Core/Mail/Account/Storage.php@@ -37,6 +37,8 @@ interface Storage/*** Mark as unseen.*+ * @todo Move to the Message interface. Call from the MessageWrapper.+ ** @throws ImapError*/public function unmarkSeen(int $id): void;@@ -53,7 +55,7 @@ interface Storage** @throws ImapError*/- public function getRawContent(int $id): string;+ public function getRawContent(int $id, bool $peek): string;/*** Get IDs from unique ID.diff --git a/application/Espo/Core/Mail/Account/Storage/DirectoryTreeStorage.php b/application/Espo/Core/Mail/Account/Storage/DirectoryTreeStorage.phpindex c9d74b7000..cdee32e07e 100644--- a/application/Espo/Core/Mail/Account/Storage/DirectoryTreeStorage.php+++ b/application/Espo/Core/Mail/Account/Storage/DirectoryTreeStorage.php@@ -102,7 +102,7 @@ class DirectoryTreeStorage implements Storage* @inheritDoc* @noinspection PhpRedundantCatchClauseInspection*/- public function getRawContent(int $id): string+ public function getRawContent(int $id, bool $peek): string{$folder = $this->getSelectedFolder();@@ -112,6 +112,10 @@ class DirectoryTreeStorage implements Storage->withFlags()->withBody()->find($id);++ if ($message instanceof Message && !$peek) {+ $message->markSeen();+ }} catch (CommonException $e) {throw new ImapError($e->getMessage(), previous: $e);}diff --git a/application/Espo/Core/Mail/MessageWrapper.php b/application/Espo/Core/Mail/MessageWrapper.phpindex a6a93085b1..26a1c17ae8 100644--- a/application/Espo/Core/Mail/MessageWrapper.php+++ b/application/Espo/Core/Mail/MessageWrapper.php@@ -50,7 +50,8 @@ class MessageWrapper implements Messageprivate int $id,private ?Storage $storage = null,private ?Parser $parser = null,- private ?string $fullRawContent = null+ private ?string $fullRawContent = null,+ private bool $peek = false,) {if ($storage) {$data = $storage->getHeaderAndFlags($id);@@ -112,7 +113,7 @@ class MessageWrapper implements Messagethrow new RuntimeException();}- $this->rawContent = $this->storage->getRawContent($this->id);+ $this->rawContent = $this->storage->getRawContent($this->id, $this->peek);}return $this->rawContent ?? '';