• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/mail/mail.php
  • Класс: BitrixMainMailMail
  • Вызов: Mail::setBody
public function setBody($bodyPart)
{
	$charset = $this->charset;
	$messageId = $this->messageId;

	$htmlPart = null;
	$plainPart = new Part();
	$plainPart->addHeader('Content-Type', 'text/plain; charset=' . $charset);

	if($this->contentType == "html")
	{
		$bodyPart = $this->replaceImages($bodyPart);
		$bodyPart = $this->replaceHrefs($bodyPart);
		$bodyPart = $this->trackRead($bodyPart);
		$bodyPart = $this->addMessageIdToBody($bodyPart, true, $messageId);

		$htmlPart = new Part();
		$htmlPart->addHeader('Content-Type', 'text/html; charset=' . $charset);
		$htmlPart->setBody($bodyPart);
		$plainPart->setBody($this->convertBodyHtmlToText($bodyPart));
	}
	else
	{
		$bodyPart = $this->addMessageIdToBody($bodyPart, false, $messageId);
		$plainPart->setBody($bodyPart);
	}

	$cteName = 'Content-Transfer-Encoding';
	$cteValue = $this->contentTransferEncoding;

	if ($this->settingMailEncodeBase64)
	{
		$cteValue = 'base64';
	}
	else if ($this->settingMailEncodeQuotedPrintable)
	{
		$cteValue = 'quoted-printable';
	}

	$this->multipart->addHeader($cteName, $cteValue);
	$plainPart->addHeader($cteName, $cteValue);
	if ($htmlPart)
	{
		$htmlPart->addHeader($cteName, $cteValue);
	}


	if ($htmlPart)
	{
		if ($this->hasImageAttachment(true))
		{
			$this->multipartRelated = (new Multipart())->setContentType(Multipart::RELATED)->setEol($this->eol);
			$this->multipartRelated->addPart($htmlPart);
			$htmlPart = $this->multipartRelated;
		}

		if ($this->generateTextVersion)
		{
			$alternative = (new Multipart())->setContentType(Multipart::ALTERNATIVE)->setEol($this->eol);
			$alternative->addPart($plainPart);
			$alternative->addPart($htmlPart);
			$this->multipart->addPart($alternative);
		}
		else
		{
			$this->multipart->addPart($htmlPart);
		}
	}
	else
	{
		$this->multipart->addPart($plainPart);
	}

	$this->setAttachment();

	$body = $this->multipart->toStringBody();
	$body = str_replace("rn", "n", $body);
	if($this->settingConvertNewLineUnixToWindows)
	{
		$body = str_replace("n", "rn", $body);
	}
	$this->body = $body;
}