Use UNSEEN in folder ETag #1003

This commit is contained in:
the-djmaze 2023-03-06 10:50:00 +01:00
parent 24cf17f68b
commit b7963ebfa0
3 changed files with 66 additions and 70 deletions

View file

@ -148,9 +148,9 @@ class Folder implements \JsonSerializable
return $role ? \ltrim($role, '\\') : null;
}
public function Hash(string $sClientHash) : ?string
public function ETag(string $sClientHash) : ?string
{
return $this->getETag($sClientHash);
return $this->Selectable() ? $this->getETag($sClientHash) : null;
}
#[\ReturnTypeWillChange]
@ -163,7 +163,7 @@ class Folder implements \JsonSerializable
'totalEmails' => (int) $this->MESSAGES,
'unreadEmails' => (int) $this->UNSEEN,
'uidNext' => (int) $this->UIDNEXT,
// 'etag' => $this->Hash($this->ImapClient()->Hash())
// 'etag' => $this->ETag($this->ImapClient()->Hash())
);
}
*/

View file

@ -26,78 +26,74 @@ trait Status
public bool $hasStatus = false;
public
/**
* The number of messages in the mailbox.
* This response is named EXISTS as a result of a SELECT or EXAMINE command.
* @var int
*/
$MESSAGES,
/**
* The number of messages in the mailbox.
* This response is named EXISTS as a result of a SELECT or EXAMINE command.
*/
public ?int $MESSAGES = null;
/**
* The number of messages with the \Recent flag set.
* This response also occurs as a result of a SELECT or EXAMINE command.
* IMAP4rev2 deprecated.
* @var int
*/
$RECENT,
/**
* The number of messages with the \Recent flag set.
* This response also occurs as a result of a SELECT or EXAMINE command.
* IMAP4rev2 deprecated.
*/
public ?int $RECENT = null;
/**
* The next unique identifier value of the mailbox.
* A 32-bit value
* This response also occurs as a result of a SELECT or EXAMINE command.
* @var int
*/
$UIDNEXT,
/**
* The next unique identifier value of the mailbox.
* A 32-bit value
* This response also occurs as a result of a SELECT or EXAMINE command.
*/
public ?int $UIDNEXT = null;
/**
* The unique identifier validity value of the mailbox.
* This response also occurs as a result of a SELECT or EXAMINE command.
* @var int
*/
$UIDVALIDITY,
/**
* The unique identifier validity value of the mailbox.
* This response also occurs as a result of a SELECT or EXAMINE command.
*/
public ?int $UIDVALIDITY = null;
/**
* The number of messages which do not have the \Seen flag set.
* 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,
/**
* The number of messages which do not have the \Seen flag set.
* 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.
*/
public ?int $UNSEEN = null;
/**
* RFC 4551
* The highest mod-sequence value of all messages in the mailbox.
* This response also occurs as a result of a SELECT or EXAMINE command.
* @var int 1*DIGIT Positive unsigned 64-bit integer
*/
$HIGHESTMODSEQ,
/**
* RFC 4551
* The highest mod-sequence value of all messages in the mailbox.
* This response also occurs as a result of a SELECT or EXAMINE command.
* 1*DIGIT Positive unsigned 64-bit integer
*/
public ?int $HIGHESTMODSEQ = null;
/**
* RFC 7889
* Message upload size limit.
* @var int
*/
$APPENDLIMIT,
/**
* RFC 7889
* Message upload size limit.
*/
public ?int $APPENDLIMIT = null;
/**
* RFC 8474
* A server-allocated unique identifier for the mailbox.
* This response also occurs as a result of a CREATE, SELECT or EXAMINE command.
* @var string
*/
$MAILBOXID,
/**
* RFC 8474
* A server-allocated unique identifier for the mailbox.
* This response also occurs as a result of a CREATE, SELECT or EXAMINE command.
*/
public ?string $MAILBOXID = null;
/**
* RFC 9051
* The total size of the mailbox in octets.
* @var int
*/
$SIZE;
/**
* RFC 9051
* The total size of the mailbox in octets.
*/
public ?int $SIZE = null;
public function getETag(string $sClientHash) : ?string
{
if (!$this->hasStatus) {
// UNSEEN undefined when only SELECT/EXAMINE is used
\error_log("STATUS missing " . \print_r($this,true));
return null;
}
if (!isset($this->MESSAGES, $this->UIDNEXT)) {
return null;
}
@ -106,13 +102,13 @@ trait Status
$this->MESSAGES,
$this->UIDNEXT,
$this->UIDVALIDITY,
// $this->UNSEEN, // undefined when SELECT/EXAMINE
$this->UNSEEN,
$this->HIGHESTMODSEQ,
$sClientHash
]));
}
private function setStatus(string $name, $value) : bool
private function setStatusItem(string $name, $value) : bool
{
if ('EXISTS' === $name) {
$name = 'MESSAGES';
@ -150,7 +146,7 @@ trait Status
// OK untagged responses
if (\is_array($oResponse->OptionalResponse)) {
if (\count($oResponse->OptionalResponse) > 1) {
$bResult = $this->setStatus($oResponse->OptionalResponse[0], $oResponse->OptionalResponse[1]);
$bResult = $this->setStatusItem($oResponse->OptionalResponse[0], $oResponse->OptionalResponse[1]);
}
}
@ -162,7 +158,7 @@ trait Status
&& \is_array($oResponse->ResponseList[3])) {
$c = \count($oResponse->ResponseList[3]);
for ($i = 0; $i < $c; $i += 2) {
$bResult |= $this->setStatus(
$bResult |= $this->setStatusItem(
$oResponse->ResponseList[3][$i],
$oResponse->ResponseList[3][$i+1]
);
@ -173,7 +169,7 @@ trait Status
else if (\is_numeric($oResponse->ResponseList[1]) && \is_string($oResponse->ResponseList[2])) {
// UNSEEN deprecated in IMAP4rev2
if ('UNSEEN' !== $oResponse->ResponseList[2]) {
$bResult |= $this->setStatus($oResponse->ResponseList[2], $oResponse->ResponseList[1]);
$bResult |= $this->setStatusItem($oResponse->ResponseList[2], $oResponse->ResponseList[1]);
}
}
}

View file

@ -191,7 +191,7 @@ trait Response
if ($mResponse instanceof \MailSo\Imap\Folder) {
$aResult = $mResponse->jsonSerialize();
$sHash = $mResponse->Hash($this->ImapClient()->Hash());
$sHash = $mResponse->ETag($this->ImapClient()->Hash());
if ($sHash) {
$aResult['etag'] = $sHash;
}