mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-06 07:57:02 +03:00
Improved mailbox ETag
This commit is contained in:
parent
2dbf192558
commit
59b3fe70b6
7 changed files with 26 additions and 47 deletions
|
|
@ -214,9 +214,11 @@ trait Folders
|
||||||
// $oFolderInfo->SIZE = \max($oFolderInfo->SIZE, $oInfo->SIZE);
|
// $oFolderInfo->SIZE = \max($oFolderInfo->SIZE, $oInfo->SIZE);
|
||||||
// $oFolderInfo->RECENT = \max(0, $oFolderInfo->RECENT, $oInfo->RECENT);
|
// $oFolderInfo->RECENT = \max(0, $oFolderInfo->RECENT, $oInfo->RECENT);
|
||||||
$oFolderInfo->hasStatus = $oInfo->hasStatus;
|
$oFolderInfo->hasStatus = $oInfo->hasStatus;
|
||||||
|
$oFolderInfo->generateETag($this);
|
||||||
return $oFolderInfo;
|
return $oFolderInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oInfo->generateETag($this);
|
||||||
return $oInfo;
|
return $oInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -436,6 +438,7 @@ trait Folders
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
$this->oCurrentFolderInfo = $oResult;
|
$this->oCurrentFolderInfo = $oResult;
|
||||||
|
$oResult->generateETag($this);
|
||||||
|
|
||||||
return $oResult;
|
return $oResult;
|
||||||
}
|
}
|
||||||
|
|
@ -516,6 +519,7 @@ trait Folders
|
||||||
$oFolderCollection[$sFullName] = new Folder($sFullName);
|
$oFolderCollection[$sFullName] = new Folder($sFullName);
|
||||||
}
|
}
|
||||||
$oFolderCollection[$sFullName]->setStatusFromResponse($oResponse);
|
$oFolderCollection[$sFullName]->setStatusFromResponse($oResponse);
|
||||||
|
$oFolderCollection[$sFullName]->generateETag($this);
|
||||||
}
|
}
|
||||||
else if ($sCmd === $oResponse->StatusOrIndex && 5 === \count($oResponse->ResponseList)) {
|
else if ($sCmd === $oResponse->StatusOrIndex && 5 === \count($oResponse->ResponseList)) {
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -148,32 +148,16 @@ class Folder implements \JsonSerializable
|
||||||
return $role ? \ltrim($role, '\\') : null;
|
return $role ? \ltrim($role, '\\') : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ETag(string $sClientHash) : ?string
|
|
||||||
{
|
|
||||||
return $this->Selectable() ? $this->getETag($sClientHash) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[\ReturnTypeWillChange]
|
#[\ReturnTypeWillChange]
|
||||||
public function jsonSerialize()
|
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')) {
|
if ($this->ImapClient->hasCapability('ACL') || $this->ImapClient->CapabilityValue('RIGHTS')) {
|
||||||
// MailSo\Imap\Responses\ACL
|
// MailSo\Imap\Responses\ACL
|
||||||
$rights = $this->ImapClient->FolderMyRights($this->FullName);
|
$rights = $this->ImapClient->FolderMyRights($this->FullName);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return array(
|
$result = array(
|
||||||
'@Object' => 'Object/Folder',
|
'@Object' => 'Object/Folder',
|
||||||
'name' => $this->Name(),
|
'name' => $this->Name(),
|
||||||
'fullName' => $this->FullName,
|
'fullName' => $this->FullName,
|
||||||
|
|
@ -202,5 +186,9 @@ class Folder implements \JsonSerializable
|
||||||
]
|
]
|
||||||
*/
|
*/
|
||||||
);
|
);
|
||||||
|
if ($this->etag) {
|
||||||
|
$result['etag'] = $this->etag;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ class FolderInformation implements \JsonSerializable
|
||||||
{
|
{
|
||||||
use Traits\Status;
|
use Traits\Status;
|
||||||
|
|
||||||
public string $etag = '';
|
|
||||||
|
|
||||||
public bool $IsWritable;
|
public bool $IsWritable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,11 +37,6 @@ class FolderInformation implements \JsonSerializable
|
||||||
$this->IsWritable = $bIsWritable;
|
$this->IsWritable = $bIsWritable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateETag(ImapClient $oImapClient) : void
|
|
||||||
{
|
|
||||||
$this->etag = $this->getETag($oImapClient->Hash());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function IsFlagSupported(string $sFlag) : bool
|
public function IsFlagSupported(string $sFlag) : bool
|
||||||
{
|
{
|
||||||
return \in_array('\\*', $this->PermanentFlags) ||
|
return \in_array('\\*', $this->PermanentFlags) ||
|
||||||
|
|
@ -75,7 +68,7 @@ class FolderInformation implements \JsonSerializable
|
||||||
if (isset($this->SIZE)) {
|
if (isset($this->SIZE)) {
|
||||||
$result['size'] = $this->SIZE;
|
$result['size'] = $this->SIZE;
|
||||||
}
|
}
|
||||||
if (isset($this->etag)) {
|
if ($this->etag) {
|
||||||
$result['etag'] = $this->etag;
|
$result['etag'] = $this->etag;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
||||||
|
|
@ -87,24 +87,25 @@ trait Status
|
||||||
*/
|
*/
|
||||||
public ?int $SIZE = null;
|
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) {
|
if (!$this->hasStatus) {
|
||||||
// UNSEEN undefined when only SELECT/EXAMINE is used
|
// UNSEEN undefined when only SELECT/EXAMINE is used
|
||||||
\error_log("STATUS missing " . \print_r($this,true));
|
\error_log("STATUS missing " . \print_r($this,true));
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
if (!isset($this->MESSAGES, $this->UIDNEXT)) {
|
if (!isset($this->MESSAGES, $this->UIDNEXT)) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
return \md5('FolderHash/'. \implode('-', [
|
$this->etag = \md5('FolderHash/'. \implode('-', [
|
||||||
$this->FullName,
|
$this->FullName,
|
||||||
$this->MESSAGES,
|
$this->MESSAGES,
|
||||||
$this->UIDNEXT,
|
$this->UIDNEXT,
|
||||||
$this->UIDVALIDITY,
|
$this->UIDVALIDITY,
|
||||||
$this->UNSEEN,
|
$this->UNSEEN,
|
||||||
$this->HIGHESTMODSEQ,
|
$this->HIGHESTMODSEQ,
|
||||||
$sClientHash
|
$oImapClient->Hash()
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -361,7 +361,7 @@ class MailClient
|
||||||
'mailboxId' => $oInfo->MAILBOXID ?: '',
|
'mailboxId' => $oInfo->MAILBOXID ?: '',
|
||||||
// 'flags' => $oInfo->Flags,
|
// 'flags' => $oInfo->Flags,
|
||||||
// 'permanentFlags' => $oInfo->PermanentFlags,
|
// 'permanentFlags' => $oInfo->PermanentFlags,
|
||||||
'etag' => $oInfo->getETag($this->oImapClient->Hash()),
|
'etag' => $oInfo->etag,
|
||||||
'messagesFlags' => $aFlags,
|
'messagesFlags' => $aFlags,
|
||||||
'newMessages' => $this->getFolderNextMessageInformation(
|
'newMessages' => $this->getFolderNextMessageInformation(
|
||||||
$sFolderName,
|
$sFolderName,
|
||||||
|
|
@ -379,8 +379,8 @@ class MailClient
|
||||||
*/
|
*/
|
||||||
public function FolderHash(string $sFolderName) : string
|
public function FolderHash(string $sFolderName) : string
|
||||||
{
|
{
|
||||||
return $this->oImapClient->FolderStatus($sFolderName)->getETag($this->oImapClient->Hash());
|
return $this->oImapClient->FolderStatus($sFolderName)->etag;
|
||||||
// return $this->oImapClient->FolderStatusAndSelect($sFolderName)->getETag($this->oImapClient->Hash());
|
// return $this->oImapClient->FolderStatusAndSelect($sFolderName)->etag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -654,8 +654,6 @@ class MailClient
|
||||||
throw new \InvalidArgumentException('THREAD not supported');
|
throw new \InvalidArgumentException('THREAD not supported');
|
||||||
}
|
}
|
||||||
|
|
||||||
$oInfo->generateETag($this->oImapClient);
|
|
||||||
|
|
||||||
if (!$oParams->iThreadUid) {
|
if (!$oParams->iThreadUid) {
|
||||||
$oMessageCollection->NewMessages = $this->getFolderNextMessageInformation(
|
$oMessageCollection->NewMessages = $this->getFolderNextMessageInformation(
|
||||||
$oParams->sFolderName, $oParams->iPrevUidNext, $oInfo->UIDNEXT
|
$oParams->sFolderName, $oParams->iPrevUidNext, $oInfo->UIDNEXT
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ trait Messages
|
||||||
// $oInfo = $this->MailClient()->FolderHash($oParams->sFolderName);
|
// $oInfo = $this->MailClient()->FolderHash($oParams->sFolderName);
|
||||||
$oInfo = $this->ImapClient()->FolderStatusAndSelect($oParams->sFolderName);
|
$oInfo = $this->ImapClient()->FolderStatusAndSelect($oParams->sFolderName);
|
||||||
$aRequestHash = \explode('-', $sHash);
|
$aRequestHash = \explode('-', $sHash);
|
||||||
$sFolderHash = $oInfo->getETag($this->getAccountFromToken()->IncLogin());
|
$sFolderHash = $oInfo->etag;
|
||||||
$sHash = $oParams->hash() . '-' . $sFolderHash;
|
$sHash = $oParams->hash() . '-' . $sFolderHash;
|
||||||
if ($aRequestHash[1] == $sFolderHash) {
|
if ($aRequestHash[1] == $sFolderHash) {
|
||||||
$this->verifyCacheByKey($sHash);
|
$this->verifyCacheByKey($sHash);
|
||||||
|
|
|
||||||
|
|
@ -142,11 +142,6 @@ trait Response
|
||||||
if ($mResponse instanceof \MailSo\Imap\Folder) {
|
if ($mResponse instanceof \MailSo\Imap\Folder) {
|
||||||
$aResult = $mResponse->jsonSerialize();
|
$aResult = $mResponse->jsonSerialize();
|
||||||
|
|
||||||
$sHash = $mResponse->ETag($this->getAccountFromToken()->IncLogin());
|
|
||||||
if ($sHash) {
|
|
||||||
$aResult['etag'] = $sHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $this->aCheckableFolder) {
|
if (null === $this->aCheckableFolder) {
|
||||||
$aCheckable = \json_decode(
|
$aCheckable = \json_decode(
|
||||||
$this->SettingsProvider(true)
|
$this->SettingsProvider(true)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue