From dd792e8253f6fa94eba4e95293a32f8bc91289bb Mon Sep 17 00:00:00 2001
From: svncommit <devs@roundcube.net>
Date: Sun, 03 Dec 2006 17:32:16 -0500
Subject: [PATCH] fixed signature issues

---
 CHANGELOG                                |    6 +++
 program/lib/html2text.inc                |   17 +++++++-
 program/steps/mail/compose.inc           |    7 +++
 program/js/app.js                        |   60 ++++++++++++++++--------------
 program/steps/settings/edit_identity.inc |    2 
 5 files changed, 61 insertions(+), 31 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 4b7bc15..7af2da9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,12 @@
 CHANGELOG RoundCube Webmail
 ---------------------------
 
+2006/12/03 (estadtherr)
+----------
+- Added fix to convert HTML signatures for plain text messages
+- Fixed signature delimeter character to be standard (Bug #1484035)
+
+
 2006/12/01 (thomasb)
 ----------
 - Implemented preview pane
diff --git a/program/js/app.js b/program/js/app.js
index 3d4d848..4975980 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -1714,50 +1714,54 @@
       if (this.env.identity && this.env.signatures && this.env.signatures[this.env.identity])
         {
         sig = this.env.signatures[this.env.identity]['text'];
-        if (sig.indexOf('--')!=0)
-          sig = '--\n'+sig;
-  
+        if (sig.indexOf('-- ')!=0)
+          sig = '-- \n'+sig;
+
         p = message.lastIndexOf(sig);
         if (p>=0)
           message = message.substring(0, p-1) + message.substring(p+sig.length, message.length);
         }
-  
+
       // add the new signature string
       if (this.env.signatures && this.env.signatures[id])
         {
         sig = this.env.signatures[id]['text'];
-        if (sig.indexOf('--')!=0)
-          sig = '--\n'+sig;
+        if (this.env.signatures[id]['is_html'])
+          {
+          sig = this.env.signatures[id]['plain_text'];
+          }
+        if (sig.indexOf('-- ')!=0)
+          sig = '-- \n'+sig;
         message += '\n'+sig;
         }
       }
     else
       {
-        var eid = tinyMCE.getEditorId('_message');
-        // editor is a TinyMCE_Control object
-        var editor = tinyMCE.getInstanceById(eid);
-        var msgDoc = editor.getDoc();
-        var msgBody = msgDoc.body;
+      var eid = tinyMCE.getEditorId('_message');
+      // editor is a TinyMCE_Control object
+      var editor = tinyMCE.getInstanceById(eid);
+      var msgDoc = editor.getDoc();
+      var msgBody = msgDoc.body;
 
-        if (this.env.signatures && this.env.signatures[id])
+      if (this.env.signatures && this.env.signatures[id])
+        {
+        // Append the signature as a span within the body
+        var sigElem = msgDoc.getElementById("_rc_sig");
+        if (!sigElem)
           {
-          // Append the signature as a span within the body
-          var sigElem = msgDoc.getElementById("_rc_sig");
-          if (!sigElem)
-            {
-            sigElem = msgDoc.createElement("span");
-            sigElem.setAttribute("id", "_rc_sig");
-            msgBody.appendChild(sigElem);
-            }
-          if (this.env.signatures[id]['is_html'])
-            {
-            sigElem.innerHTML = this.env.signatures[id]['text'];
-            }
-          else
-            {
-            sigElem.innerHTML = '<pre>' + this.env.signatures[id]['text'] + '</pre>';
-            }
+          sigElem = msgDoc.createElement("span");
+          sigElem.setAttribute("id", "_rc_sig");
+          msgBody.appendChild(sigElem);
           }
+        if (this.env.signatures[id]['is_html'])
+          {
+          sigElem.innerHTML = this.env.signatures[id]['text'];
+          }
+        else
+          {
+          sigElem.innerHTML = '<pre>' + this.env.signatures[id]['text'] + '</pre>';
+          }
+        }
       }
 
     if (input_message)
diff --git a/program/lib/html2text.inc b/program/lib/html2text.inc
index 36849a4..eabe15c 100644
--- a/program/lib/html2text.inc
+++ b/program/lib/html2text.inc
@@ -164,7 +164,7 @@
         '$this->_build_link_list("\\1", "\\2")', // <a href="">
         "strtoupper(\"\n\n\\1\n\n\")",          // H1 - H3
         "ucwords(\"\n\n\\1\n\n\")",             // H4 - H6
-        "\n\n\t",                               // <P>
+        "\n",                                   // <P>
         "\n",                                   // <br>
         'strtoupper("\\1")',                    // <b>
         '_\\1_',                                // <i>
@@ -232,6 +232,15 @@
      *  @see _build_link_list()
      */
     var $_link_list = array();
+    
+    /**
+     * Boolean flag, true if a table of link URLs should be listed after the text.
+     * 
+     * @var boolean $_do_links
+     * @access private
+     * @see html2text()
+     */
+    var $_do_links = true;
 
     /**
      *  Constructor.
@@ -242,15 +251,17 @@
      *
      *  @param string $source HTML content
      *  @param boolean $from_file Indicates $source is a file to pull content from
+     *  @param boolean $do_link_table indicate whether a table of link URLs is desired
      *  @access public
      *  @return void
      */
-    function html2text( $source = '', $from_file = false )
+    function html2text( $source = '', $from_file = false, $do_link_table = true )
     {
         if ( !empty($source) ) {
             $this->set_html($source, $from_file);
         }
         $this->set_base_url();
+        $this->_do_links = $produce_link_table;
     }
 
     /**
@@ -409,6 +420,8 @@
     */
     function _build_link_list($link, $display)
       {
+      if (! $this->_do_links) return $display;
+
       $link_lc = strtolower($link);
       
       if (substr($link_lc, 0, 7) == 'http://' || substr($link_lc, 0, 8) == 'https://' || substr($link_lc, 0, 7) == 'mailto:')
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 76aa78f..6e1126b 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -20,6 +20,7 @@
 */
 
 require_once('Mail/mimeDecode.php');
+require_once('lib/html2text.inc');
 
 // define constants for message compose mode
 define('RCUBE_COMPOSE_REPLY', 0x0106);
@@ -296,6 +297,12 @@
         {
         $a_signatures[$identity_id]['text'] = $sql_arr['signature'];
         $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false;
+        if ($a_signatures[$identity_id]['is_html'])
+          {
+            $h2t = new html2text($a_signatures[$identity_id]['text'], false, false);
+            $plainTextPart = $h2t->get_text();
+            $a_signatures[$identity_id]['plain_text'] = trim($plainTextPart);
+          }
         }
 
       // set identity if it's one of the reply-message recipients
diff --git a/program/steps/settings/edit_identity.inc b/program/steps/settings/edit_identity.inc
index a7303bd..1ea8947 100644
--- a/program/steps/settings/edit_identity.inc
+++ b/program/steps/settings/edit_identity.inc
@@ -56,7 +56,7 @@
                                     "theme_advanced_toolbar_location : 'top'," .
                                     "theme_advanced_toolbar_align : 'left'," .
                                     "theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr'," .
-                                    "theme_advanced_buttons2 : 'link,unlink,forecolor,fontselect,fontsizeselect'," .
+                                    "theme_advanced_buttons2 : 'link,unlink,code,forecolor,fontselect,fontsizeselect'," .
                                     "theme_advanced_buttons3 : '' });");
 
   if (!$IDENTITY_RECORD && $GLOBALS['_action']!='add-identity')

--
Gitblit v1.9.1