/** * @return array */ public function AjaxFolderCreate() { $sFolderNameInUtf8 = trim((string) $this->getParamValue('FolderNameInUtf8', '')); $sDelimiter = trim((string) $this->getParamValue('Delimiter', '')); $sFolderParentFullNameRaw = (string) $this->getParamValue('FolderParentFullNameRaw', ''); if (0 === strlen($sFolderNameInUtf8) || 1 !== strlen($sDelimiter)) { throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::InvalidInputParameter); } $oAccount = $this->getAccountFromParam(); $this->oApiMail->createFolder($oAccount, $sFolderNameInUtf8, $sDelimiter, $sFolderParentFullNameRaw); if (!$oAccount->isExtensionEnabled(\CAccount::DisableFoldersManualSort)) { $aFoldersOrderList = $this->oApiMail->getFoldersOrder($oAccount); if (is_array($aFoldersOrderList) && 0 < count($aFoldersOrderList)) { $aFoldersOrderListNew = $aFoldersOrderList; $sFolderNameInUtf7Imap = \MailSo\Base\Utils::ConvertEncoding($sFolderNameInUtf8, \MailSo\Base\Enumerations\Charset::UTF_8, \MailSo\Base\Enumerations\Charset::UTF_7_IMAP); $sFolderFullNameRaw = (0 < strlen($sFolderParentFullNameRaw) ? $sFolderParentFullNameRaw . $sDelimiter : '') . $sFolderNameInUtf7Imap; $sFolderFullNameUtf8 = \MailSo\Base\Utils::ConvertEncoding($sFolderFullNameRaw, \MailSo\Base\Enumerations\Charset::UTF_7_IMAP, \MailSo\Base\Enumerations\Charset::UTF_8); $aFoldersOrderListNew[] = $sFolderFullNameRaw; $aFoldersOrderListUtf8 = array_map(function ($sValue) { return \MailSo\Base\Utils::ConvertEncoding($sValue, \MailSo\Base\Enumerations\Charset::UTF_7_IMAP, \MailSo\Base\Enumerations\Charset::UTF_8); }, $aFoldersOrderListNew); usort($aFoldersOrderListUtf8, 'strnatcasecmp'); $iKey = array_search($sFolderFullNameUtf8, $aFoldersOrderListUtf8, true); if (is_int($iKey) && 0 < $iKey && isset($aFoldersOrderListUtf8[$iKey - 1])) { $sUpperName = $aFoldersOrderListUtf8[$iKey - 1]; $iUpperKey = array_search(\MailSo\Base\Utils::ConvertEncoding($sUpperName, \MailSo\Base\Enumerations\Charset::UTF_8, \MailSo\Base\Enumerations\Charset::UTF_7_IMAP), $aFoldersOrderList, true); if (is_int($iUpperKey) && isset($aFoldersOrderList[$iUpperKey])) { \CApi::Log('insert order index:' . $iUpperKey); array_splice($aFoldersOrderList, $iUpperKey + 1, 0, $sFolderFullNameRaw); $this->oApiMail->updateFoldersOrder($oAccount, $aFoldersOrderList); } } } } return $this->TrueResponse($oAccount, __FUNCTION__); }