- Improve logic of signatures colorizing and truncating, introduce sig_max_lines option

release-0.6
alecpl 14 years ago
parent 99b8c1e2ac
commit 33dfdd891b

@ -610,14 +610,24 @@ function rcmail_create_reply_body($body, $bodyIsHtml)
global $RCMAIL, $MESSAGE, $LINE_LENGTH; global $RCMAIL, $MESSAGE, $LINE_LENGTH;
if (!$bodyIsHtml) { if (!$bodyIsHtml) {
$body = preg_replace('/\r?\n/', "\n", $body);
// try to remove the signature // try to remove the signature
if ($RCMAIL->config->get('strip_existing_sig', true) && ($sp = strrpos($body, '-- ')) !== false && ($sp == 0 || $body{$sp-1} == "\n")) { if ($RCMAIL->config->get('strip_existing_sig', true)) {
if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r") $len = strlen($body);
$body = substr($body, 0, max(0, $sp-1)); while (($sp = strrpos($body, "-- \n", $sp ? -$len+$sp-1 : 0)) !== false) {
if ($sp == 0 || $body[$sp-1] == "\n") {
// do not touch blocks with more that X lines
if (substr_count($body, "\n", $sp) < $RCMAIL->config->get('sig_max_lines', 15)) {
$body = substr($body, 0, max(0, $sp-1));
}
break;
}
}
} }
// soft-wrap and quote message text // soft-wrap and quote message text
$body = rcmail_wrap_and_quote(rtrim($body, "\r\n"), $LINE_LENGTH); $body = rcmail_wrap_and_quote(rtrim($body, "\n"), $LINE_LENGTH);
// add title line(s) // add title line(s)
$prefix = sprintf("On %s, %s wrote:\n", $prefix = sprintf("On %s, %s wrote:\n",

@ -754,6 +754,8 @@ function rcmail_print_body($part, $p = array())
*/ */
function rcmail_plain_body($body, $flowed=false) function rcmail_plain_body($body, $flowed=false)
{ {
global $RCMAIL;
// make links and email-addresses clickable // make links and email-addresses clickable
$replacer = new rcube_string_replacer; $replacer = new rcube_string_replacer;
@ -780,9 +782,9 @@ function rcmail_plain_body($body, $flowed=false)
str_repeat('</blockquote>', $quote_level - $q))) . $a_lines[$n]; str_repeat('</blockquote>', $quote_level - $q))) . $a_lines[$n];
else if ($flowed) { else if ($flowed) {
// previous line is flowed // previous line is flowed
if (isset($a_lines[$last]) if (isset($a_lines[$last]) && $a_lines[$n]
&& $a_lines[$last][strlen($a_lines[$last])-1] == ' ') { && $a_lines[$last][strlen($a_lines[$last])-1] == ' ') {
// merge lines (and remove space-stuffing) // merge lines
$a_lines[$last] .= $a_lines[$n]; $a_lines[$last] .= $a_lines[$n];
unset($a_lines[$n]); unset($a_lines[$n]);
} }
@ -803,7 +805,7 @@ function rcmail_plain_body($body, $flowed=false)
$a_lines[$n] = substr($a_lines[$n], 1); $a_lines[$n] = substr($a_lines[$n], 1);
// previous line is flowed? // previous line is flowed?
if (isset($a_lines[$last]) if (isset($a_lines[$last]) && $a_lines[$n]
&& $a_lines[$last] != '-- ' && $a_lines[$last] != '-- '
&& $a_lines[$last][strlen($a_lines[$last])-1] == ' ' && $a_lines[$last][strlen($a_lines[$last])-1] == ' '
) { ) {
@ -830,12 +832,14 @@ function rcmail_plain_body($body, $flowed=false)
$body = Q(join("\n", $a_lines), '', false); $body = Q(join("\n", $a_lines), '', false);
// colorize signature // colorize signature
if (($sp = strrpos($body, "-- \n")) !== false) { $len = strlen($body);
if (($sp == 0 || $body[$sp-1] == "\n")) { while (($sp = strrpos($body, "-- \n", $sp ? -$len+$sp-1 : 0)) !== false) {
// do not touch blocks with more that 10 lines if ($sp == 0 || $body[$sp-1] == "\n") {
if (substr_count($body, "\n", $sp) < 10) // do not touch blocks with more that X lines
if (substr_count($body, "\n", $sp) < $RCMAIL->config->get('sig_max_lines', 15))
$body = substr($body, 0, max(0, $sp)) $body = substr($body, 0, max(0, $sp))
.'<span class="sig">'.substr($body, $sp).'</span>'; .'<span class="sig">'.substr($body, $sp).'</span>';
break;
} }
} }

Loading…
Cancel
Save