- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/mail/sender.php
- Класс: BitrixMainMailSender
- Вызов: Sender::setEmailLimit
static function setEmailLimit(string $email, int $limit, bool $quite = true): bool
{
$address = new BitrixMainMailAddress($email);
if (!$address->validate())
{
return false;
}
$email = $address->getEmail();
$cache = new CPHPCache();
$cache->clean($email, '/main/mail/limit');
$res = InternalSenderTable::getList(array(
'filter' => array(
'IS_CONFIRMED' => true,
'=EMAIL' => $email,
),
'order' => array(
'ID' => 'DESC',
),
));
if ($limit < 0)
{
$limit = 0;
}
$hasChanges = false;
while ($item = $res->fetch())
{
$oldLimit = (int)($item['OPTIONS']['smtp']['limit'] ?? 0);
if ($item['OPTIONS']['smtp'] && $limit !== $oldLimit)
{
$item['OPTIONS']['smtp']['limit'] = $limit;
$updateResult = InternalSenderTable::update($item['ID'], ['OPTIONS' => $item['OPTIONS']]);
$hasChanges = true;
if (!$quite && $limit < $oldLimit && $updateResult->isSuccess())
{
$event = new Event('main', self::MAIN_SENDER_SMTP_LIMIT_DECREASE, ['EMAIL'=>$email]);
$event->send();
}
}
}
return $hasChanges;
}