/** * @param string $sPrevFolderFullNameRaw * @param string $sNextFolderNameInUtf * @param bool $bRenameOrMove * @param bool $bSubscribeOnModify * * @return \MailSo\Mail\MailClient * * @throws \MailSo\Base\Exceptions\InvalidArgumentException */ public function folderModify($sPrevFolderFullNameRaw, $sNextFolderNameInUtf, $bRenameOrMove, $bSubscribeOnModify) { if (0 === \strlen($sPrevFolderFullNameRaw) || 0 === \strlen($sNextFolderNameInUtf)) { throw new \MailSo\Base\Exceptions\InvalidArgumentException(); } $aFolders = $this->oImapClient->FolderList('', $sPrevFolderFullNameRaw); if (!\is_array($aFolders) || !isset($aFolders[0])) { // TODO throw new \MailSo\Mail\Exceptions\RuntimeException('Cannot rename non-existen folder'); } $sDelimiter = $aFolders[0]->Delimiter(); $iLast = \strrpos($sPrevFolderFullNameRaw, $sDelimiter); $mSubscribeFolders = null; if ($bSubscribeOnModify) { $mSubscribeFolders = $this->oImapClient->FolderSubscribeList($sPrevFolderFullNameRaw, '*'); if (\is_array($mSubscribeFolders) && 0 < count($mSubscribeFolders)) { foreach ($mSubscribeFolders as $oFolder) { $this->oImapClient->FolderUnSubscribe($oFolder->FullNameRaw()); } } } $sNewFolderFullNameRaw = \MailSo\Base\Utils::ConvertEncoding($sNextFolderNameInUtf, \MailSo\Base\Enumerations\Charset::UTF_8, \MailSo\Base\Enumerations\Charset::UTF_7_IMAP); if ($bRenameOrMove) { if (0 < \strlen($sDelimiter) && false !== \strpos($sNewFolderFullNameRaw, $sDelimiter)) { // TODO throw new \MailSo\Mail\Exceptions\RuntimeException('New folder name contain delimiter'); } $sFolderParentFullNameRaw = false === $iLast ? '' : \substr($sPrevFolderFullNameRaw, 0, $iLast + 1); $sNewFolderFullNameRaw = $sFolderParentFullNameRaw . $sNewFolderFullNameRaw; } $this->oImapClient->FolderRename($sPrevFolderFullNameRaw, $sNewFolderFullNameRaw); if (\is_array($mSubscribeFolders) && 0 < count($mSubscribeFolders)) { foreach ($mSubscribeFolders as $oFolder) { $sFolderFullNameRawForResubscrine = $oFolder->FullNameRaw(); if (0 === \strpos($sFolderFullNameRawForResubscrine, $sPrevFolderFullNameRaw)) { $sNewFolderFullNameRawForResubscrine = $sNewFolderFullNameRaw . \substr($sFolderFullNameRawForResubscrine, \strlen($sPrevFolderFullNameRaw)); $this->oImapClient->FolderSubscribe($sNewFolderFullNameRawForResubscrine); } } } return $this; }