From d8270b66ccca4aef0db76bade89a398b1d33abe9 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 18 Mar 2013 14:51:32 -0400
Subject: [PATCH] Fix wrapping of text lines with the same length as specified length limit

---
 tests/src/format-flowed.txt          |    4 ++--
 program/lib/Roundcube/rcube_mime.php |    7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php
index 2f24a1b..d21e3b4 100644
--- a/program/lib/Roundcube/rcube_mime.php
+++ b/program/lib/Roundcube/rcube_mime.php
@@ -595,11 +595,12 @@
             while (count($list)) {
                 $line   = array_shift($list);
                 $l      = mb_strlen($line);
-                $newlen = $len + $l + ($len ? 1 : 0);
+                $space  = $len ? 1 : 0;
+                $newlen = $len + $l + $space;
 
                 if ($newlen <= $width) {
-                    $string .= ($len ? ' ' : '').$line;
-                    $len += (1 + $l);
+                    $string .= ($space ? ' ' : '').$line;
+                    $len += ($space + $l);
                 }
                 else {
                     if ($l > $width) {
diff --git a/tests/src/format-flowed.txt b/tests/src/format-flowed.txt
index a390ffd..359a41a 100644
--- a/tests/src/format-flowed.txt
+++ b/tests/src/format-flowed.txt
@@ -1,7 +1,7 @@
 I'm replying on this with a very long line which is then wrapped and 
 space-stuffed because the draft is saved as format=flowed.
- From what's specified in RFC 2646 some lines need to be space-stuffed to 
-avoid muning during transport.
+ From what's specified in RFC 2646 some lines need to be space-stuffed to avoid 
+muning during transport.
 
 X
 

--
Gitblit v1.9.1