Improved IMAP4rev2 RFC9051 support

This commit is contained in:
djmaze 2021-10-29 12:55:46 +02:00
parent 1cdbf2b944
commit d3ad9dc115
8 changed files with 23 additions and 20 deletions

View file

@ -20,7 +20,7 @@ abstract class FolderResponseStatus
{ {
// rfc3501 // rfc3501
const MESSAGES = 'MESSAGES'; const MESSAGES = 'MESSAGES';
const RECENT = 'RECENT'; // Obsolete in IMAP4rev2 // const RECENT = 'RECENT'; // IMAP4rev2 deprecated
const UIDNEXT = 'UIDNEXT'; const UIDNEXT = 'UIDNEXT';
const UIDVALIDITY = 'UIDVALIDITY'; const UIDVALIDITY = 'UIDVALIDITY';
const UNSEEN = 'UNSEEN'; const UNSEEN = 'UNSEEN';

View file

@ -20,7 +20,7 @@ abstract class FolderStatus
{ {
// rfc3501 // rfc3501
const MESSAGES = 'MESSAGES'; const MESSAGES = 'MESSAGES';
const RECENT = 'RECENT'; // Obsolete in IMAP4rev2 // const RECENT = 'RECENT'; // IMAP4rev2 deprecated
const UIDNEXT = 'UIDNEXT'; const UIDNEXT = 'UIDNEXT';
const UIDVALIDITY = 'UIDVALIDITY'; const UIDVALIDITY = 'UIDVALIDITY';
const UNSEEN = 'UNSEEN'; const UNSEEN = 'UNSEEN';

View file

@ -18,7 +18,7 @@ namespace MailSo\Imap\Enumerations;
*/ */
abstract class MessageFlag abstract class MessageFlag
{ {
const RECENT = '\\Recent'; // const RECENT = '\\Recent'; // IMAP4rev2 deprecated
const SEEN = '\\Seen'; const SEEN = '\\Seen';
const DELETED = '\\Deleted'; const DELETED = '\\Deleted';
const FLAGGED = '\\Flagged'; const FLAGGED = '\\Flagged';

View file

@ -442,6 +442,7 @@ class ImapClient extends \MailSo\Net\NetClient
$aReturnParams = array(); $aReturnParams = array();
if ($bIsSubscribeList) { if ($bIsSubscribeList) {
// IMAP4rev2 deprecated
$sCmd = 'LSUB'; $sCmd = 'LSUB';
} else if ($this->IsSupported('LIST-EXTENDED')) { } else if ($this->IsSupported('LIST-EXTENDED')) {
// RFC 5258 // RFC 5258
@ -556,6 +557,9 @@ class ImapClient extends \MailSo\Net\NetClient
throw new \MailSo\Base\Exceptions\InvalidArgumentException; 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', $this->oCurrentFolderInfo = $this->SendRequestGetResponse($bIsWritable ? 'SELECT' : 'EXAMINE',
array($this->EscapeString($sFolderName))) array($this->EscapeString($sFolderName)))
->getCurrentFolderInformation($sFolderName, $bIsWritable); ->getCurrentFolderInformation($sFolderName, $bIsWritable);

View file

@ -33,7 +33,7 @@ trait Status
/** /**
* The number of messages with the \Recent flag set. * The number of messages with the \Recent flag set.
* This response also occurs as a result of a SELECT or EXAMINE command. * This response also occurs as a result of a SELECT or EXAMINE command.
* Obsolete in IMAP4rev2 * IMAP4rev2 deprecated.
* @var int * @var int
*/ */
$RECENT, $RECENT,
@ -55,8 +55,9 @@ trait Status
/** /**
* The number of messages which do not have the \Seen flag set. * 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. * but then it is the message sequence number of the first unseen message.
* IMAP4rev2 deprecated on SELECT/EXAMINE.
* @var int * @var int
*/ */
$UNSEEN, $UNSEEN,

View file

@ -665,7 +665,7 @@ class MailClient
'MessageCount' => $iCount, 'MessageCount' => $iCount,
'MessageUnseenCount' => $iUnseenCount, 'MessageUnseenCount' => $iUnseenCount,
'UidNext' => $iUidNext, 'UidNext' => $iUidNext,
'Flags' => $aFlags, 'MessageFlags' => $aFlags,
'HighestModSeq' => $iHighestModSeq, 'HighestModSeq' => $iHighestModSeq,
'NewMessages' => 'INBOX' === $sFolderName && \MailSo\Config::$CheckNewMessages ? 'NewMessages' => 'INBOX' === $sFolderName && \MailSo\Config::$CheckNewMessages ?
$this->getFolderNextMessageInformation($sFolderName, $iPrevUidNext, $iUidNext) : array() $this->getFolderNextMessageInformation($sFolderName, $iPrevUidNext, $iUidNext) : array()

View file

@ -31,7 +31,6 @@ class Message implements \JsonSerializable
$iInternalTimeStampInUTC = 0, $iInternalTimeStampInUTC = 0,
$iHeaderTimeStampInUTC = 0, $iHeaderTimeStampInUTC = 0,
$sHeaderDate = '', $sHeaderDate = '',
$aFlags = [],
$aFlagsLowerCase = [], $aFlagsLowerCase = [],
/** /**
@ -194,11 +193,6 @@ class Message implements \JsonSerializable
return $this->sHeaderDate; return $this->sHeaderDate;
} }
public function Flags() : array
{
return $this->aFlags;
}
public function FlagsLowerCase() : array public function FlagsLowerCase() : array
{ {
return $this->aFlagsLowerCase; return $this->aFlagsLowerCase;
@ -317,8 +311,7 @@ class Message implements \JsonSerializable
$this->sFolder = $sFolder; $this->sFolder = $sFolder;
$this->iUid = (int) $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID); $this->iUid = (int) $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
$this->iSize = (int) $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE); $this->iSize = (int) $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE);
$this->aFlags = \is_array($aFlags) ? $aFlags : array(); $this->aFlagsLowerCase = \array_map('strtolower', $aFlags ?: []);
$this->aFlagsLowerCase = \array_map('strtolower', $this->aFlags);
$this->iInternalTimeStampInUTC = $this->iInternalTimeStampInUTC =
\MailSo\Base\DateTimeHelper::ParseInternalDateString($sInternalDate); \MailSo\Base\DateTimeHelper::ParseInternalDateString($sInternalDate);
@ -692,7 +685,11 @@ class Message implements \JsonSerializable
'IsSeen' => \in_array('\\seen', $this->aFlagsLowerCase), 'IsSeen' => \in_array('\\seen', $this->aFlagsLowerCase),
'IsFlagged' => \in_array('\\flagged', $this->aFlagsLowerCase), 'IsFlagged' => \in_array('\\flagged', $this->aFlagsLowerCase),
'IsAnswered' => \in_array('\\answered', $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)
); );
} }
} }

View file

@ -363,8 +363,7 @@ trait Folders
$aInboxInformation = $this->MailClient()->FolderInformation( $aInboxInformation = $this->MailClient()->FolderInformation(
$sFolder, $iPrevUidNext, $aFlagsUids $sFolder, $iPrevUidNext, $aFlagsUids
); );
foreach ($aInboxInformation['MessageFlags'] as $iUid => $aFlags)
foreach ($aInboxInformation['Flags'] as $iUid => $aFlags)
{ {
$aLowerFlags = \array_map('strtolower', $aFlags); $aLowerFlags = \array_map('strtolower', $aFlags);
$aInboxInformation['Flags'][$iUid] = array( $aInboxInformation['Flags'][$iUid] = array(
@ -374,11 +373,13 @@ trait Folders
'IsFlagged' => \in_array('\\flagged', $aLowerFlags), 'IsFlagged' => \in_array('\\flagged', $aLowerFlags),
'IsAnswered' => \in_array('\\answered', $aLowerFlags), 'IsAnswered' => \in_array('\\answered', $aLowerFlags),
'IsDeleted' => \in_array('\\deleted', $aLowerFlags), 'IsDeleted' => \in_array('\\deleted', $aLowerFlags),
'IsForwarded' => $sForwardedFlag && \in_array(\strtolower($sForwardedFlag), $aLowerFlags), 'IsForwarded' => \in_array(\strtolower('$Forwarded'), $aLowerFlags) || ($sForwardedFlag && \in_array(\strtolower($sForwardedFlag), $aLowerFlags)),
'IsReadReceipt' => $sReadReceiptFlag && \in_array(\strtolower($sReadReceiptFlag), $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) catch (\Throwable $oException)
{ {