- Модуль: mail
- Путь к файлу: ~/bitrix/modules/mail/lib/helper/mailbox.php
- Класс: BitrixMailHelperMailbox
- Вызов: Mailbox::registerMessage
protected function registerMessage(&$fields, $replaces = null, $isOutgoing = false)
{
$now = new MainTypeDateTime();
if (!empty($replaces))
{
/*
To replace the temporary id of outgoing emails with a permanent one
after receiving the uid from the original mail service.
*/
if($isOutgoing)
{
if (!is_array($replaces))
{
$replaces = [
'=ID' => $replaces,
];
}
$exists = MailMailMessageUidTable::getList([
'select' => [
'ID',
'MESSAGE_ID',
],
'filter' => [
$replaces,
'=MAILBOX_ID' => $this->mailbox['ID'],
'==DELETE_TIME' => 0,
],
])->fetch();
}
else
{
$exists = [
'ID' => $replaces,
'MESSAGE_ID' => $fields['MESSAGE_ID'],
];
}
}
if (!empty($exists))
{
$fields['MESSAGE_ID'] = $exists['MESSAGE_ID'];
$result = (bool) MailMailMessageUidTable::updateList(
array(
'=ID' => $exists['ID'],
'=MAILBOX_ID' => $this->mailbox['ID'],
'==DELETE_TIME' => 0,
),
array_merge(
$fields,
array(
'TIMESTAMP_X' => $now,
)
),
array_merge(
$exists,
array(
'MAILBOX_USER_ID' => $this->mailbox['USER_ID'],
)
)
);
}
else
{
$checkResult = new ORMDataAddResult();
$addFields = array_merge(
[
'MESSAGE_ID' => 0,
],
$fields,
[
'IS_OLD' => 'D',
'MAILBOX_ID' => $this->mailbox['ID'],
'SESSION_ID' => $this->session,
'TIMESTAMP_X' => $now,
'DATE_INSERT' => $now,
]
);
MailMailMessageUidTable::checkFields($checkResult, null, $addFields);
if (!$checkResult->isSuccess())
{
return false;
}
MailMailMessageUidTable::mergeData($addFields, [
'MSG_UID' => $addFields['MSG_UID'],
'HEADER_MD5' => $addFields['HEADER_MD5'],
'SESSION_ID' => $addFields['SESSION_ID'],
'TIMESTAMP_X' => $addFields['TIMESTAMP_X'],
]);
return true;
}
return $result;
}