Hi all,
Some time ago I wrote to the list and reported a bug with regards to how quoted text was wrapping when the original email was HTML and the reply was in plain text (http://trac.roundcube.net/trac.cgi/ticket/1484141). With further investigation I discovered that this only seemed to happen when the line being wrapped was exactly equal to the maximum line length (75 characters, in compose.inc ($body = wordwrap($body, 75);)).
To reproduce the
I am *not* a programmer, so I know I'm not going to be able to do this the right way, but I do have Ilohamail kicking around and was able to look at how they do line wrapping, use their functions and get Roundcube wrapping HTML quoted text properly in plain text.
I'm not sure how to contribute this because I know I've *totally* done this wrong, but I'm hoping someone can see what I've done, do it the right way and get it in SVN.
Here's what I did:
Prior to function rcmail_create_reply_body($body, $bodyIsHtml) in compose.inc (line 484) I added the following:
function LangWrapLine($line, $width){ $line_len = strlen($line); $i = 0;
//if line is less than width, we're good
if ($line_len <= $width) return $line;
for ($prev_i=0,$i=$width;$i<$line_len;$prev_i=$i,$i+=$width){
//extract last segment that is $width wide
$chunk = substr($line, $prev_i, ($i-$prev_i))."\n";
//find last space in this chunk
$last_space = strrpos($chunk, " ");
$last_space = $prev_i + $last_space;
if ($last_space==$prev_i){
//no space found in this chunk
$next_space = strpos($line, " ", $i);
if ($next_space!==false){
$i = $next_space;
$line[$next_space] = "\n";
}
}else{
//replace last space before width with newline
$line[$last_space]="\n";
$i = $last_space;
}
}
return $line;
}
function LangSmartWrap($body, $len){ $lines = explode("\n", $body);
if (!is_array($lines)) return "";
while ( list($i,$line)=each($lines) ){
if (!ereg("^>", $line)) $lines[$i] = LangWrapLine(chop($line), $len);
}
return implode("\n", $lines);
}
which is almost an exact copy of the relevant functions out of Ilohamail. I then changed:
$body = wordwrap($body, 75);
on line 491 to:
LangSmartWrap($body, 75);
As I said, I know this isn't how it should be, but using the above functions everything works as it is supposed to.