17 private const MAILBOX_IS_LOCKED_PROPERTY = 1;
18 private const MAILBOX_IS_AVAILABLE_PROPERTY = 0;
24 if ($maxCountAvailableMailboxes < 0)
29 static $checkedMailboxes = [];
31 if (!array_key_exists($checkedMailboxId, $checkedMailboxes))
33 $checkedMailboxes[$checkedMailboxId] = MailboxTable::getById($checkedMailboxId)->fetch();
36 $mailboxAvailabilitySyncStatus =
false;
38 if ($checkedMailboxes[$checkedMailboxId] && isset($checkedMailboxes[$checkedMailboxId][
'USER_ID']))
40 $userId = (int) $checkedMailboxes[$checkedMailboxId][
'USER_ID'];
42 static $userMailboxes = [];
44 if (!array_key_exists($userId, $userMailboxes))
46 $userMailboxes[$userId] = MailboxTable::getList([
51 '=USER_ID' => $userId,
62 foreach ($userMailboxes[$userId] as $mailbox)
64 if (isset($mailbox[
'ID']))
66 $mailboxId = (int) $mailbox[
'ID'];
67 if ($mailboxNumber <= $maxCountAvailableMailboxes)
69 if ($mailboxId === $checkedMailboxId)
71 $mailboxAvailabilitySyncStatus =
true;
74 static::removeTariffRestrictionsOnTheMailbox($mailboxId);
78 static::imposeTariffRestrictionsOnTheMailbox($mailboxId);
86 return $mailboxAvailabilitySyncStatus;
89 private static function getMailboxTariffRestrictions($mailboxId, $overwriteCache =
false): int
91 static $mailboxesRestriction = [];
93 if ($overwriteCache || !array_key_exists($mailboxId, $mailboxesRestriction))
96 '=MAILBOX_ID' => $mailboxId,
97 '=ENTITY_TYPE' =>
'MAILBOX',
98 '=ENTITY_ID' => $mailboxId,
99 '=PROPERTY_NAME' =>
'TARIFF_RESTRICTIONS',
102 $restriction = MailEntityOptionsTable::getList([
110 if (isset($restriction[
'VALUE']))
112 $mailboxesRestriction[$mailboxId] = (int) $restriction[
'VALUE'];
116 $mailboxesRestriction[$mailboxId] = 0;
120 return $mailboxesRestriction[$mailboxId];
123 private static function removeTariffRestrictionsOnTheMailbox($mailboxId): void
125 if (static::getMailboxTariffRestrictions($mailboxId) !== static::MAILBOX_IS_AVAILABLE_PROPERTY)
127 static::setTheOptionOfTariffRestrictions($mailboxId, static::MAILBOX_IS_AVAILABLE_PROPERTY);
128 static::getMailboxTariffRestrictions($mailboxId,
true);
132 private static function imposeTariffRestrictionsOnTheMailbox($mailboxId): void
134 if (static::getMailboxTariffRestrictions($mailboxId) !== static::MAILBOX_IS_LOCKED_PROPERTY)
138 'imposed_tariff_restrictions_on_the_mailbox',
143 static::setTheOptionOfTariffRestrictions($mailboxId, static::MAILBOX_IS_LOCKED_PROPERTY);
144 static::getMailboxTariffRestrictions($mailboxId,
true);
148 private static function setTheOptionOfTariffRestrictions($mailboxId, $optionValue): void
151 '=MAILBOX_ID' => $mailboxId,
152 '=ENTITY_TYPE' =>
'MAILBOX',
153 '=ENTITY_ID' => $mailboxId,
154 '=PROPERTY_NAME' =>
'TARIFF_RESTRICTIONS',
158 'MAILBOX_ID' => $mailboxId,
159 'ENTITY_TYPE' =>
'MAILBOX',
160 'ENTITY_ID' => $mailboxId,
161 'PROPERTY_NAME' =>
'TARIFF_RESTRICTIONS',
166 $fields[
'DATE_INSERT'] =
new Main\Type\DateTime();
167 $fields[
'VALUE'] = $optionValue;
169 if (MailEntityOptionsTable::getCount($filter))
171 MailEntityOptionsTable::update(
174 'VALUE' => $optionValue,
175 'DATE_INSERT' =>
new Main\
Type\DateTime(),
181 MailEntityOptionsTable::add(
189 if (Main\Loader::includeModule(
'crm') && Main\Loader::includeModule(
'im'))
193 \CIMSettings::CLIENT_SITE,
194 \CIMSettings::CLIENT_MAIL,
195 \CIMSettings::CLIENT_PUSH,
200 \CIMSettings::GetNotifyAccess(
203 \CCrmNotifierSchemeType::IncomingEmailName,
216 private static function getCountSenders(
int $userId = 0)
220 if (!($userId > 0 || (is_object($USER) && $USER->isAuthorized())))
227 $userId = $USER->getId();
231 return SenderTable::getCount([
232 'IS_CONFIRMED' =>
true,
235 '=USER_ID' => $userId,
245 if (!($userId > 0 || (is_object($USER) && $USER->isAuthorized())))
252 $userId = $USER->getId();
256 self::isSyncAvailable()
258 && self::checkUserHasNotExceededTheConnectedMailboxesLimit($userId)
271 if (!($userId > 0 || (is_object($USER) && $USER->isAuthorized())))
278 $userId = $USER->getId();
284 $userMailboxesLimit >= 0
301 if (!Main\Loader::includeModule(
'bitrix24'))
306 return (
bool) Bitrix24\Feature::isFeatureEnabled(
'mail_mailbox_sync');
311 if (!Main\Loader::includeModule(
'bitrix24'))
316 return (
int) Bitrix24\Feature::getVariable(
'mail_shared_mailboxes_limit');
326 if (!Main\Loader::includeModule(
'bitrix24'))
331 if (!static::isSyncAvailable())
336 return (
int) Bitrix24\Feature::getVariable(
'mail_user_mailboxes_limit');
341 if (Main\Loader::includeModule(
'bitrix24') && (!static::isSyncAvailable() || \CBitrix24::IsDemoLicense()))
356 if (!Main\Loader::includeModule(
'bitrix24'))
358 return (
int) Main\Config\Option::get(
'mail',
'sync_old_limit2', -1);
361 return (
int) Bitrix24\Feature::getVariable(
'mail_sync_old_limit');
371 return static::getSyncOldLimit() > 0;