Bugfix: folder rename/move was broken

This commit is contained in:
djmaze 2021-12-02 23:21:12 +01:00
parent 792fee547a
commit c1228d09f0

View file

@ -1385,22 +1385,13 @@ class MailClient
* @throws \MailSo\Base\Exceptions\InvalidArgumentException * @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Base\Exceptions\RuntimeException * @throws \MailSo\Base\Exceptions\RuntimeException
*/ */
protected function folderModify(string $sPrevFolderFullName, string $sNextFolderNameInUtf, bool $bRename, bool $bSubscribeOnModify) : self protected function folderModify(string $sPrevFolderFullName, string $sNewFolderFullName, bool $bRename, bool $bSubscribeOnModify) : self
{ {
if (!\strlen($sPrevFolderFullName) || !\strlen($sNextFolderNameInUtf)) if (!\strlen($sPrevFolderFullName) || !\strlen($sNewFolderFullName))
{ {
throw new \MailSo\Base\Exceptions\InvalidArgumentException; throw new \MailSo\Base\Exceptions\InvalidArgumentException;
} }
$sDelimiter = $this->oImapClient->FolderHierarchyDelimiter($sPrevFolderFullName);
if (!$sDelimiter)
{
// TODO: Translate
throw new Exceptions\RuntimeException('Cannot '.($bRename?'rename':'move').' non-existent folder.');
}
$iLast = \strrpos($sPrevFolderFullName, $sDelimiter);
$aSubscribeFolders = array(); $aSubscribeFolders = array();
if ($bSubscribeOnModify) if ($bSubscribeOnModify)
{ {
@ -1413,14 +1404,23 @@ class MailClient
if ($bRename) 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)) if (\strlen($sDelimiter) && false !== \strpos($sNewFolderFullName, $sDelimiter))
{ {
// TODO: Translate // TODO: Translate
throw new Exceptions\RuntimeException('New folder name contains delimiter.'); throw new Exceptions\RuntimeException('New folder name contains delimiter.');
} }
$sFolderParentFullName = false === $iLast ? '' : \substr($sPrevFolderFullName, 0, $iLast + 1); $sNewFolderFullName = (false === $iLast ? '' : \substr($sPrevFolderFullName, 0, $iLast + 1))
$sNewFolderFullName = $sFolderParentFullName.$sNewFolderFullName; . $sNewFolderFullName;
} }
$this->oImapClient->FolderRename($sPrevFolderFullName, $sNewFolderFullName); $this->oImapClient->FolderRename($sPrevFolderFullName, $sNewFolderFullName);