mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-09 17:37:02 +03:00
Revamp the FullNameHash system for better readable urls
And reduce the folders caching footprint. And it reduces server load.
This commit is contained in:
parent
76627ae2f6
commit
3a61bb3e5a
10 changed files with 90 additions and 78 deletions
|
|
@ -1361,22 +1361,43 @@ class MailClient
|
|||
*/
|
||||
public function FolderMove(string $sPrevFolderFullName, string $sNextFolderFullNameInUtf, bool $bSubscribeOnMove = true) : self
|
||||
{
|
||||
return $this->folderModify($sPrevFolderFullName, $sNextFolderFullNameInUtf, false, $bSubscribeOnMove);
|
||||
if (!$this->oImapClient->FolderHierarchyDelimiter($sPrevFolderFullName)) {
|
||||
// TODO: Translate
|
||||
throw new Exceptions\RuntimeException('Cannot move non-existent folder.');
|
||||
}
|
||||
return $this->folderModify($sPrevFolderFullName, $sNextFolderFullNameInUtf, $bSubscribeOnMove);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function FolderRename(string $sPrevFolderFullName, string $sNewTopFolderNameInUtf, bool $bSubscribeOnRename = true) : self
|
||||
public function FolderRename(string $sPrevFolderFullName, string $sNewTopFolderNameInUtf, bool $bSubscribeOnRename = true) : string
|
||||
{
|
||||
return $this->folderModify($sPrevFolderFullName, $sNewTopFolderNameInUtf, true, $bSubscribeOnRename);
|
||||
$sDelimiter = $this->oImapClient->FolderHierarchyDelimiter($sPrevFolderFullName);
|
||||
if (!$sDelimiter) {
|
||||
// TODO: Translate
|
||||
throw new Exceptions\RuntimeException('Cannot rename non-existent folder.');
|
||||
}
|
||||
|
||||
if (\strlen($sDelimiter) && false !== \strpos($sNewTopFolderNameInUtf, $sDelimiter)) {
|
||||
// TODO: Translate
|
||||
throw new Exceptions\RuntimeException('New folder name contains delimiter.');
|
||||
}
|
||||
|
||||
$iLast = \strrpos($sPrevFolderFullName, $sDelimiter);
|
||||
$sNewFolderFullName = (false === $iLast ? '' : \substr($sPrevFolderFullName, 0, $iLast + 1))
|
||||
. $sNewTopFolderNameInUtf;
|
||||
|
||||
$this->folderModify($sPrevFolderFullName, $sNewFolderFullName, $bSubscribeOnRename);
|
||||
|
||||
return $sNewFolderFullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
* @throws \MailSo\Base\Exceptions\RuntimeException
|
||||
*/
|
||||
protected function folderModify(string $sPrevFolderFullName, string $sNewFolderFullName, bool $bRename, bool $bSubscribeOnModify) : self
|
||||
protected function folderModify(string $sPrevFolderFullName, string $sNewFolderFullName, bool $bSubscribe) : self
|
||||
{
|
||||
if (!\strlen($sPrevFolderFullName) || !\strlen($sNewFolderFullName))
|
||||
{
|
||||
|
|
@ -1384,7 +1405,7 @@ class MailClient
|
|||
}
|
||||
|
||||
$aSubscribeFolders = array();
|
||||
if ($bSubscribeOnModify)
|
||||
if ($bSubscribe)
|
||||
{
|
||||
$aSubscribeFolders = $this->oImapClient->FolderSubscribeList($sPrevFolderFullName, '*');
|
||||
foreach ($aSubscribeFolders as /* @var $oFolder \MailSo\Imap\Folder */ $oFolder)
|
||||
|
|
@ -1393,27 +1414,6 @@ class MailClient
|
|||
}
|
||||
}
|
||||
|
||||
if ($bRename)
|
||||
{
|
||||
$sDelimiter = $this->oImapClient->FolderHierarchyDelimiter($sPrevFolderFullName);
|
||||
if (!$sDelimiter)
|
||||
{
|
||||
// TODO: Translate
|
||||
throw new Exceptions\RuntimeException('Cannot '.($bRename?'rename':'move').' non-existent folder.');
|
||||
}
|
||||
|
||||
$iLast = \strrpos($sPrevFolderFullName, $sDelimiter);
|
||||
|
||||
if (\strlen($sDelimiter) && false !== \strpos($sNewFolderFullName, $sDelimiter))
|
||||
{
|
||||
// TODO: Translate
|
||||
throw new Exceptions\RuntimeException('New folder name contains delimiter.');
|
||||
}
|
||||
|
||||
$sNewFolderFullName = (false === $iLast ? '' : \substr($sPrevFolderFullName, 0, $iLast + 1))
|
||||
. $sNewFolderFullName;
|
||||
}
|
||||
|
||||
$this->oImapClient->FolderRename($sPrevFolderFullName, $sNewFolderFullName);
|
||||
|
||||
foreach ($aSubscribeFolders as /* @var $oFolder \MailSo\Imap\Folder */ $oFolder)
|
||||
|
|
|
|||
|
|
@ -320,11 +320,12 @@ trait Folders
|
|||
{
|
||||
$this->initMailClientConnection();
|
||||
|
||||
$sName = $this->GetActionParam('NewFolderName', '');
|
||||
try
|
||||
{
|
||||
$this->MailClient()->FolderRename(
|
||||
$sFullName = $this->MailClient()->FolderRename(
|
||||
$this->GetActionParam('Folder', ''),
|
||||
$this->GetActionParam('NewFolderName', ''),
|
||||
$sName,
|
||||
!!$this->Config()->Get('labs', 'use_imap_list_subscribe', true)
|
||||
);
|
||||
}
|
||||
|
|
@ -333,7 +334,11 @@ trait Folders
|
|||
throw new ClientException(Notifications::CantRenameFolder, $oException);
|
||||
}
|
||||
|
||||
return $this->TrueResponse(__FUNCTION__);
|
||||
// FolderInformation(string $sFolderName, int $iPrevUidNext = 0, array $aUids = array())
|
||||
return $this->DefaultResponse(__FUNCTION__, array(
|
||||
'Name' => $sName,
|
||||
'FullName' => $sFullName,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -139,12 +139,6 @@ trait Response
|
|||
return $bResult;
|
||||
}
|
||||
|
||||
private function hashFolderFullName(string $sFolderFullName) : string
|
||||
{
|
||||
// return \strspn(\mb_strtolower($sFolderFullName), ':/#?') ? \md5($sFolderFullName) : $sFolderFullName;
|
||||
return \preg_match('/^[a-z0-9]+$/iu', $sFolderFullName) ? $sFolderFullName : \md5($sFolderFullName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mResponse
|
||||
*
|
||||
|
|
@ -382,7 +376,6 @@ trait Response
|
|||
return \array_merge(
|
||||
$mResponse->jsonSerialize(),
|
||||
array(
|
||||
'FullNameHash' => $this->hashFolderFullName($mResponse->FullName()),
|
||||
'Checkable' => \in_array($mResponse->FullName(), $this->aCheckableFolder),
|
||||
'Extended' => $aExtended,
|
||||
'SubFolders' => $this->responseObject($mResponse->SubFolders(), $sParent, $aParameters)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue