From d3ad9dc1158c2bef32c1665cd87451b355cf6630 Mon Sep 17 00:00:00 2001 From: djmaze Date: Fri, 29 Oct 2021 12:55:46 +0200 Subject: [PATCH] Improved IMAP4rev2 RFC9051 support --- .../Imap/Enumerations/FolderResponseStatus.php | 2 +- .../MailSo/Imap/Enumerations/FolderStatus.php | 2 +- .../MailSo/Imap/Enumerations/MessageFlag.php | 2 +- .../app/libraries/MailSo/Imap/ImapClient.php | 4 ++++ .../app/libraries/MailSo/Imap/Traits/Status.php | 5 +++-- .../app/libraries/MailSo/Mail/MailClient.php | 2 +- .../v/0.0.0/app/libraries/MailSo/Mail/Message.php | 15 ++++++--------- .../app/libraries/RainLoop/Actions/Folders.php | 11 ++++++----- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FolderResponseStatus.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FolderResponseStatus.php index 587c5a401..8a602bbec 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FolderResponseStatus.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FolderResponseStatus.php @@ -20,7 +20,7 @@ abstract class FolderResponseStatus { // rfc3501 const MESSAGES = 'MESSAGES'; - const RECENT = 'RECENT'; // Obsolete in IMAP4rev2 +// const RECENT = 'RECENT'; // IMAP4rev2 deprecated const UIDNEXT = 'UIDNEXT'; const UIDVALIDITY = 'UIDVALIDITY'; const UNSEEN = 'UNSEEN'; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FolderStatus.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FolderStatus.php index 88403e088..4f44cd886 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FolderStatus.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FolderStatus.php @@ -20,7 +20,7 @@ abstract class FolderStatus { // rfc3501 const MESSAGES = 'MESSAGES'; - const RECENT = 'RECENT'; // Obsolete in IMAP4rev2 +// const RECENT = 'RECENT'; // IMAP4rev2 deprecated const UIDNEXT = 'UIDNEXT'; const UIDVALIDITY = 'UIDVALIDITY'; const UNSEEN = 'UNSEEN'; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/MessageFlag.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/MessageFlag.php index be19077ec..c2e2c2b69 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/MessageFlag.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/MessageFlag.php @@ -18,7 +18,7 @@ namespace MailSo\Imap\Enumerations; */ abstract class MessageFlag { - const RECENT = '\\Recent'; +// const RECENT = '\\Recent'; // IMAP4rev2 deprecated const SEEN = '\\Seen'; const DELETED = '\\Deleted'; const FLAGGED = '\\Flagged'; 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 2b3856705..c952bfd91 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 @@ -442,6 +442,7 @@ class ImapClient extends \MailSo\Net\NetClient $aReturnParams = array(); if ($bIsSubscribeList) { + // IMAP4rev2 deprecated $sCmd = 'LSUB'; } else if ($this->IsSupported('LIST-EXTENDED')) { // RFC 5258 @@ -556,6 +557,9 @@ class ImapClient extends \MailSo\Net\NetClient throw new \MailSo\Base\Exceptions\InvalidArgumentException; } + /** + * IMAP4rev2 SELECT/EXAMINE are now required to return an untagged LIST response. + */ $this->oCurrentFolderInfo = $this->SendRequestGetResponse($bIsWritable ? 'SELECT' : 'EXAMINE', array($this->EscapeString($sFolderName))) ->getCurrentFolderInformation($sFolderName, $bIsWritable); diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/Status.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/Status.php index 5b3e7d8dc..659a3e9a0 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/Status.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/Status.php @@ -33,7 +33,7 @@ trait Status /** * The number of messages with the \Recent flag set. * This response also occurs as a result of a SELECT or EXAMINE command. - * Obsolete in IMAP4rev2 + * IMAP4rev2 deprecated. * @var int */ $RECENT, @@ -55,8 +55,9 @@ trait Status /** * The number of messages which do not have the \Seen flag set. - * This response also occurs as a result of a SELECT or EXAMINE command, + * This response also occurs as a result of a IMAP4rev1 SELECT or EXAMINE command, * but then it is the message sequence number of the first unseen message. + * IMAP4rev2 deprecated on SELECT/EXAMINE. * @var int */ $UNSEEN, 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 df90c2c69..656a727d9 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 @@ -665,7 +665,7 @@ class MailClient 'MessageCount' => $iCount, 'MessageUnseenCount' => $iUnseenCount, 'UidNext' => $iUidNext, - 'Flags' => $aFlags, + 'MessageFlags' => $aFlags, 'HighestModSeq' => $iHighestModSeq, 'NewMessages' => 'INBOX' === $sFolderName && \MailSo\Config::$CheckNewMessages ? $this->getFolderNextMessageInformation($sFolderName, $iPrevUidNext, $iUidNext) : array() 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 9d8d39e1d..5863f880f 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 @@ -31,7 +31,6 @@ class Message implements \JsonSerializable $iInternalTimeStampInUTC = 0, $iHeaderTimeStampInUTC = 0, $sHeaderDate = '', - $aFlags = [], $aFlagsLowerCase = [], /** @@ -194,11 +193,6 @@ class Message implements \JsonSerializable return $this->sHeaderDate; } - public function Flags() : array - { - return $this->aFlags; - } - public function FlagsLowerCase() : array { return $this->aFlagsLowerCase; @@ -317,8 +311,7 @@ class Message implements \JsonSerializable $this->sFolder = $sFolder; $this->iUid = (int) $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID); $this->iSize = (int) $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE); - $this->aFlags = \is_array($aFlags) ? $aFlags : array(); - $this->aFlagsLowerCase = \array_map('strtolower', $this->aFlags); + $this->aFlagsLowerCase = \array_map('strtolower', $aFlags ?: []); $this->iInternalTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseInternalDateString($sInternalDate); @@ -692,7 +685,11 @@ class Message implements \JsonSerializable 'IsSeen' => \in_array('\\seen', $this->aFlagsLowerCase), 'IsFlagged' => \in_array('\\flagged', $this->aFlagsLowerCase), 'IsAnswered' => \in_array('\\answered', $this->aFlagsLowerCase), - 'IsDeleted' => \in_array('\\deleted', $this->aFlagsLowerCase) + 'IsDeleted' => \in_array('\\deleted', $this->aFlagsLowerCase), + 'IsForwarded' => \in_array(\strtolower('$Forwarded'), $this->aFlagsLowerCase), + 'IsReadReceipt' => \in_array(\strtolower('$MDNSent'), $this->aFlagsLowerCase), + 'IsJunk' => !\in_array(\strtolower('$NonJunk'), $this->aFlagsLowerCase) && \in_array(\strtolower('$Junk'), $this->aFlagsLowerCase), + 'IsPhishing' => \in_array(\strtolower('$Phishing'), $this->aFlagsLowerCase) ); } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php index 11f136c2f..5bfb6fea2 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php @@ -363,8 +363,7 @@ trait Folders $aInboxInformation = $this->MailClient()->FolderInformation( $sFolder, $iPrevUidNext, $aFlagsUids ); - - foreach ($aInboxInformation['Flags'] as $iUid => $aFlags) + foreach ($aInboxInformation['MessageFlags'] as $iUid => $aFlags) { $aLowerFlags = \array_map('strtolower', $aFlags); $aInboxInformation['Flags'][$iUid] = array( @@ -374,11 +373,13 @@ trait Folders 'IsFlagged' => \in_array('\\flagged', $aLowerFlags), 'IsAnswered' => \in_array('\\answered', $aLowerFlags), 'IsDeleted' => \in_array('\\deleted', $aLowerFlags), - 'IsForwarded' => $sForwardedFlag && \in_array(\strtolower($sForwardedFlag), $aLowerFlags), - 'IsReadReceipt' => $sReadReceiptFlag && \in_array(\strtolower($sReadReceiptFlag), $aLowerFlags) + 'IsForwarded' => \in_array(\strtolower('$Forwarded'), $aLowerFlags) || ($sForwardedFlag && \in_array(\strtolower($sForwardedFlag), $aLowerFlags)), + 'IsReadReceipt' => \in_array(\strtolower('$MDNSent'), $aLowerFlags) || ($sReadReceiptFlag && \in_array(\strtolower($sReadReceiptFlag), $aLowerFlags)), + 'IsJunk' => !\in_array(\strtolower('$NonJunk'), $aLowerFlags) && \in_array(\strtolower('$Junk'), $aLowerFlags), + 'IsPhishing' => \in_array(\strtolower('$Phishing'), $aLowerFlags) ); } - $aInboxInformation['Flags'] = \array_values($aInboxInformation['Flags']); + $aInboxInformation['Flags'] = \array_values($aInboxInformation['MessageFlags']); } catch (\Throwable $oException) {