From fb8d5570994afd61c43f2806a636226d60c3d844 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 29 Nov 2023 22:45:40 +0100 Subject: [PATCH] Resolve #1338 --- dev/Model/Message.js | 1 + dev/View/Popup/Domain.js | 2 ++ snappymail/v/0.0.0/app/domains/default.json | 1 + .../0.0.0/app/libraries/MailSo/Imap/ImapClient.php | 3 +++ .../v/0.0.0/app/libraries/MailSo/Imap/Settings.php | 4 ++++ .../0.0.0/app/libraries/MailSo/Mail/MailClient.php | 12 ++++++++---- .../v/0.0.0/app/libraries/MailSo/Mail/Message.php | 14 ++++++++++++-- .../app/templates/Views/Admin/PopupsDomain.html | 7 +++++++ .../app/templates/Views/User/MailMessageList.html | 4 ++-- 9 files changed, 40 insertions(+), 8 deletions(-) diff --git a/dev/Model/Message.js b/dev/Model/Message.js index a0439c540..b26b5157f 100644 --- a/dev/Model/Message.js +++ b/dev/Model/Message.js @@ -79,6 +79,7 @@ export class MessageModel extends AbstractModel { subject: '', plain: '', html: '', + preview: null, size: 0, spamScore: 0, spamResult: '', diff --git a/dev/View/Popup/Domain.js b/dev/View/Popup/Domain.js index 0da270f42..de16fe7c7 100644 --- a/dev/View/Popup/Domain.js +++ b/dev/View/Popup/Domain.js @@ -37,6 +37,7 @@ const imapDisable_thread: false, imapDisable_binary: false, imapDisable_status_size: true, + imapDisable_preview: true, imapExpunge_all_on_delete: false, imapFast_simple_search: true, imapFetch_new_messages: true, @@ -88,6 +89,7 @@ const disable_thread: !!oDomain.imapDisable_thread(), disable_binary: !!oDomain.imapDisable_binary(), disable_status_size: !!oDomain.imapDisable_status_size(), + disable_preview: !!oDomain.imapDisable_preview(), folder_list_limit: pInt(oDomain.imapFolder_list_limit()), message_list_limit: pInt(oDomain.imapMessage_list_limit()) /* diff --git a/snappymail/v/0.0.0/app/domains/default.json b/snappymail/v/0.0.0/app/domains/default.json index 840103e33..86f5ccddd 100644 --- a/snappymail/v/0.0.0/app/domains/default.json +++ b/snappymail/v/0.0.0/app/domains/default.json @@ -29,6 +29,7 @@ "disable_thread": false, "disable_binary": false, "disable_status_size": true, + "disable_preview": true, "use_expunge_all_on_delete": false, "fast_simple_search": true, "force_select": false, diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php index 67e53aab9..494c663db 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php @@ -330,6 +330,9 @@ class ImapClient extends \MailSo\Net\NetClient if ($this->Settings->disable_status_size) { $aList = \array_diff($aList, ['STATUS=SIZE']); } + if ($this->Settings->disable_preview) { + $aList = \array_diff($aList, ['PREVIEW']); + } } $this->aCapabilityItems = $aList; } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Settings.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Settings.php index 66e88ce0e..85e40769b 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Settings.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Settings.php @@ -30,6 +30,8 @@ class Settings extends \MailSo\Net\ConnectSettings $disable_binary = false, // STATUS SIZE can take a significant amount of time, therefore not active by default $disable_status_size = true, + // RFC 8970 + $disable_preview = true, $expunge_all_on_delete = false, $fast_simple_search = true, $fetch_new_messages = true, @@ -56,6 +58,7 @@ class Settings extends \MailSo\Net\ConnectSettings 'disable_thread', 'disable_binary', 'disable_status_size', + 'disable_preview', 'expunge_all_on_delete', 'fast_simple_search', 'fetch_new_messages', @@ -95,6 +98,7 @@ class Settings extends \MailSo\Net\ConnectSettings 'disable_thread' => $this->disable_thread, 'disable_binary' => $this->disable_binary, 'disable_status_size' => $this->disable_status_size, + 'disable_preview' => $this->disable_preview, 'use_expunge_all_on_delete' => $this->expunge_all_on_delete, // 'body_text_limit' => $this->body_text_limit, 'fast_simple_search' => $this->fast_simple_search, diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php index 56c1767c0..884db9d38 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php @@ -467,14 +467,18 @@ class MailClient array &$aAllThreads = [], array &$aUnseenUIDs = []) : void { if (\count($oRange)) { - $aFetchIterator = $this->oImapClient->FetchIterate(array( + $aFetchItems = array( FetchType::UID, FetchType::RFC822_SIZE, FetchType::INTERNALDATE, FetchType::FLAGS, - FetchType::BODYSTRUCTURE, - $this->getEnvelopeOrHeadersRequestString() - ), (string) $oRange, $oRange->UID); + FetchType::BODYSTRUCTURE + ); + if ($this->oImapClient->hasCapability('PREVIEW')) { + $aFetchItems[] = FetchType::PREVIEW; + } + $aFetchItems[] = $this->getEnvelopeOrHeadersRequestString(); + $aFetchIterator = $this->oImapClient->FetchIterate($aFetchItems, (string) $oRange, $oRange->UID); // FETCH does not respond in the id order of the SequenceSet, so we prefill $aCollection for the right sort order. $aCollection = \array_fill_keys($oRange->getArrayCopy(), null); foreach ($aFetchIterator as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem) { diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php index 0e3ade98a..e3a950a5c 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php @@ -41,6 +41,10 @@ class Message implements \JsonSerializable */ $sEmailId = null, $sThreadId = null, + /** + * https://www.rfc-editor.org/rfc/rfc8970 + */ + $sPreview = null, // https://autocrypt.org/level1.html#the-autocrypt-header $sAutocrypt = ''; @@ -154,7 +158,7 @@ class Message implements \JsonSerializable // $oMessage->sEmailId = $oMessage->sEmailId ?: $oFetchResponse->GetFetchValue('X-GUID'); $aThreadId = $oFetchResponse->GetFetchValue(FetchType::THREADID); $oMessage->sThreadId = $aThreadId ? $aThreadId[0] : $oFetchResponse->GetFetchValue('X-GM-THRID'); - + $oMessage->sPreview = $oFetchResponse->GetFetchValue(FetchType::PREVIEW) ?: null; $sCharset = $oBodyStructure ? Utils::NormalizeCharset($oBodyStructure->SearchCharset()) : ''; $sHeaders = $oFetchResponse->GetHeaderFieldsValue(); @@ -461,6 +465,10 @@ class Message implements \JsonSerializable } } + if (\str_starts_with($oMessage->sSubject, '[Preview]')) { + $oMessage->sSubject = \mb_substr($oMessage->sSubject, 10); + } + return $oMessage; } @@ -566,7 +574,9 @@ class Message implements \JsonSerializable // 'threadId' => $this->sThreadId, // 'mailboxIds' => ['mailboxid'=>true], // 'keywords' => $keywords, - 'size' => $this->iSize + 'size' => $this->iSize, + + 'preview' => $this->sPreview ); if ($this->DraftInfo) { diff --git a/snappymail/v/0.0.0/app/templates/Views/Admin/PopupsDomain.html b/snappymail/v/0.0.0/app/templates/Views/Admin/PopupsDomain.html index cf4cf855d..a0d4ac4b9 100644 --- a/snappymail/v/0.0.0/app/templates/Views/Admin/PopupsDomain.html +++ b/snappymail/v/0.0.0/app/templates/Views/Admin/PopupsDomain.html @@ -128,6 +128,13 @@ label: 'STATUS SIZE' } }"> +