public function PHPMailer::utf8CharBoundary
Search API
5.x PHPMailer.php | public PHPMailer::utf8CharBoundary($encodedText, $maxLength) |
Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string. Original written by Colin Brown.
Parameters
string $encodedText utf-8 QP text:
int $maxLength Find the last character boundary prior to this length:
Return value
int
1 call to PHPMailer::utf8CharBoundary()
- PHPMailer::wrapText in inc/
PHPMailer/ src/ PHPMailer.php - Word-wrap message. For use with mailers that do not automatically perform wrapping and for quoted-printable encoded messages. Original written by philippe.
File
- inc/
PHPMailer/ src/ PHPMailer.php, line 2256
Class
- PHPMailer
- PHPMailer - PHP email creation and transport class.
Namespace
PHPMailer\PHPMailerCode
public function utf8CharBoundary($encodedText, $maxLength)
{
$foundSplitPos = false;
$lookBack = 3;
while (!$foundSplitPos) {
$lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
$encodedCharPos = strpos($lastChunk, '=');
if (false !== $encodedCharPos) {
// Found start of encoded character byte within $lookBack block.
// Check the encoded byte value (the 2 chars after the '=')
$hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
$dec = hexdec($hex);
if ($dec < 128) {
// Single byte character.
// If the encoded char was found at pos 0, it will fit
// otherwise reduce maxLength to start of the encoded char
if ($encodedCharPos > 0) {
$maxLength -= $lookBack - $encodedCharPos;
}
$foundSplitPos = true;
}
elseif ($dec >= 192) {
// First byte of a multi byte character
// Reduce maxLength to split at start of character
$maxLength -= $lookBack - $encodedCharPos;
$foundSplitPos = true;
}
elseif ($dec < 192) {
// Middle byte of a multi byte character, look further back
$lookBack += 3;
}
}
else {
// No encoded character found
$foundSplitPos = true;
}
}
return $maxLength;
}