• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/mail/mail.php
  • Класс: BitrixMainMailMail
  • Вызов: Mail::getReplacedImageCid
protected function getReplacedImageCid($matches)
{
	$src = $matches[3];

	if($src == "")
	{
		return $matches[0];
	}

	if(array_key_exists($src, $this->filesReplacedFromBody))
	{
		$uid = $this->filesReplacedFromBody[$src]["ID"];
		return $matches[1].$matches[2]."cid:".$uid.$matches[4].$matches[5];
	}

	$uri = new Uri($src);
	$filePath = Application::getDocumentRoot() . $uri->getPath();
	$io = CBXVirtualIo::GetInstance();
	$filePath = $io->GetPhysicalName($filePath);
	if(!File::isFileExists($filePath))
	{
		return $matches[0];
	}

	foreach($this->attachment as $attachIndex => $attach)
	{
		if($filePath == $attach['PATH'])
		{
			$this->attachment[$attachIndex]['RELATED'] = true;
			return $matches[1].$matches[2]."cid:".$attach['ID'].$matches[4].$matches[5];
		}
	}

	if ($this->settingMaxFileSize > 0)
	{
		$fileIoObject = new File($filePath);
		if ($fileIoObject->getSize() > $this->settingMaxFileSize)
		{
			return $matches[0];
		}
	}


	$imageInfo = (new BitrixMainFileImage($filePath))->getInfo();
	if (!$imageInfo)
	{
		return $matches[0];
	}

	if (function_exists("image_type_to_mime_type"))
	{
		$contentType = image_type_to_mime_type($imageInfo->getFormat());
	}
	else
	{
		$contentType = $this->imageTypeToMimeType($imageInfo->getFormat());
	}

	$uid = uniqid(md5($src));

	$this->filesReplacedFromBody[$src] = array(
		"RELATED" => true,
		"SRC" => $src,
		"PATH" => $filePath,
		"CONTENT_TYPE" => $contentType,
		"NAME" => bx_basename($src),
		"ID" => $uid,
	);

	return $matches[1].$matches[2]."cid:".$uid.$matches[4].$matches[5];
}