Esempio n. 1
0
            }
            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 {
                $unseen = intval($result);
            }
            break;
    }
    CUserCounter::Set($userId, 'mail_unseen', $unseen, $siteId);
    CUserOptions::SetOption('global', 'last_mail_check_' . $siteId, time(), false, $userId);
    CUserOptions::SetOption('global', 'last_mail_check_success_' . $siteId, $unseen >= 0, false, $userId);
} else {
    $unseen = 0;
    CUserOptions::SetOption('global', 'last_mail_check_' . $siteId, -1, false, $userId);
}
Esempio n. 2
0
 private static function executeCheck(&$error)
 {
     global $USER;
     $error = false;
     $unseen = -1;
     if (!check_bitrix_sessid()) {
         $error = GetMessage('INTR_MAIL_CSRF');
     }
     if ($error === false) {
         $mailbox = CIntranetMailSetupHelper::getUserMailbox($USER->GetID());
         if (empty($mailbox)) {
             $error = GetMessage('INTR_MAIL_AJAX_ERROR');
         }
     }
     if ($error === false) {
         switch ($mailbox['SERVER_TYPE']) {
             case 'imap':
                 $unseen = CMailUtil::CheckImapMailbox($mailbox['SERVER'], $mailbox['PORT'], $mailbox['USE_TLS'], $mailbox['LOGIN'], $mailbox['PASSWORD'], $error, 30);
                 break;
             case 'controller':
                 list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
                 $crCheckMailbox = CControllerClient::ExecuteEvent('OnMailControllerCheckMailbox', array('DOMAIN' => $domain, 'NAME' => $login));
                 if (isset($crCheckMailbox['result'])) {
                     $unseen = intval($crCheckMailbox['result']);
                 } else {
                     $error = empty($crCheckMailbox['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crCheckMailbox['error']);
                 }
                 break;
             case 'crdomain':
                 list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
                 $crCheckMailbox = CControllerClient::ExecuteEvent('OnMailControllerCheckMemberMailbox', array('DOMAIN' => $domain, 'NAME' => $login));
                 if (isset($crCheckMailbox['result'])) {
                     $unseen = intval($crCheckMailbox['result']);
                 } else {
                     $error = empty($crCheckMailbox['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crCheckMailbox['error']);
                 }
                 break;
             case 'domain':
                 $serviceId = $mailbox['SERVICE_ID'];
                 $services = CIntranetMailSetupHelper::getMailServices();
                 list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
                 $result = CMailDomain2::getUnreadMessagesCount($services[$serviceId]['token'], $domain, $login, $error);
                 if (is_null($result)) {
                     $error = CMail::getErrorMessage($error);
                 } else {
                     $unseen = intval($result);
                 }
                 break;
         }
         CUserCounter::Set($USER->GetID(), 'mail_unseen', $unseen, SITE_ID);
         CUserOptions::SetOption('global', 'last_mail_check_' . SITE_ID, time());
         CUserOptions::SetOption('global', 'last_mail_check_success_' . SITE_ID, $unseen >= 0);
     }
     return array('unseen' => $unseen);
 }