CCrmEMail::BeforeSendMail

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmEMail
  4. BeforeSendMail
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_email.php
  • Класс: \CCrmEMail
  • Вызов: CCrmEMail::BeforeSendMail
static function BeforeSendMail($arMessageFields)
{
	// ADD ADDITIONAL HEADERS
	$postingID = self::ExtractPostingID($arMessageFields);
	if($postingID <= 0)
	{
		return $arMessageFields;
	}

	$dbActivity = \CCrmActivity::getList(
		array('ID' => 'DESC'),
		array(
			'=TYPE_ID' => CCrmActivityType::Email,
			'=ASSOCIATED_ENTITY_ID' => $postingID,
			'CHECK_PERMISSIONS'=>'N'
		),
		false,
		false,
		array('SETTINGS'),
		array()
	);

	$arActivity = $dbActivity ? $dbActivity->Fetch() : null;

	if(!$arActivity)
	{
		return $arMessageFields;
	}

	$settings = isset($arActivity['SETTINGS']) && is_array($arActivity['SETTINGS']) ? $arActivity['SETTINGS'] : array();
	$messageHeaders = isset($settings['MESSAGE_HEADERS']) ? $settings['MESSAGE_HEADERS'] : array();
	if(empty($messageHeaders))
	{
		return $arMessageFields;
	}

	$header = isset($arMessageFields['HEADER']) ? $arMessageFields['HEADER'] : '';
	$eol = CEvent::GetMailEOL();
	foreach($messageHeaders as $headerName => &$headerValue)
	{
		if($header <> '')
		{
			$header .= $eol;
		}

		$header .= $headerName.': '.$headerValue;
	}
	unset($headerValue);
	$arMessageFields['HEADER'] = $header;

	$cidRegex = sprintf(
		'/Content-Disposition: attachment; filename="(.+?)_(bxacid.[0-9a-f]{2,8}@[0-9a-f]{2,8}.crm)"(%s)/i',
		'\x'.join('\x', str_split(bin2hex(\Bitrix\Main\Mail\Mail::getMailEol()), 2))
	);
	if (preg_match_all($cidRegex, $arMessageFields['BODY'], $matches, PREG_SET_ORDER) > 0)
	{
		foreach ($matches as $set)
		{
			$arMessageFields['BODY'] = str_replace(
				$set[0],
				sprintf(
					'Content-Disposition: attachment; filename="%s"%sContent-ID: <%s>%s',
					$set[1], $set[3], $set[2], $set[3]
				),
				$arMessageFields['BODY']
			);

			$arMessageFields['BODY'] = str_replace(
				sprintf('%s_%s', $set[1], $set[2]),
				$set[1],
				$arMessageFields['BODY']
			);
		}
	}

	return $arMessageFields;
}

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