public static function onUserDelete($id) { $selectResult = CMailbox::getList(array(), array('USER_ID' => intval($id))); while ($mailbox = $selectResult->fetch()) { CMailbox::delete($mailbox['ID']); } }
private static function executeManageDeleteMailbox(&$error) { $error = false; $userId = $_REQUEST['USER_ID']; if (!check_bitrix_sessid()) { $error = GetMessage('INTR_MAIL_CSRF'); } if ($error === false) { $mailbox = CIntranetMailSetupHelper::getUserMailbox($userId); if (empty($mailbox) || !in_array($mailbox['SERVER_TYPE'], array('controller', 'domain', 'crdomain'))) { $error = GetMessage('INTR_MAIL_AJAX_ERROR'); } } if ($error === false) { CMailbox::delete($mailbox['ID']); list($login, $domain) = explode('@', $mailbox['LOGIN'], 2); if ($mailbox['SERVER_TYPE'] == 'domain') { $domainService = CIntranetMailSetupHelper::getDomainService($mailbox['SERVICE_ID']); CMailDomain2::deleteUser($domainService['token'], $domain, $login); } else { if ($mailbox['SERVER_TYPE'] == 'crdomain') { $crResponse = CControllerClient::ExecuteEvent('OnMailControllerDeleteMemberUser', array('DOMAIN' => $domain, 'NAME' => $login)); if (!isset($crResponse['result'])) { $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']); } } else { if ($mailbox['SERVER_TYPE'] == 'controller') { $crResponse = CControllerClient::ExecuteEvent('OnMailControllerDeleteUser', array('DOMAIN' => $domain, 'NAME' => $login)); if (!isset($crResponse['result'])) { $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']); } } } } CUserCounter::Clear($userId, 'mail_unseen', $mailbox['LID']); CUserOptions::DeleteOption('global', 'last_mail_check_' . $mailbox['LID']); CUserOptions::DeleteOption('global', 'last_mail_check_success_' . $mailbox['LID']); } if ($error === false) { $create = '<a href="#" onclick="mb.create(' . intval($userId) . '); return false; ">' . GetMessage('INTR_MAIL_MANAGE_CREATE') . '</a>'; } return array('result' => $error === false ? 'ok' : 'error', 'create' => isset($create) ? CharsetConverter::ConvertCharset($create, SITE_CHARSET, 'UTF-8') : '', 'error' => CharsetConverter::ConvertCharset($error, SITE_CHARSET, 'UTF-8')); }
public static function createMailbox($exists, $userId, $serviceId, $domain, $login, $password, &$error) { $error = false; if (intval($userId)) { $dbUser = CUser::getList($by = 'ID', $order = 'ASC', array('ID_EQUAL_EXACT' => intval($userId)), array('FIELDS' => 'ID')); if (!$dbUser->fetch()) { $error = GetMessage('INTR_MAIL_FORM_ERROR'); } } if ($error === false) { $services = self::getMailServices(); if (empty($services[$serviceId]) || !in_array($services[$serviceId]['type'], array('controller', 'domain', 'crdomain'))) { $error = GetMessage('INTR_MAIL_FORM_ERROR'); } } if ($error === false) { $service = $services[$serviceId]; if ($service['type'] == 'controller') { $crDomains = CControllerClient::ExecuteEvent('OnMailControllerGetDomains', array()); $arDomains = empty($crDomains['result']) ? array() : $crDomains['result']; if (!is_array($arDomains) || !in_array($domain, $arDomains)) { $error = CMail::getErrorMessage(CMail::ERR_API_OP_DENIED); } } else { if ($service['type'] == 'crdomain') { $crDomains = CControllerClient::ExecuteEvent('OnMailControllerGetMemberDomains', array()); $arDomains = empty($crDomains['result']) ? array() : $crDomains['result']; if (!is_array($arDomains) || !in_array($domain, $arDomains)) { $error = CMail::getErrorMessage(CMail::ERR_API_OP_DENIED); } } else { if ($service['type'] == 'domain') { if ($service['server'] != $domain) { $error = GetMessage('INTR_MAIL_FORM_ERROR'); } } } } } if ($error === false && !$exists) { if (!preg_match('/^[a-z0-9_]+(\\.?[a-z0-9_-]*[a-z0-9_]+)*?$/i', $login)) { $error = CMail::getErrorMessage(CMail::ERR_API_BAD_NAME); } if ($error === false) { if ($service['type'] == 'controller') { $crResponse = CControllerClient::ExecuteEvent('OnMailControllerAddUser', array('DOMAIN' => $domain, 'NAME' => $login, 'PASSWORD' => $password)); if (!isset($crResponse['result'])) { $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']); } } else { if ($service['type'] == 'crdomain') { $crResponse = CControllerClient::ExecuteEvent('OnMailControllerAddMemberUser', array('DOMAIN' => $domain, 'NAME' => $login, 'PASSWORD' => $password)); if (!isset($crResponse['result'])) { $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']); } } else { if ($service['type'] == 'domain') { $result = CMailDomain2::addUser($service['token'], $domain, $login, $password, $error); if (is_null($result)) { $error = CMail::getErrorMessage($error); } } } } } } if ($error === false && intval($userId)) { if ($exists) { if ($service['type'] == 'controller') { $crCheckMailbox = CControllerClient::ExecuteEvent('OnMailControllerCheckMailbox', array('DOMAIN' => $domain, 'NAME' => $login)); if (!isset($crCheckMailbox['result'])) { $error = empty($crCheckMailbox['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crCheckMailbox['error']); } } if ($error === false) { $dbMailbox = CMailbox::getList(array('TIMESTAMP_X' => 'ASC'), array('ACTIVE' => 'Y', '!USER_ID' => intval($userId), '=LOGIN' => $login . '@' . $domain)); if (($mailbox = $dbMailbox->fetch()) && $mailbox['USER_ID']) { $error = GetMessage('INTR_MAIL_MAILBOX_OCCUPIED'); } } } if ($error === false) { $mailbox = self::getUserMailbox($userId); if (!empty($mailbox)) { $res = CMailbox::delete($mailbox['ID']); } $arFields = array('LID' => SITE_ID, 'ACTIVE' => 'Y', 'SERVICE_ID' => $serviceId, 'NAME' => $service['name'], 'LOGIN' => $login . '@' . $domain, 'SERVER_TYPE' => $service['type'], 'USER_ID' => intval($userId)); $res = CMailbox::add($arFields); if (!$res) { $error = GetMessage('INTR_MAIL_SAVE_ERROR'); } } } if ($error === false) { return $login . '@' . $domain; } }