Ejemplo n.º 1
0
 case 'imap':
     $unseen = CMailUtil::CheckImapMailbox($acc['SERVER'], $acc['PORT'], $acc['USE_TLS'], $acc['LOGIN'], $acc['PASSWORD'], $error, 30);
     break;
 case 'controller':
     list($acc['login'], $acc['domain']) = explode('@', $acc['LOGIN'], 2);
     $crCheckMailbox = CControllerClient::ExecuteEvent('OnMailControllerCheckMailbox', array('DOMAIN' => $acc['domain'], 'NAME' => $acc['login']));
     if (isset($crCheckMailbox['result'])) {
         $unseen = intval($crCheckMailbox['result']);
     } else {
         $unseen = -1;
         $error = empty($crCheckMailbox['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crCheckMailbox['error']);
     }
     break;
 case 'crdomain':
     list($acc['login'], $acc['domain']) = explode('@', $acc['LOGIN'], 2);
     $crCheckMailbox = CControllerClient::ExecuteEvent('OnMailControllerCheckMemberMailbox', array('DOMAIN' => $acc['domain'], 'NAME' => $acc['login']));
     if (isset($crCheckMailbox['result'])) {
         $unseen = intval($crCheckMailbox['result']);
     } else {
         $unseen = -1;
         $error = empty($crCheckMailbox['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crCheckMailbox['error']);
     }
     break;
 case 'domain':
     $service = \Bitrix\Mail\MailServicesTable::getRowById($acc['SERVICE_ID']);
     list($acc['login'], $acc['domain']) = explode('@', $acc['LOGIN'], 2);
     $result = CMailDomain2::getUnreadMessagesCount($service['TOKEN'], $acc['domain'], $acc['login'], $error);
     if (is_null($result)) {
         $unseen = -1;
         $error = CMail::getErrorMessage($error);
     } else {
Ejemplo n.º 2
0
             }
         }
         if (!$bDomainUsersExist && !empty($arMailServices[$arService['ID']]['users'])) {
             $bConnectDomainsExist = true;
             $bDomainUsersExist = true;
         }
     }
 } else {
     if ($arService['SERVICE_TYPE'] == 'crdomain') {
         $crDomains = CControllerClient::ExecuteEvent('OnMailControllerGetMemberDomains', array());
         if (!empty($crDomains['result']) && is_array($crDomains['result'])) {
             $arMailServices[$arService['ID']]['domains'] = $crDomains['result'];
             $bCreateDomainsExist = true;
         }
         $arMailServices[$arService['ID']]['users'] = array();
         $crUsers = CControllerClient::ExecuteEvent('OnMailControllerGetMemberUsers', array('DOMAIN' => $arService['SERVER']));
         if (!empty($crUsers['result']) && is_array($crUsers['result'])) {
             foreach ($crUsers['result'] as $login) {
                 if (empty($arMailServices[$arService['ID']]['users'][$arService['SERVER']])) {
                     $arMailServices[$arService['ID']]['users'][$arService['SERVER']] = array();
                 }
                 $arMailServices[$arService['ID']]['users'][$arService['SERVER']][] = $login;
             }
             $rsMailbox = CMailbox::getList(array('TIMESTAMP_X' => 'ASC'), array('ACTIVE' => 'Y', '!USER_ID' => 0, 'SERVICE_ID' => $arMailServices[$arService['ID']]['id']));
             while ($arMailbox = $rsMailbox->Fetch()) {
                 list($login, $domain) = explode('@', $arMailbox['LOGIN'], 2);
                 if (!empty($arMailServices[$arService['ID']]['users'][$domain]) && ($key = array_search($login, $arMailServices[$arService['ID']]['users'][$domain])) !== false) {
                     array_splice($arMailServices[$arService['ID']]['users'][$domain], $key, 1);
                 }
             }
             if (is_array($arMailServices[$arService['ID']]['users'])) {
Ejemplo n.º 3
0
 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'));
 }
Ejemplo n.º 4
0
 private static function checkDomainStatus($settings, &$error)
 {
     if ($settings['type'] == 'domain') {
         $result = CMailDomain2::getDomainStatus($settings['token'], $settings['domain'], $error);
         if (is_null($result)) {
             $error = CMail::getErrorMessage($error);
         } else {
             if (!isset($result['stage']) || !in_array($result['stage'], array('owner-check', 'mx-check', 'added'))) {
                 $error = CMail::getErrorMessage(CMail::ERR_API_DENIED);
             }
         }
     } else {
         if ($settings['type'] == 'crdomain') {
             $result = null;
             $crResponse = CControllerClient::ExecuteEvent('OnMailControllerCheckMemberDomain', array('DOMAIN' => $settings['domain']));
             if (!isset($crResponse['result'])) {
                 $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']);
             } else {
                 $result = $crResponse['result'];
                 if (!is_array($result)) {
                     $error = GetMessage('INTR_MAIL_CONTROLLER_INVALID');
                 } else {
                     if (!isset($result['stage']) || !in_array($result['stage'], array('owner-check', 'mx-check', 'added'))) {
                         $error = GetMessage('INTR_MAIL_CONTROLLER_INVALID');
                     } else {
                         if ($result['stage'] == 'owner-check' && (!isset($result['secrets']['name']) || !isset($result['secrets']['content']))) {
                             $error = GetMessage('INTR_MAIL_CONTROLLER_INVALID');
                         }
                     }
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 5
0
 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;
     }
 }