summaryrefslogtreecommitdiff
path: root/program/include/rcube_shared.inc
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2009-03-30 18:04:18 +0000
committeralecpl <alec@alec.pl>2009-03-30 18:04:18 +0000
commit7145e009e440ef4d6dcba2b4845656376c9d8ccd (patch)
tree781720e87f351cecef10ed49126c6b1ea6f90077 /program/include/rcube_shared.inc
parentdadb05b0afc9a76d4f29a8d35bdf268aa20926df (diff)
- Fix incorrect word wrapping in outgoing plaintext multibyte messages (#1485714)
- Fix double footer in HTML message with embedded images
Diffstat (limited to 'program/include/rcube_shared.inc')
-rw-r--r--program/include/rcube_shared.inc48
1 files changed, 48 insertions, 0 deletions
diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc
index f1cbb19c3..a05815800 100644
--- a/program/include/rcube_shared.inc
+++ b/program/include/rcube_shared.inc
@@ -405,6 +405,54 @@ function rc_strrpos($haystack, $needle, $offset=0)
return strrpos($haystack, $needle, $offset);
}
+/**
+ * Wrapper function for wordwrap
+ */
+function rc_wordwrap($string, $width=75, $break="\n", $cut=false)
+{
+ if (!function_exists('mb_substr') || !function_exists('mb_strlen'))
+ return wordwrap($string, $width, $break, $cut);
+
+ $para = explode($break, $string);
+ $string = '';
+ while (count($para)) {
+ $list = explode(' ', array_shift($para));
+ $len = 0;
+ while (count($list)) {
+ $line = array_shift($list);
+ $l = mb_strlen($line);
+ $newlen = $len + $l + ($len ? 1 : 0);
+
+ if ($newlen <= $width) {
+ $string .= ($len ? ' ' : '').$line;
+ $len += ($len ? 1 : 0) + $l;
+ } else {
+ if ($l > $width) {
+ if ($cut) {
+ $start = 0;
+ while ($l) {
+ $str = mb_substr($line, $start, $width);
+ $strlen = mb_strlen($str);
+ $string .= ($len ? $break : '').$str;
+ $start += $strlen;
+ $l -= $strlen;
+ $len = $strlen;
+ }
+ } else {
+ $string .= ($len ? $break : '').$line;
+ if (count($list)) $string .= $break;
+ $len = 0;
+ }
+ } else {
+ $string .= $break.$line;
+ $len = $l;
+ }
+ }
+ }
+ if (count($para)) $string .= $break;
+ }
+ return $string;
+}
/**
* Read a specific HTTP request header