aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2006-11-23 14:54:37 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2006-11-23 14:54:37 +0000
commit6d6f433d2eec895bb6cd61e286d289434faae9ba (patch)
tree08bd0746a2c4405900d9b831d81ea97cfd244d51
parent945491d37d47d46d6f0f189dd2493bf9a0bd3367 (diff)
downloadforums-6d6f433d2eec895bb6cd61e286d289434faae9ba.tar
forums-6d6f433d2eec895bb6cd61e286d289434faae9ba.tar.gz
forums-6d6f433d2eec895bb6cd61e286d289434faae9ba.tar.bz2
forums-6d6f433d2eec895bb6cd61e286d289434faae9ba.tar.xz
forums-6d6f433d2eec895bb6cd61e286d289434faae9ba.zip
davidmj came up with a simpler (and working in all cases!) approach. :) Bow to him...
git-svn-id: file:///svn/phpbb/trunk@6642 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r--phpBB/includes/functions_messenger.php52
1 files changed, 18 insertions, 34 deletions
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index 113d9a6178..273a74edef 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -1374,63 +1374,47 @@ class smtp_class
* is if the mail client does not understand this encoding the user
* is basically doomed with an unreadable subject.
*
-* Please note that this version fully supports RFC 2045 section 6.8 to
-* the expense of using more resources. It downgrades to non-compliance (but workable)
-* if the string is not able to be splitted properly.
-* You are able to force non-compliance.
+* Please note that this version fully supports RFC 2045 section 6.8.
*/
-function mail_encode($str, $compliant = true)
+function mail_encode($str)
{
// define start delimimter, end delimiter and spacer
- $end = '?=';
- $start = '=?UTF-8?B?';
- $spacer = "$end $start";
+ $start = "=?UTF-8?B?";
+ $end = "?=";
+ $spacer = $end . ' ' . $start;
+ $split_length = 64;
$encoded_str = base64_encode($str);
- $split_length = 64;
- // Pass back if the encoded string does not need to be split or forced.
- if (!$compliant || strlen($encoded_str) <= $split_length)
+ // If encoded string meets the limits, we just return with the correct data.
+ if (strlen($encoded_str) <= $split_length)
{
return $start . $encoded_str . $end;
}
- // If there is only ASCII data, we just return what we want, no need to process.
+ // If there is only ASCII data, we just return what we want, correctly splitting the lines.
if (strlen($str) === utf8_strlen($str))
{
return $start . implode($spacer, str_split($encoded_str, $split_length)) . $end;
}
- // What we do is encoding/decoding forth and back and checking
- // for a valid utf8 string to make sure no lines include half-baked data.
- $correct_encode = false;
+ // UTF-8 data, compose encoded lines
+ $array = utf8_str_split($str);
+ $str = '';
- // Also quit the operation if the chunks get too small
- while (!$correct_encode || $split_length < 10)
+ while (sizeof($array))
{
- $chunks = str_split($encoded_str, $split_length);
- $correct_encode = true;
+ $text = '';
- foreach ($chunks as $chunk)
+ while (sizeof($array) && strlen(base64_encode($text . $array[0])) <= $split_length)
{
- // Not well-formed utf8 data?
- if (!preg_match('/^./u', base64_decode($chunk)))
- {
- $correct_encode = false;
-
- // Always odd length
- $split_length -= 2;
- }
+ $text .= array_shift($array);
}
- }
- if (!$correct_encode)
- {
- // Not RFC-compliant, but working with all setups
- return $start . $encoded_str . $end;
+ $str .= $start . base64_encode($text) . $end . ' ';
}
- return $start . implode($spacer, $chunks) . $end;
+ return substr($str, 0, -1);
}
?> \ No newline at end of file