11 $defSiteID = CSite::GetDefSite();
14 $arGroupNotify =
array();
15 $arGroupNotifyUser =
array();
16 $arUnsendNotify = CIMNotify::GetUnsendNotify();
17 $attachList = self::getAttachList(array_keys($arUnsendNotify));
20 foreach($arUnsendNotify as $id => $arNotify)
22 $maxId = ((int)$id > $maxId) ? (
int)$id : $maxId;
23 if (!isset($arMark[$arNotify[
"CHAT_ID"]]) || $arMark[$arNotify[
"CHAT_ID"]] < $arNotify[
"ID"])
24 $arMark[$arNotify[
"CHAT_ID"]] = $arNotify[
"ID"];
26 if ($arNotify[
'TO_EXTERNAL_AUTH_ID'] == \
Bitrix\Im\Bot::EXTERNAL_AUTH_ID || $arNotify[
'TO_EXTERNAL_AUTH_ID'] ==
"network")
28 unset($arUnsendNotify[$id]);
32 if ($arNotify[
'TO_USER_ACTIVE'] !=
'Y')
34 unset($arUnsendNotify[$id]);
38 if (isset($arNotify[
"NOTIFY_MODULE"]) && isset($arNotify[
"NOTIFY_EVENT"])
41 unset($arUnsendNotify[$id]);
47 unset($arUnsendNotify[$id]);
51 if (!$arNotify[
"TO_USER_LID"] || $arNotify[
"TO_USER_LID"] ==
'')
53 $arNotify[
"TO_USER_LID"] = $defSiteID;
54 if (!$arNotify[
"TO_USER_LID"] || $arNotify[
"TO_USER_LID"] ==
'')
56 unset($arUnsendNotify[$id]);
60 if ($arNotify[
"MESSAGE_OUT"] ==
'')
62 $arNotify[
"MESSAGE_OUT"] = self::getMessageTextWithAttach($arNotify[
"MESSAGE"], $attachList[$arNotify[
'ID']] ??
null);
66 if (!(isset($arNotify[
"EMAIL_TEMPLATE"]) && $arNotify[
"EMAIL_TEMPLATE"] <>
''))
67 $arNotify[
"EMAIL_TEMPLATE"] =
"IM_NEW_NOTIFY";
70 "NAME" => $arNotify[
"TO_USER_NAME"],
71 "LAST_NAME" => $arNotify[
"TO_USER_LAST_NAME"],
72 "SECOND_NAME" => $arNotify[
"TO_USER_SECOND_NAME"],
73 "LOGIN" => $arNotify[
"TO_USER_LOGIN"],
74 "EXTERNAL_AUTH_ID" => $arNotify[
"TO_EXTERNAL_AUTH_ID"]
77 if ($arNotify[
"FROM_USER_ID"] == 0)
79 $arNotify[
"FROM_USER"] =
GetMessage(
'IM_MAIL_USER_SYSTEM');
84 "NAME" => $arNotify[
"FROM_USER_NAME"],
85 "LAST_NAME" => $arNotify[
"FROM_USER_LAST_NAME"],
86 "SECOND_NAME" => $arNotify[
"FROM_USER_SECOND_NAME"],
87 "LOGIN" => $arNotify[
"FROM_USER_LOGIN"],
88 "EXTERNAL_AUTH_ID" => $arNotify[
"FROM_EXTERNAL_AUTH_ID"]
92 $arNotify[
'NOTIFY_TAG_MD5'] = md5($arNotify[
"TO_USER_ID"].
'|'.$arNotify[
'NOTIFY_TAG']);
93 $arUnsendNotify[$id] = $arNotify;
94 if ($arNotify[
"EMAIL_TEMPLATE"] ==
"IM_NEW_NOTIFY" && $arNotify[
'NOTIFY_TAG'] !=
'')
96 if (isset($arGroupNotify[$arNotify[
'NOTIFY_TAG_MD5']]))
98 $arGroupNotifyUser[$arNotify[
'NOTIFY_TAG_MD5']][$arNotify[
"FROM_USER_ID"]] = $arNotify[
"FROM_USER"];
99 unset($arUnsendNotify[$id]);
103 $arGroupNotifyUser[$arNotify[
'NOTIFY_TAG_MD5']][$arNotify[
"FROM_USER_ID"]] = $arNotify[
"FROM_USER"];
104 $arGroupNotify[$arNotify[
'NOTIFY_TAG_MD5']] =
true;
115 foreach($arUnsendNotify as $id => $arNotify)
117 $message = $CTP->convert4mail(str_replace(
"#BR#",
"\n", strip_tags($arNotify[
"MESSAGE_OUT"])));
118 $messageShort = str_replace(
array(
"<br>",
"<br/>",
"<br />",
"#BR#"), Array(
" ",
" ",
" ",
" "), nl2br($CTP->convert4mail(strip_tags($arNotify[
"MESSAGE_OUT"]))));
120 $messageShort = $CTP->html_cut(\
Bitrix\Im\Text::removeBbCodes($messageShort), 50);
121 $title = trim($arNotify[
"NOTIFY_TITLE"] ??
'');
127 "MESSAGE_ID" => $arNotify[
"ID"],
128 "USER" => $arNotify[
"USER"],
129 "USER_ID" => $arNotify[
"TO_USER_ID"],
130 "USER_LOGIN" => $arNotify[
"TO_USER_LOGIN"],
131 "USER_NAME" => $arNotify[
"TO_USER_NAME"],
132 "USER_LAST_NAME" => $arNotify[
"TO_USER_LAST_NAME"],
133 "USER_SECOND_NAME" => $arNotify[
"TO_USER_SECOND_NAME"],
134 "DATE_CREATE" =>
FormatDate(
"FULL", $arNotify[
"DATE_CREATE"]),
135 "FROM_USER_ID" => $arNotify[
"FROM_USER_ID"],
136 "FROM_USER_LOGIN" => $arNotify[
"FROM_USER_LOGIN"],
137 "FROM_USER" => $arNotify[
"FROM_USER"],
138 "SENDER_ID" => $arNotify[
"FROM_USER_ID"],
139 "SENDER_LOGIN" => $arNotify[
"FROM_USER_LOGIN"],
140 "SENDER_NAME" => $arNotify[
"FROM_USER_NAME"],
141 "SENDER_LAST_NAME" => $arNotify[
"FROM_USER_LAST_NAME"],
142 "SENDER_SECOND_NAME" => $arNotify[
"FROM_USER_SECOND_NAME"],
143 "EMAIL_TO" => $arNotify[
"TO_USER_EMAIL"],
146 "MESSAGE_50" => $messageShort,
154 if (isset($arGroupNotifyUser[$arNotify[
'NOTIFY_TAG_MD5']]) &&
count($arGroupNotifyUser[$arNotify[
'NOTIFY_TAG_MD5']]) > 1)
156 $arNotify[
"EMAIL_TEMPLATE"] =
"IM_NEW_NOTIFY_GROUP";
157 $arFields[
'FROM_USERS'] = implode(
', ', $arGroupNotifyUser[$arNotify[
'NOTIFY_TAG_MD5']]);
162 $event->Send($arNotify[
"EMAIL_TEMPLATE"], $arNotify[
"TO_USER_LID"],
$arFields,
"N");
165 return __METHOD__.
'();';
170 $defSiteID = CSite::GetDefSite();
174 $attachList = self::getAttachList(array_keys($arUnsendMessage));
177 $arFromUser = Array();
182 foreach($arUnsendMessage as $id => $arMessage)
184 $maxId = ((int)$id > $maxId) ? (
int)$id : $maxId;
185 if (!isset($arMark[$arMessage[
"TO_USER_ID"]][$arMessage[
"CHAT_ID"]]) || $arMark[$arMessage[
"TO_USER_ID"]][$arMessage[
"CHAT_ID"]] < $arMessage[
"ID"])
186 $arMark[$arMessage[
"TO_USER_ID"]][$arMessage[
"CHAT_ID"]] = $arMessage[
"ID"];
188 if ($arMessage[
'TO_EXTERNAL_AUTH_ID'] == \
Bitrix\Im\Bot::EXTERNAL_AUTH_ID || $arMessage[
'TO_EXTERNAL_AUTH_ID'] ==
"network")
190 unset($arUnsendMessage[$id]);
194 if ($arMessage[
'TO_USER_ACTIVE'] !=
'Y')
196 unset($arUnsendMessage[$id]);
202 unset($arUnsendMessage[$id]);
208 unset($arUnsendMessage[$id]);
212 if ($arMessage[
"MESSAGE_OUT"] ==
'')
214 $arMessage[
"MESSAGE_OUT"] = self::getMessageTextWithAttach($arMessage[
"MESSAGE"], $attachList[$arMessage[
'ID']] ??
null);
217 if (!isset($arToUser[$arMessage[
"TO_USER_ID"]]))
219 $siteID = $arMessage[
"TO_USER_LID"];
228 "NAME" => $arMessage[
"TO_USER_NAME"],
229 "LAST_NAME" => $arMessage[
"TO_USER_LAST_NAME"],
230 "SECOND_NAME" => $arMessage[
"TO_USER_SECOND_NAME"] ??
null,
231 "LOGIN" => $arMessage[
"TO_USER_LOGIN"],
232 "EXTERNAL_AUTH_ID" => $arMessage[
"TO_EXTERNAL_AUTH_ID"],
235 $arToUser[$arMessage[
"TO_USER_ID"]] = Array(
236 "USER" => $arMessage[
'USER'] ??
null,
237 "USER_ID" => $arMessage[
"TO_USER_ID"],
238 "USER_LOGIN" => $arMessage[
"TO_USER_LOGIN"],
239 "USER_NAME" => $arMessage[
"TO_USER_NAME"],
240 "USER_LAST_NAME" => $arMessage[
"TO_USER_LAST_NAME"],
241 "USER_SECOND_NAME" => $arMessage[
"TO_USER_SECOND_NAME"] ??
null,
243 "EMAIL_TO" => $arMessage[
"TO_USER_EMAIL"],
246 if (!isset($arFromUser[$arMessage[
"FROM_USER_ID"]]))
248 if ($arMessage[
"FROM_USER_ID"] == 0)
250 $arMessage[
"FROM_USER"] =
GetMessage(
'IM_MAIL_USER_SYSTEM');
255 "NAME" => $arMessage[
"FROM_USER_NAME"],
256 "LAST_NAME" => $arMessage[
"FROM_USER_LAST_NAME"],
257 "SECOND_NAME" => $arMessage[
"FROM_USER_SECOND_NAME"] ??
null,
258 "LOGIN" => $arMessage[
"FROM_USER_LOGIN"],
259 "EXTERNAL_AUTH_ID" => $arMessage[
"FROM_EXTERNAL_AUTH_ID"],
263 $arFromUser[$arMessage[
"FROM_USER_ID"]] = Array(
264 "FROM_USER" => $arMessage[
"FROM_USER"],
265 "FROM_USER_ID" => $arMessage[
"FROM_USER_ID"],
266 "FROM_USER_LOGIN" => $arMessage[
"FROM_USER_LOGIN"],
267 "FROM_USER_NAME" => $arMessage[
"FROM_USER_NAME"],
268 "FROM_USER_LAST_NAME" => $arMessage[
"FROM_USER_LAST_NAME"],
269 "FROM_USER_SECOND_NAME" => $arMessage[
"FROM_USER_SECOND_NAME"] ??
null,
273 $message = $parser->convert4mail(str_replace(
"#BR#",
"\n", strip_tags($arMessage[
"MESSAGE_OUT"])));
275 $arDialog[$arMessage[
"TO_USER_ID"]][$arMessage[
"FROM_USER_ID"]][] = Array(
276 'DATE_CREATE' =>
FormatDate(
"FULL", $arMessage[
"DATE_CREATE"]),
286 foreach ($arToUser as $toID=> $arToInfo)
289 $messagesFromUsers =
array();
293 $bFirstMessage =
true;
294 foreach ($arDialog[$toID] as $fromID => $arMessages)
296 $fromIdUserMessages =
"";
299 $bFirstMessage =
false;
303 if (
count($arDialog[$toID])>1)
305 $message .=
GetMessage(
'IM_MAIL_TEMPLATE_NEW_MESSAGE_HEADER', Array(
'#FROM_USER#' => $arFromUser[$fromID][
'FROM_USER'])).
"\n";
308 $arNames[] = $arFromUser[$fromID][
'FROM_USER'];
309 $arFromId[] = $arFromUser[$fromID][
'FROM_USER_ID'];
310 foreach ($arMessages as $arMessage)
312 $message .=
GetMessage(
'IM_MAIL_TEMPLATE_NEW_MESSAGE_TEXT', Array(
'#DATE_CREATE#' => $arMessage[
'DATE_CREATE'],
'#MESSAGE#' => $arMessage[
'MESSAGE'])).
"\n";
313 $fromIdUserMessages .= nl2br(
GetMessage(
'IM_MAIL_TEMPLATE_NEW_MESSAGE_TEXT', Array(
'#DATE_CREATE#' => $arMessage[
'DATE_CREATE'],
'#MESSAGE#' => $arMessage[
'MESSAGE'])).
"\n");
315 $messagesFromUsers[$fromID] = $fromIdUserMessages;
318 $message .=
"\n".GetMessage(
'IM_MAIL_TEMPLATE_NEW_MESSAGE_FOOTER');
320 $fromUserId = $arToInfo[
"FROM_USER_ID"] ??
null;
323 "USER" => $arToInfo[
"USER_ID"],
324 "USER_ID" =>
count(
$arNames) > 1? $arToInfo[
"USER_ID"]: $fromUserId,
325 "USER_LOGIN" => $arToInfo[
"USER_LOGIN"],
326 "USER_NAME" => $arToInfo[
"USER_NAME"],
327 "USER_LAST_NAME" => $arToInfo[
"USER_LAST_NAME"],
328 "USER_SECOND_NAME" => $arToInfo[
"USER_SECOND_NAME"],
329 "EMAIL_TO" => $arToInfo[
"EMAIL_TO"],
330 "TITLE" => $arToInfo[
"TITLE"] ??
null,
332 "MESSAGES_FROM_USERS" => serialize($messagesFromUsers),
333 "DATE_CREATE" =>
null,
335 $arFields[
'FROM_USER_ID'] = implode(
', ', $arFromId);
338 $mailTemplate =
"IM_NEW_MESSAGE_GROUP";
343 $mailTemplate =
"IM_NEW_MESSAGE";
351 return __METHOD__.
'();';
402 if (!is_object(
$USER) || !
$USER->IsAuthorized())
408 if (COption::GetOptionString(
'intranet',
'allow_external_mail',
'Y') !=
'Y')
411 if (COption::GetOptionString(
'extranet',
'extranet_site',
'') ==
SITE_ID)
414 if (isset(\
Bitrix\Main\Application::getInstance()->getKernelSession()[
'aExtranetUser_'.
$USER->GetID()][
SITE_ID]))
416 if (!\
Bitrix\Main\Application::getInstance()->getKernelSession()[
'aExtranetUser_'.
$USER->GetID()][
SITE_ID])
419 else if (CModule::IncludeModule(
'extranet') && !CExtranet::IsIntranetUser())
425 if (COption::GetOptionString(
'dav',
'exchange_server',
'') ==
'')
428 if (COption::GetOptionString(
'dav',
'agent_mail',
'N') !=
'Y')
431 if (COption::GetOptionString(
'dav',
'exchange_use_login',
'Y') ==
'Y')
434 if (!CUserOptions::GetOption(
'global',
'davex_mailbox'))
436 $arUser = CUser::GetList(
439 array(
'SELECT' =>
array(
'UF_BXDAVEX_MAILBOX'),
'FIELDS' =>
array(
'ID'))
442 CUserOptions::SetOption(
'global',
'davex_mailbox', empty($arUser[
'UF_BXDAVEX_MAILBOX']) ?
'N' :
'Y');
445 if (CUserOptions::GetOption(
'global',
'davex_mailbox') ==
'Y')