MailFormatHelper
class MailFormatHelper (View source)
Defines a class containing utility methods for formatting mail messages.
Properties
| static protected array | $urls | Internal array of urls replaced with tokens. |
|
| static protected string | $regexp | Quoted regex expression based on base path. |
|
| static protected array | $supportedTags | Array of tags supported. |
Methods
Performs format=flowed soft wrapping for mail (RFC 3676).
Transforms an HTML string into plain text, preserving its structure.
Wraps words on a single line.
Keeps track of URLs and replaces them with placeholder tokens.
Replaces non-quotation markers from a piece of indentation with spaces.
Pads the last line with the given character.
Details
static string
wrapMail(string $text, string $indent = '')
Performs format=flowed soft wrapping for mail (RFC 3676).
We use delsp=yes wrapping, but only break non-spaced languages when absolutely necessary to avoid compatibility issues.
We deliberately use LF rather than CRLF, see MailManagerInterface::mail().
static string
htmlToText(string $string, array $allowed_tags = NULL)
Transforms an HTML string into plain text, preserving its structure.
The output will be suitable for use as 'format=flowed; delsp=yes' text (RFC 3676) and can be passed directly to MailManagerInterface::mail() for sending.
We deliberately use LF rather than CRLF, see MailManagerInterface::mail().
This function provides suitable alternatives for the following tags:
static protected
wrapMailLine($line, $key, $values)
Wraps words on a single line.
Callback for array_walk() within \Drupal\Core\Mail\MailFormatHelper::wrapMail().
Note that we are skipping MIME content header lines, because attached files, especially applications, could have long MIME types or long filenames which result in line length longer than the 77 characters limit and wrapping that line will break the email format. For instance, the attached file hello_drupal.docx will produce the following Content-Type:
static protected
htmlToMailUrls($match = NULL, $reset = FALSE)
Keeps track of URLs and replaces them with placeholder tokens.
Callback for preg_replace_callback() within \Drupal\Core\Mail\MailFormatHelper::htmlToText().
static protected
htmlToTextClean($indent)
Replaces non-quotation markers from a piece of indentation with spaces.
Callback for array_map() within \Drupal\Core\Mail\MailFormatHelper::htmlToText().
static protected string
htmlToTextPad(string $text, string $pad, string $prefix = '')
Pads the last line with the given character.