Email::getParentByEmail

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Email
  4. getParentByEmail
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/email.php
  • Класс: Bitrix\Crm\Activity\Provider\Email
  • Вызов: Email::getParentByEmail
static function getParentByEmail(&$msgFields)
{
	$inReplyTo = isset($msgFields['IN_REPLY_TO']) ? $msgFields['IN_REPLY_TO'] : '';

	// @TODO: multiple
	if (!empty($inReplyTo))
	{
		if (preg_match('/]+>/i', sprintf('<%s>', $inReplyTo), $matches))
		{
			$matchActivity = \CCrmActivity::getById($matches[2], false);
			if ($matchActivity && mb_strtolower($matchActivity['URN']) == mb_strtolower($matches[1]))
				$targetActivity = $matchActivity;
		}

		if (empty($targetActivity))
		{
			$res = Activity\MailMetaTable::getList([
				'select' => ['ACTIVITY_ID'],
				'filter' => [
					'=MSG_ID_HASH' => md5(mb_strtolower($inReplyTo)),
				],
			]);

			while ($mailMeta = $res->fetch())
			{
				if ($matchActivity = \CCrmActivity::getById($mailMeta['ACTIVITY_ID'], false))
				{
					$targetActivity = $matchActivity;
					break;
				}
			}
		}
	}

	if (empty($targetActivity))
	{
		$urnInfo = \CCrmActivity::parseUrn(
			\CCrmActivity::extractUrnFromMessage(
				$msgFields, \CCrmEMailCodeAllocation::getCurrent()
			)
		);

		if ($urnInfo['ID'] > 0)
		{
			$matchActivity = \CCrmActivity::getById($urnInfo['ID'], false);
			if (!empty($matchActivity) && mb_strtolower($matchActivity['URN']) == mb_strtolower($urnInfo['URN']))
				$targetActivity = $matchActivity;
		}
	}

	if (!empty($targetActivity))
	{
		if ($targetActivity['OWNER_TYPE_ID'] > 0 && $targetActivity['OWNER_ID'] > 0)
		{
			return $targetActivity;
		}
	}

	return false;
}

Добавить комментарий