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 39c7166cf..587c5a401 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'; + const RECENT = 'RECENT'; // Obsolete in IMAP4rev2 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 97435602f..88403e088 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'; + const RECENT = 'RECENT'; // Obsolete in IMAP4rev2 const UIDNEXT = 'UIDNEXT'; const UIDVALIDITY = 'UIDVALIDITY'; const UNSEEN = 'UNSEEN'; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Exceptions/ResponseException.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Exceptions/ResponseException.php index bc62eeb5e..c4e3ff46a 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Exceptions/ResponseException.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Exceptions/ResponseException.php @@ -32,6 +32,12 @@ class ResponseException extends \MailSo\Imap\Exceptions\Exception parent::__construct($sMessage, $iCode, $oPrevious); } + public function GetResponseStatus() : ?string + { + $oItem = $this->GetLastResponse(); + return $oItem && $oItem->IsStatusResponse ? $oItem->StatusOrIndex : null; + } + public function GetResponses() : ?\MailSo\Imap\ResponseCollection { return $this->oResponses; 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 77dd0adba..15284960e 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 @@ -239,6 +239,12 @@ class ImapClient extends \MailSo\Net\NetClient { $this->SendRequestGetResponse('PROXYAUTH', array($this->EscapeString($sProxyAuthUser))); } +/* + // RFC 9051 + if ($this->IsSupported('IMAP4rev2')) { + $this->SendRequestGetResponse('ENABLE', array('IMAP4rev1')); + } +*/ } catch (Exceptions\NegativeResponseException $oException) { @@ -288,7 +294,7 @@ class ImapClient extends \MailSo\Net\NetClient /** * Test support for things like: - * IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY + * IMAP4rev1 IMAP4rev2 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY * THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND * URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED * I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH @@ -301,14 +307,12 @@ class ImapClient extends \MailSo\Net\NetClient */ public function IsSupported(string $sExtentionName) : bool { - $bResult = strlen(\trim($sExtentionName)); - if ($bResult && null === $this->aCapabilityItems) - { + $sExtentionName = \trim($sExtentionName); + if ($sExtentionName && null === $this->aCapabilityItems) { $this->aCapabilityItems = $this->Capability(); } - return $bResult && \is_array($this->aCapabilityItems) && - \in_array(\strtoupper($sExtentionName), $this->aCapabilityItems); + return $sExtentionName && \in_array(\strtoupper($sExtentionName), $this->aCapabilityItems ?: []); } /** @@ -588,14 +592,50 @@ class ImapClient extends \MailSo\Net\NetClient * @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception */ - public function FolderUnSelect() : self + public function FolderCheck() : self { - if ($this->IsSelected() && $this->IsSupported('UNSELECT')) - { - $this->SendRequestGetResponse('UNSELECT'); + if ($this->IsSelected()) { + $this->SendRequestGetResponse('CHECK'); + } + return $this; + } + + /** + * This also expunge the mailbox + * @throws \MailSo\Net\Exceptions\Exception + * @throws \MailSo\Imap\Exceptions\Exception + */ + public function FolderClose() : self + { + if ($this->IsSelected()) { + $this->SendRequestGetResponse('CLOSE'); $this->oCurrentFolderInfo = null; } + return $this; + } + /** + * @throws \MailSo\Net\Exceptions\Exception + * @throws \MailSo\Imap\Exceptions\Exception + */ + public function FolderUnSelect() : self + { + if ($this->IsSelected()) { + if ($this->IsSupported('UNSELECT')) { + $this->SendRequestGetResponse('UNSELECT'); + $this->oCurrentFolderInfo = null; + } else { + try { + $this->SendRequestGetResponse('SELECT', '""'); + // * OK [CLOSED] Previous mailbox closed. + // 3 NO [CANNOT] Invalid mailbox name: Name is empty + } catch (Exceptions\NegativeResponseException $e) { + if ('NO' === $e->GetResponseStatus()) { + $this->oCurrentFolderInfo = null; + } + } + } + } return $this; } 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 d517b474b..5b3e7d8dc 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,6 +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 * @var int */ $RECENT,