diff options
author | Thomas Bruederli <thomas@roundcube.net> | 2012-11-19 11:02:13 +0100 |
---|---|---|
committer | Thomas Bruederli <thomas@roundcube.net> | 2012-11-19 11:02:13 +0100 |
commit | c72a96144de1e5674159f4010ec0e44c9d946a5b (patch) | |
tree | 8385fbd77ce12e30613bec7ecf2ccaeb8fb5520f /program/include/rcube_mime.php | |
parent | 6fa61759e2369f4702ecebe584c133f9d79e0d93 (diff) |
Improve line wrapping behavior where message charset is changed by plugins (including html2plaintext conversion)
Diffstat (limited to 'program/include/rcube_mime.php')
-rw-r--r-- | program/include/rcube_mime.php | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/program/include/rcube_mime.php b/program/include/rcube_mime.php index 2dbeaf67a..ac3ef9e8a 100644 --- a/program/include/rcube_mime.php +++ b/program/include/rcube_mime.php @@ -529,10 +529,11 @@ class rcube_mime * * @param string $text Text to wrap * @param int $length Length + * @param string $charset Character encoding of $text * * @return string Wrapped text */ - public static function format_flowed($text, $length = 72) + public static function format_flowed($text, $length = 72, $charset=null) { $text = preg_split('/\r?\n/', $text); @@ -542,10 +543,10 @@ class rcube_mime $prefix = $regs[0]; $level = strlen($prefix); $line = rtrim(substr($line, $level)); - $line = $prefix . self::wordwrap($line, $length - $level - 2, " \r\n$prefix "); + $line = $prefix . self::wordwrap($line, $length - $level - 2, " \r\n$prefix ", false, $charset); } else if ($line) { - $line = self::wordwrap(rtrim($line), $length - 2, " \r\n"); + $line = self::wordwrap(rtrim($line), $length - 2, " \r\n", false, $charset); // space-stuffing $line = preg_replace('/(^|\r\n)(From| |>)/', '\\1 \\2', $line); } @@ -565,12 +566,16 @@ class rcube_mime * @param int $width Line width * @param string $break Line separator * @param bool $cut Enable to cut word + * @param string $charset Charset of $string * * @return string Text */ - public static function wordwrap($string, $width=75, $break="\n", $cut=false) + public static function wordwrap($string, $width=75, $break="\n", $cut=false, $charset=null) { - $para = explode($break, $string); + if ($charset) + mb_internal_encoding($charset); + + $para = preg_split('/\r?\n/', $string); $string = ''; while (count($para)) { @@ -624,6 +629,9 @@ class rcube_mime } } + if ($charset) + mb_internal_encoding(RCMAIL_CHARSET); + return $string; } |