From ba12c76300387988c95417d97b50243a9682d4b6 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Tue, 12 Oct 2010 04:56:46 -0400
Subject: [PATCH] - Fix signature removal when replying in HTML to plain/text message

---
 program/steps/mail/compose.inc |   46 +++++++++++++++++++++++++++++++---------------
 program/steps/mail/func.inc    |    5 +++--
 2 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 406033c..1b39b588 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -537,7 +537,12 @@
         $body = $MESSAGE->first_html_part();
       }
       else {
-        $body = rcmail_plain_body($MESSAGE->first_text_part());
+        $body = $MESSAGE->first_text_part();
+        // try to remove the signature
+        if ($RCMAIL->config->get('strip_existing_sig', true))
+          $body = rcmail_remove_signature($body);
+        // add HTML formatting
+        $body = rcmail_plain_body($body);
         if ($body)
           $body = '<pre>' . $body . '</pre>';
       }
@@ -710,18 +715,8 @@
     $body = preg_replace('/\r?\n/', "\n", $body);
 
     // try to remove the signature
-    if ($RCMAIL->config->get('strip_existing_sig', true)) {
-      $len = strlen($body);
-      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;
-        }
-      }
-    }
+    if ($RCMAIL->config->get('strip_existing_sig', true))
+      $body = rcmail_remove_signature($body);
 
     // soft-wrap and quote message text
     $body = rcmail_wrap_and_quote(rtrim($body, "\n"), $LINE_LENGTH);
@@ -835,8 +830,29 @@
   
   return $body;
 }
-  
-  
+
+
+function rcmail_remove_signature($body)
+{
+  global $RCMAIL;
+
+  $len = strlen($body);
+  $sig_max_lines = $RCMAIL->config->get('sig_max_lines', 15);
+
+  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) < $sig_max_lines) {
+        $body = substr($body, 0, max(0, $sp-1));
+      }
+      break;
+    }
+  }
+
+  return $body;
+}
+
+
 function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
 {
   global $OUTPUT;
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 1d65390..9a24a97 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -843,12 +843,13 @@
   // quote plain text
   $body = Q(join("\n", $a_lines), 'dummy', false);
 
-  // colorize signature
+  // colorize signature (up to <sig_max_lines> lines)
   $len = strlen($body);
+  $sig_max_lines = $RCMAIL->config->get('sig_max_lines', 15);
   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))
+      if (substr_count($body, "\n", $sp) < $sig_max_lines)
         $body = substr($body, 0, max(0, $sp))
           .'<span class="sig">'.substr($body, $sp).'</span>';
       break;

--
Gitblit v1.9.1