Improved mailbox ETag

This commit is contained in:
the-djmaze 2023-03-13 09:56:35 +01:00
parent 2dbf192558
commit 59b3fe70b6
7 changed files with 26 additions and 47 deletions

View file

@ -214,9 +214,11 @@ trait Folders
// $oFolderInfo->SIZE = \max($oFolderInfo->SIZE, $oInfo->SIZE);
// $oFolderInfo->RECENT = \max(0, $oFolderInfo->RECENT, $oInfo->RECENT);
$oFolderInfo->hasStatus = $oInfo->hasStatus;
$oFolderInfo->generateETag($this);
return $oFolderInfo;
}
$oInfo->generateETag($this);
return $oInfo;
}
@ -436,6 +438,7 @@ trait Folders
}
*/
$this->oCurrentFolderInfo = $oResult;
$oResult->generateETag($this);
return $oResult;
}
@ -516,6 +519,7 @@ trait Folders
$oFolderCollection[$sFullName] = new Folder($sFullName);
}
$oFolderCollection[$sFullName]->setStatusFromResponse($oResponse);
$oFolderCollection[$sFullName]->generateETag($this);
}
else if ($sCmd === $oResponse->StatusOrIndex && 5 === \count($oResponse->ResponseList)) {
try

View file

@ -148,32 +148,16 @@ class Folder implements \JsonSerializable
return $role ? \ltrim($role, '\\') : null;
}
public function ETag(string $sClientHash) : ?string
{
return $this->Selectable() ? $this->getETag($sClientHash) : null;
}
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
/*
$aExtended = null;
if (isset($this->MESSAGES, $this->UNSEEN, $this->UIDNEXT)) {
$aExtended = array(
'totalEmails' => (int) $this->MESSAGES,
'unreadEmails' => (int) $this->UNSEEN,
'uidNext' => (int) $this->UIDNEXT,
// 'etag' => $this->ETag($this->getAccountFromToken()->IncLogin())
);
}
*/
/*
if ($this->ImapClient->hasCapability('ACL') || $this->ImapClient->CapabilityValue('RIGHTS')) {
// MailSo\Imap\Responses\ACL
$rights = $this->ImapClient->FolderMyRights($this->FullName);
}
*/
return array(
$result = array(
'@Object' => 'Object/Folder',
'name' => $this->Name(),
'fullName' => $this->FullName,
@ -202,5 +186,9 @@ class Folder implements \JsonSerializable
]
*/
);
if ($this->etag) {
$result['etag'] = $this->etag;
}
return $result;
}
}

View file

@ -19,8 +19,6 @@ class FolderInformation implements \JsonSerializable
{
use Traits\Status;
public string $etag = '';
public bool $IsWritable;
/**
@ -39,11 +37,6 @@ class FolderInformation implements \JsonSerializable
$this->IsWritable = $bIsWritable;
}
public function generateETag(ImapClient $oImapClient) : void
{
$this->etag = $this->getETag($oImapClient->Hash());
}
public function IsFlagSupported(string $sFlag) : bool
{
return \in_array('\\*', $this->PermanentFlags) ||
@ -75,7 +68,7 @@ class FolderInformation implements \JsonSerializable
if (isset($this->SIZE)) {
$result['size'] = $this->SIZE;
}
if (isset($this->etag)) {
if ($this->etag) {
$result['etag'] = $this->etag;
}
return $result;

View file

@ -87,24 +87,25 @@ trait Status
*/
public ?int $SIZE = null;
public function getETag(string $sClientHash) : ?string
public ?string $etag = null;
public function generateETag(\MailSo\Imap\ImapClient $oImapClient) : void
{
if (!$this->hasStatus) {
// UNSEEN undefined when only SELECT/EXAMINE is used
\error_log("STATUS missing " . \print_r($this,true));
return null;
return;
}
if (!isset($this->MESSAGES, $this->UIDNEXT)) {
return null;
return;
}
return \md5('FolderHash/'. \implode('-', [
$this->FullName,
$this->MESSAGES,
$this->UIDNEXT,
$this->UIDVALIDITY,
$this->UNSEEN,
$this->HIGHESTMODSEQ,
$sClientHash
$this->etag = \md5('FolderHash/'. \implode('-', [
$this->FullName,
$this->MESSAGES,
$this->UIDNEXT,
$this->UIDVALIDITY,
$this->UNSEEN,
$this->HIGHESTMODSEQ,
$oImapClient->Hash()
]));
}

View file

@ -361,7 +361,7 @@ class MailClient
'mailboxId' => $oInfo->MAILBOXID ?: '',
// 'flags' => $oInfo->Flags,
// 'permanentFlags' => $oInfo->PermanentFlags,
'etag' => $oInfo->getETag($this->oImapClient->Hash()),
'etag' => $oInfo->etag,
'messagesFlags' => $aFlags,
'newMessages' => $this->getFolderNextMessageInformation(
$sFolderName,
@ -379,8 +379,8 @@ class MailClient
*/
public function FolderHash(string $sFolderName) : string
{
return $this->oImapClient->FolderStatus($sFolderName)->getETag($this->oImapClient->Hash());
// return $this->oImapClient->FolderStatusAndSelect($sFolderName)->getETag($this->oImapClient->Hash());
return $this->oImapClient->FolderStatus($sFolderName)->etag;
// return $this->oImapClient->FolderStatusAndSelect($sFolderName)->etag;
}
/**
@ -654,8 +654,6 @@ class MailClient
throw new \InvalidArgumentException('THREAD not supported');
}
$oInfo->generateETag($this->oImapClient);
if (!$oParams->iThreadUid) {
$oMessageCollection->NewMessages = $this->getFolderNextMessageInformation(
$oParams->sFolderName, $oParams->iPrevUidNext, $oInfo->UIDNEXT

View file

@ -65,7 +65,7 @@ trait Messages
// $oInfo = $this->MailClient()->FolderHash($oParams->sFolderName);
$oInfo = $this->ImapClient()->FolderStatusAndSelect($oParams->sFolderName);
$aRequestHash = \explode('-', $sHash);
$sFolderHash = $oInfo->getETag($this->getAccountFromToken()->IncLogin());
$sFolderHash = $oInfo->etag;
$sHash = $oParams->hash() . '-' . $sFolderHash;
if ($aRequestHash[1] == $sFolderHash) {
$this->verifyCacheByKey($sHash);

View file

@ -142,11 +142,6 @@ trait Response
if ($mResponse instanceof \MailSo\Imap\Folder) {
$aResult = $mResponse->jsonSerialize();
$sHash = $mResponse->ETag($this->getAccountFromToken()->IncLogin());
if ($sHash) {
$aResult['etag'] = $sHash;
}
if (null === $this->aCheckableFolder) {
$aCheckable = \json_decode(
$this->SettingsProvider(true)