Example #1
0
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php';
if (!is_object($USER) || !$USER->IsAuthorized()) {
    return;
}
$userId = $USER->GetID();
session_write_close();
CModule::IncludeModule('mail');
$siteId = isset($_REQUEST['SITE_ID']) ? $_REQUEST['SITE_ID'] : SITE_ID;
$error = false;
$dbAcc = CMailbox::GetList(array('TIMESTAMP_X' => 'DESC'), array('LID' => SITE_ID, 'ACTIVE' => 'Y', 'USER_ID' => $USER->GetID()));
while (($acc = $dbAcc->fetch()) !== false && !in_array($acc['SERVER_TYPE'], array('imap', 'controller', 'domain', 'crdomain'))) {
}
if (!empty($acc)) {
    switch ($acc['SERVER_TYPE']) {
        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'])) {
Example #2
0
 foreach ($arParams['OPTIONS'] as $option) {
     if (empty($arResult['SETTINGS'][$option])) {
         unset($error);
         $arResult['SETTINGS'][$option] = isset($_REQUEST[$option]) ? $_REQUEST[$option] : null;
         $arResult['SETTINGS'][$option] = CheckOption($option, $arResult['SETTINGS'][$option], $error);
         if (!empty($error)) {
             $arResult['ERRORS'][] = $error;
         }
     }
 }
 if (!check_bitrix_sessid()) {
     $arResult['ERRORS'][] = GetMessage('INTR_MAIL_CSRF');
 }
 if (empty($arResult['ERRORS'])) {
     $error = false;
     $unseen = CMailUtil::CheckImapMailbox($arResult['SETTINGS']['server'], $arResult['SETTINGS']['port'], $arResult['SETTINGS']['encryption'], $arResult['SETTINGS']['login'], $arResult['SETTINGS']['password'], $error, 30);
     if ($error !== false) {
         $arResult['ERRORS'][] = $error;
     }
 }
 if (empty($arResult['ERRORS'])) {
     $arFields = array('LID' => SITE_ID, 'ACTIVE' => 'Y', 'SERVICE_ID' => $arResult['SERVICE'], 'NAME' => $arResult['SETTINGS']['name'], 'SERVER' => $arResult['SETTINGS']['server'], 'PORT' => $arResult['SETTINGS']['port'], 'LINK' => $arResult['SETTINGS']['link'], 'LOGIN' => $arResult['SETTINGS']['login'], 'PASSWORD' => $arResult['SETTINGS']['password'], 'USE_TLS' => $arResult['SETTINGS']['encryption'] == 'Y' ? 'Y' : 'N', 'SERVER_TYPE' => 'imap', 'USER_ID' => $USER->GetID());
     if (!empty($arResult['ID'])) {
         $res = CMailbox::Update($arResult['ID'], $arFields);
     } else {
         $arResult['ID'] = CMailbox::Add($arFields);
         $res = $arResult['ID'] > 0;
     }
     if (!$res) {
         $arResult['ERRORS'][] = GetMessage('INTR_MAIL_SAVE_ERROR');
     } else {
Example #3
0
 private static function executeChangePassword(&$error)
 {
     global $USER;
     $error = false;
     $password = $_REQUEST['password'];
     $password2 = $_REQUEST['password2'];
     if (!check_bitrix_sessid()) {
         $error = GetMessage('INTR_MAIL_CSRF');
     }
     if ($error === false) {
         $mailbox = CIntranetMailSetupHelper::getUserMailbox($USER->GetID());
         if (empty($mailbox) || !in_array($mailbox['SERVER_TYPE'], array('controller', 'domain', 'crdomain', 'imap'))) {
             $error = GetMessage('INTR_MAIL_FORM_ERROR');
         }
     }
     if ($error === false) {
         if ($mailbox['ID'] != $_REQUEST['ID']) {
             $error = GetMessage('INTR_MAIL_FORM_ERROR');
         }
     }
     if ($error === false) {
         if (in_array($mailbox['SERVER_TYPE'], array('controller', 'domain', 'crdomain')) && $password != $password2) {
             $error = GetMessage('INTR_MAIL_INP_PASSWORD2_BAD');
         }
     }
     if ($error === false) {
         if ($mailbox['SERVER_TYPE'] == 'crdomain') {
             list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
             $crResponse = CControllerClient::ExecuteEvent('OnMailControllerChangeMemberPassword', 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 ($mailbox['SERVER_TYPE'] == 'domain') {
                 $domainService = CIntranetMailSetupHelper::getDomainService($mailbox['SERVICE_ID']);
                 list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
                 $result = CMailDomain2::changePassword($domainService['token'], $domain, $login, $password, $error);
                 if (is_null($result)) {
                     $error = CMail::getErrorMessage($error);
                 }
             } else {
                 if ($mailbox['SERVER_TYPE'] == 'controller') {
                     list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
                     $crResponse = CControllerClient::ExecuteEvent('OnMailControllerChangePassword', 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 ($mailbox['SERVER_TYPE'] == 'imap') {
                         $unseen = CMailUtil::CheckImapMailbox($mailbox['SERVER'], $mailbox['PORT'], $mailbox['USE_TLS'], $mailbox['LOGIN'], $password, $error, 30);
                         if ($error === false) {
                             $res = CMailbox::update($mailbox['ID'], array('PASSWORD' => $password));
                             if (!$res) {
                                 $error = GetMessage('INTR_MAIL_SAVE_ERROR');
                             }
                         }
                     }
                 }
             }
         }
     }
     return array('result' => $error === false ? 'ok' : 'error', 'error' => CharsetConverter::ConvertCharset($error, SITE_CHARSET, 'UTF-8'));
 }