- Модуль: mail
- Путь к файлу: ~/bitrix/modules/mail/classes/general/mail.php
- Класс: CAllMailMessage
- Вызов: CAllMailMessage::getClearBody
static function getClearBody(string $body): string
{
//todo merge with BitrixMainMailMail::convertBodyHtmlToText
// get inner html if exists
$innerBody = trim(preg_replace('/(.*?]*>)(.*?)(.*)/is', '$2', $body));
$body = $innerBody ?: $body;
// modify links to text version
$body = preg_replace_callback(
"%]*?href=(['"])(?[^1]*?)(?1)[^>]*?>(?.*?)%ims",
function ($matches)
{
$href = $matches['href'];
$text = trim($matches['text']);
if (!$href)
{
return $matches[0];
}
$text = strip_tags($text);
return ($text ? "$text:" : '') ."n$hrefn";
},
$body
);
// change
to new line
$body = preg_replace('/
/i', "n", $body);
$body = preg_replace('|()|isU', '', $body);
$body = preg_replace('|()|isU', '', $body);
// remove tags
$body = strip_tags($body);
// format text to the left side
$lines = [];
foreach (explode("n", trim($body)) as $line)
{
$lines[] = trim($line);
}
// remove redundant new lines
$body = preg_replace("/[\n]{2,}/", "nn", implode("n", $lines));
// remove redundant spaces
$body = preg_replace("/[ \t]{2,}/", " ", $body);
// decode html-entities
return html_entity_decode($body);
}