mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
Merge pull request #6258 from rxu/ticket/15729
[ticket/15729] Avoid unnecessary email headers encoding in Base64
This commit is contained in:
commit
75df7c202e
1 changed files with 14 additions and 6 deletions
|
@ -1853,14 +1853,22 @@ class smtp_class
|
||||||
*/
|
*/
|
||||||
function mail_encode($str, $eol = "\r\n")
|
function mail_encode($str, $eol = "\r\n")
|
||||||
{
|
{
|
||||||
// define start delimimter, end delimiter and spacer
|
// Check if string contains ASCII only characters
|
||||||
$start = "=?UTF-8?B?";
|
$is_ascii = strlen($str) === utf8_strlen($str);
|
||||||
|
|
||||||
|
// Define start delimimter, end delimiter and spacer
|
||||||
|
// Use the Quoted-Printable encoding for ASCII strings to avoid unnecessary encoding in Base64
|
||||||
|
$start = $is_ascii ? "=?US-ASCII?Q?" : "=?UTF-8?B?";
|
||||||
$end = "?=";
|
$end = "?=";
|
||||||
$delimiter = "$eol ";
|
$delimiter = "$eol ";
|
||||||
|
|
||||||
// Maximum length is 75. $split_length *must* be a multiple of 4, but <= 75 - strlen($start . $delimiter . $end)!!!
|
// Maximum encoded-word length is 75 as per RFC 2047 section 2.
|
||||||
$split_length = 60;
|
// $split_length *must* be a multiple of 4, but <= 75 - strlen($start . $delimiter . $end)!!!
|
||||||
$encoded_str = base64_encode($str);
|
$split_length = 75 - strlen($start . $delimiter . $end);
|
||||||
|
$split_length = $split_length - $split_length % 4;
|
||||||
|
|
||||||
|
// Use the Quoted-Printable encoding for ASCII strings to avoid unnecessary encoding in Base64
|
||||||
|
$encoded_str = $is_ascii ? quoted_printable_encode($str) : base64_encode($str);
|
||||||
|
|
||||||
// If encoded string meets the limits, we just return with the correct data.
|
// If encoded string meets the limits, we just return with the correct data.
|
||||||
if (strlen($encoded_str) <= $split_length)
|
if (strlen($encoded_str) <= $split_length)
|
||||||
|
@ -1869,7 +1877,7 @@ function mail_encode($str, $eol = "\r\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is only ASCII data, we just return what we want, correctly splitting the lines.
|
// If there is only ASCII data, we just return what we want, correctly splitting the lines.
|
||||||
if (strlen($str) === utf8_strlen($str))
|
if ($is_ascii)
|
||||||
{
|
{
|
||||||
return $start . implode($end . $delimiter . $start, str_split($encoded_str, $split_length)) . $end;
|
return $start . implode($end . $delimiter . $start, str_split($encoded_str, $split_length)) . $end;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue