Skip to content

Commit

Permalink
Use UNSEEN in folder ETag #1003
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Mar 6, 2023
1 parent 24cf17f commit b7963eb
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 78 deletions.
6 changes: 3 additions & 3 deletions snappymail/v/0.0.0/app/libraries/MailSo/Imap/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ public function Role() : ?string
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]
Expand All @@ -163,7 +163,7 @@ public function jsonSerialize()
'totalEmails' => (int) $this->MESSAGES,
'unreadEmails' => (int) $this->UNSEEN,
'uidNext' => (int) $this->UIDNEXT,
// 'etag' => $this->Hash($this->ImapClient()->Hash())
// 'etag' => $this->ETag($this->ImapClient()->Hash())
);
}
*/
Expand Down
144 changes: 70 additions & 74 deletions snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 with the \Recent flag set.
* This response also occurs as a result of a SELECT or EXAMINE command.
* IMAP4rev2 deprecated.
* @var int
*/
$RECENT,

/**
* 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 unique identifier validity value of the mailbox.
* This response also occurs as a result of a SELECT or EXAMINE command.
* @var int
*/
$UIDVALIDITY,

/**
* 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,

/**
* 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 7889
* Message upload size limit.
* @var int
*/
$APPENDLIMIT,

/**
* 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 9051
* The total size of the mailbox in octets.
* @var int
*/
$SIZE;
/**
* 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.
*/
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.
*/
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.
*/
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.
*/
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.
* 1*DIGIT Positive unsigned 64-bit integer
*/
public ?int $HIGHESTMODSEQ = null;

/**
* 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.
*/
public ?string $MAILBOXID = null;

/**
* 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;
}
Expand All @@ -106,13 +102,13 @@ public function getETag(string $sClientHash) : ?string
$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';
Expand Down Expand Up @@ -150,7 +146,7 @@ public function setStatusFromResponse(\MailSo\Imap\Response $oResponse) : bool
// 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]);
}
}

Expand All @@ -162,7 +158,7 @@ public function setStatusFromResponse(\MailSo\Imap\Response $oResponse) : bool
&& \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]
);
Expand All @@ -173,7 +169,7 @@ public function setStatusFromResponse(\MailSo\Imap\Response $oResponse) : bool
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]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private function responseObject($mResponse, string $sParent = '')
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;
}
Expand Down

0 comments on commit b7963eb

Please sign in to comment.