Added some RFC 9051 IMAP4rev2 details

Added the missing FolderCheck() and FolderClose() commands
This commit is contained in:
djmaze 2021-10-29 01:57:05 +02:00
parent 2eac280508
commit 76630f593d
5 changed files with 59 additions and 12 deletions

View file

@ -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';

View file

@ -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';

View file

@ -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;

View file

@ -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;
}

View file

@ -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,