From 0207c45c90818e7c7df64ea52c61050850dee13d Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Mon, 02 Nov 2009 04:58:14 -0500
Subject: [PATCH] More options for top posting feature (#1484272) using patch from Phil Weir

---
 CHANGELOG                             |    4 
 program/steps/mail/compose.inc        |   45 +++---
 program/localization/de_CH/labels.inc |   10 +
 config/main.inc.php.dist              |   14 +
 program/steps/settings/save_prefs.inc |    6 
 program/localization/de_DE/labels.inc |   10 +
 program/steps/settings/func.inc       |   45 ++++-
 program/localization/en_US/labels.inc |   16 +
 skins/default/images/mail_toolbar.gif |    0 
 program/localization/pl_PL/labels.inc |    9 
 skins/default/templates/compose.html  |    2 
 program/js/app.js                     |  208 ++++++++++++----------------
 skins/default/images/mail_toolbar.png |    0 
 13 files changed, 198 insertions(+), 171 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index a6b6d43..a99eb16 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,7 +2,7 @@
 ===========================
 
 - Don't cut off attachment names when using non-RFC2231 encoding (#1485515)
-- Allow inserting signatures above replied message body (#1484272) 
+- Allow inserting signatures above replied message body (#1484272)
 - Managesieve 2.0: multi-script support
 - Fix imap_auth_type regression (#1486263)
 
@@ -92,7 +92,7 @@
 ---------------
 - Fix import of vCard entries with params (#1485453)
 - Fix HTML messages output with empty block elements (#1485974)
-- Use request tokens to protect POST requests from CSFR
+- Use request tokens to protect POST requests from CSRF
 - Added hook when killing a session
 - Added hook to write_log function (#1485971)
 - Performance improvements by use UID commands (#1485690)
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 51c8ee4..5c3558a 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -453,12 +453,18 @@
 // When replying place cursor above original message (top posting)
 $rcmail_config['top_posting'] = FALSE;
 
+// When replying strip original signature from message
+$rcmail_config['strip_existing_sig'] = TRUE;
+
 // Show signature:
-// 0 - Always
-// 1 - Never
+// 0 - Never
+// 1 - Always
 // 2 - New messages only
-// 3 - Forwards, Edits and Replies only
-$rcmail_config['show_sig'] = 0;
+// 3 - Forwards and Replies only
+$rcmail_config['show_sig'] = 1;
+
+// When replying or forwarding place sender's signature above existing message
+$rcmail_config['sig_above'] = FALSE;
 
 // end of config file
 ?>
diff --git a/program/js/app.js b/program/js/app.js
index 3ada699..dca2956 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -473,9 +473,6 @@
     this.init_address_input_events($("[name='_cc']"));
     this.init_address_input_events($("[name='_bcc']"));
 
-    if (!html_mode)
-      this.set_caret_pos(input_message, this.env.top_posting ? 0 : $(input_message).val().length);
-
     // add signature according to selected identity
     if (input_from.attr('type') == 'select-one' && $("input[name='_draft_saveid']").val() == ''
         && !html_mode) {  // if we have HTML editor, signature is added in callback
@@ -975,10 +972,6 @@
         clearTimeout(this.request_timer);
         break;
 
-      case 'insert-sig':
-        this.change_identity($("[name='_from']")[0], true);
-        break;
-
       case 'add-attachment':
         this.show_attachment_form(true);
         
@@ -991,6 +984,10 @@
       
       case 'remove-attachment':
         this.remove_attachment(props);
+        break;
+
+      case 'insert-sig':
+        this.change_identity($("[name='_from']")[0], true);
         break;
 
       case 'reply-all':
@@ -2311,147 +2308,122 @@
       show_sig = this.env.show_sig;
 
     var id = obj.options[obj.selectedIndex].value;
+    var input_message = $("[name='_message']");
+    var message = input_message.val();
+    var new_message = '';
     var is_html = ($("input[name='_is_html']").val() == '1');
-    var sig;
-
-    // enable manual signature insert
-    if (this.env.signatures && this.env.signatures[id])
-      this.enable_command('insert-sig', true);
-    else {
-      this.enable_command('insert-sig', false);
-      if (!this.env.signatures)
-        return true;
-      }
+    var sig, p, len = message.length;
 
     if (!this.env.identity)
       this.env.identity = id
-
-    if (!show_sig)
-      return false;
   
-    if (!is_html)
-      {
-      var input_message = $("[name='_message']");
-      var message = input_message.val();
-      var pos, cursor_pos, p = -1;
+    // enable manual signature insert
+    if (this.env.signatures && this.env.signatures[id])
+      this.enable_command('insert-sig', true);
+    else
+      this.enable_command('insert-sig', false);
 
+    if (!is_html && show_sig) {
       // remove the 'old' signature
-      if (this.env.identity && this.env.signatures[this.env.identity])
-        {
+      if (this.env.identity && this.env.signatures && this.env.signatures[this.env.identity]) {
         if (this.env.signatures[this.env.identity]['is_html'])
           sig = this.env.signatures[this.env.identity]['plain_text'];
         else
           sig = this.env.signatures[this.env.identity]['text'];
+        
+        if (sig.indexOf('-- ') != 0)
+          sig = '-- \n'+sig;
 
-	if (this.env.top_posting)
-          p = message.indexOf(sig);
-        else {
-	  if (sig.indexOf('-- ')!=0)
-            sig = '-- \n'+sig;
-          p = message.lastIndexOf(sig);
-	  }
-	  
-        if (p>=0)
-          message = message.substring(0, p) + message.substring(p+sig.length, message.length);
-	}
+        p = message.lastIndexOf(sig);
+        if (p >= 0) {
+          if (this.env.sig_above) {
+            new_message = message.substring(0, p-1);
+            new_message = new_message.replace(/[\r\n]+$/, '');
+            message = message.substring(p+sig.length, message.length);
+          }
+          else {
+            message = message.substring(0, p-1) + message.substring(p+sig.length, message.length);
+          }
+        }
+      }
 
-      input_message.get(0).focus();
+      message = message.replace(/[\r\n]+$/, '');
+      len = message.length;
 
       // add the new signature string
-      if (this.env.signatures[id])
-        {
+      if (this.env.signatures && this.env.signatures[id]) {
+        sig = this.env.signatures[id]['text'];
         if (this.env.signatures[id]['is_html'])
           sig = this.env.signatures[id]['plain_text'];
-	else
-          sig = this.env.signatures[id]['text'];
 
-	if (this.env.top_posting) {
-	  if (p>=0) { // in place of removed signature
-	    message = message.substring(0, p) + sig + message.substring(p, message.length);
-	    cursor_pos = p - 1;
-	    }
-	  else if (pos = this.get_caret_pos(input_message.get(0))) { // at cursor position
-	    message = message.substring(0, pos) + '\n' + sig + '\n' + message.substring(pos, message.length);
-	    cursor_pos = pos;
-	    }
-	  else { // on top
-	    cursor_pos = 0;
-	    message = '\n\n' + sig + '\n' + message;
-	    }
-	  }
-	else {
-          message = message.replace(/[\r\n]+$/, '');
+        if (sig.indexOf('-- ') != 0)
+          sig = '-- \n'+sig;
 
-          if (sig.indexOf('-- ')!=0)
-            sig = '-- \n'+sig;
-	  cursor_pos = message.length ? message.length+1 : 0;
-          message += '\n\n' + sig;
-	  }
+        if (this.env.sig_above) {
+          message = message.replace(/^[\r\n]+/, '');
+          message = new_message+'\n\n'+sig+'\n\n'+message;
         }
+        else
+          message += '\n\n'+sig;
 
-      input_message.val(message);
-
-      // move cursor before the signature
-      if (typeof(cursor_pos) != 'undefined')
-        this.set_caret_pos(input_message.get(0), cursor_pos);
+        if (len)
+          len += 1;
+        }
       }
-    // html
-    else
+    else if (show_sig)
       {
       var editor = tinyMCE.get(this.env.composebody);
-      var sigElem = editor.dom.get('_rc_sig');
 
-      // Append the signature as a div within the body
-      if (!sigElem) {
-	var body = editor.getBody();
-	var doc = editor.getDoc();
-        
-	sigElem = doc.createElement('div');
-        sigElem.setAttribute('id', '_rc_sig');
-      
-        if (this.env.top_posting) {
-          // if no existing sig and top posting then insert at caret pos
-          editor.getWin().focus(); // correct focus in IE
-
-          var node = editor.selection.getNode();
-
-          if (node.nodeName == 'BODY') {
-            // no real focus, insert at start
-            body.insertBefore(sigElem, body.firstChild);
-            body.insertBefore(doc.createElement('br'), body.firstChild);
-            }
-          else {
-            body.insertBefore(sigElem, node.nextSibling);
-            body.insertBefore(doc.createElement('br'), node.nextSibling);
-            }
-	  }
-        else {
-	  if (bw.ie)
-            // add empty line before signature on IE
-            body.appendChild(doc.createElement('br'));
-
-          body.appendChild(sigElem);
-          }
-	}
-
-      if (this.env.signatures[id])
+      if (this.env.signatures)
         {
-        if (this.env.signatures[id]['is_html']) {
-          sig = this.env.signatures[id]['text'];
-          if (!this.env.top_posting && this.env.signatures[id]['plain_text'].indexOf('-- ')!=0)
-            sig = '-- <br />' + sig;
-	  }
-	else {
-          sig = this.env.signatures[id]['text'];
-	  if (!this.env.top_posting && sig.indexOf('-- ')!=0)
-            sig = '-- \n' + sig;
-	  sig = '<pre>' + sig + '</pre>';
+        // Append the signature as a div within the body
+        var sigElem = editor.dom.get('_rc_sig');
+        var newsig = '';
+        var htmlsig = true;
+
+        if (!sigElem)
+          {
+          // add empty line before signature on IE
+          if (bw.ie)
+            editor.getBody().appendChild(editor.getDoc().createElement('br'));
+
+          sigElem = editor.getDoc().createElement('div');
+          sigElem.setAttribute('id', '_rc_sig');
+          if (this.env.sig_above) {
+            editor.getBody().insertBefore(sigElem, editor.getBody().firstChild);
+            editor.getBody().insertBefore(editor.getDoc().createElement('br'), editor.getBody().firstChild);
+            editor.getBody().insertBefore(editor.getDoc().createElement('br'), editor.getBody().firstChild);
           }
-        
-        sigElem.innerHTML = sig;
+          else
+          editor.getBody().appendChild(sigElem);
+          }
+
+        if (this.env.signatures[id])
+        {
+          newsig = this.env.signatures[id]['text'];
+          htmlsig = this.env.signatures[id]['is_html'];
+
+          if (newsig && !this.env.sig_above) {
+            if (htmlsig && this.env.signatures[id]['plain_text'].indexOf('-- ')!=0)
+              newsig = '<p>-- </p>' + newsig;
+            else if (!htmlsig && newsig.indexOf('-- ')!=0)
+              newsig = '-- \n' + newsig;
+          }
+        }
+
+        if (htmlsig)
+          sigElem.innerHTML = newsig;
+        else
+          sigElem.innerHTML = '<pre>' + newsig + '</pre>';
         }
       }
 
+    input_message.val(message);
+
+    // move cursor before the signature
+    if (!is_html)
+      this.set_caret_pos(input_message.get(0), (this.env.top_posting ? 0 : len));
+
     this.env.identity = id;
     return true;
     };
diff --git a/program/localization/de_CH/labels.inc b/program/localization/de_CH/labels.inc
index 40d829b..7b3f14d 100644
--- a/program/localization/de_CH/labels.inc
+++ b/program/localization/de_CH/labels.inc
@@ -258,6 +258,16 @@
 $labels['maintenance'] = 'Wartung';
 $labels['newmessage'] = 'Neue Nachrichten';
 $labels['listoptions'] = 'Listendarstellung';
+$labels['signatureoptions'] = 'Signatur';
+$labels['whenreplying'] = 'Beantworten einer Nachricht';
+$labels['replytopposting'] = 'Antwort über der Originalnachricht';
+$labels['replybottomposting'] = 'Antwort unter der Originalnachricht';
+$labels['replyremovesignature'] = 'Beim Antworten die Signatur der Originalnachricht entfernen';
+$labels['autoaddsignature'] = 'Signatur automatisch einfügen';
+$labels['newmessageonly'] = 'nur bei neuen Nachrichten';
+$labels['replyandforwardonly'] = 'nur bei Antworten und Weiterleitungen';
+$labels['replysignatureabove'] = 'Beim Antworten die Signatur über der Originalnachricht einfügen';
+$labels['insertsignature'] = 'Signatur einfügen';
 $labels['folder'] = 'Ordner';
 $labels['folders'] = 'Ordner';
 $labels['foldername'] = 'Ordnername';
diff --git a/program/localization/de_DE/labels.inc b/program/localization/de_DE/labels.inc
index e063302..ac53b49 100644
--- a/program/localization/de_DE/labels.inc
+++ b/program/localization/de_DE/labels.inc
@@ -257,6 +257,16 @@
 $labels['maintenance'] = 'Wartung';
 $labels['newmessage'] = 'Neue Nachrichten';
 $labels['listoptions'] = 'Listendarstellung';
+$labels['signatureoptions'] = 'Signatur';
+$labels['whenreplying'] = 'Beantworten einer Nachricht';
+$labels['replytopposting'] = 'Antwort über der Originalnachricht';
+$labels['replybottomposting'] = 'Antwort unter der Originalnachricht';
+$labels['replyremovesignature'] = 'Beim Antworten Signatur der Originalnachricht entfernen';
+$labels['autoaddsignature'] = 'Signatur automatisch einfügen';
+$labels['newmessageonly'] = 'nur bei neuen Nachrichten';
+$labels['replyandforwardonly'] = 'nur bei Antworten und Weiterleitungen';
+$labels['replysignatureabove'] = 'Beim Antworten die Signatur über der Originalnachricht einfügen';
+$labels['insertsignature'] = 'Signatur einfügen';
 $labels['folder'] = 'Ordner';
 $labels['folders'] = 'Ordner';
 $labels['foldername'] = 'Ordnername';
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 9ed0d09..23dcc08 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -307,17 +307,23 @@
 $labels['checkallfolders'] = 'Check all folders for new messages';
 $labels['displaynext'] = 'After message delete/move display the next message';
 $labels['indexsort'] = 'Use message index for sorting by date';
-$labels['top_posting'] = 'Start reply on top of the replied message body (not recommended)';
-$labels['auto_add_sig'] = 'Automatically add signature';
-$labels['new_msg_only'] = 'new messages only';
-$labels['reply_forward_only'] = 'edits, replies and forwards only';
-$labels['insertsig'] = 'Insert signature';
 $labels['mainoptions'] = 'Main Options';
 $labels['section'] = 'Section';
 $labels['maintenance'] = 'Maintenance';
 $labels['newmessage'] = 'New Message';
 $labels['listoptions'] = 'List Options';
 
+$labels['signatureoptions'] = 'Signature Options';
+$labels['whenreplying'] = 'When replying';
+$labels['replytopposting'] = 'start new message above original';
+$labels['replybottomposting'] = 'start new message below original';
+$labels['replyremovesignature'] = 'When replying remove original signature from message';
+$labels['autoaddsignature'] = 'Automatically add signature';
+$labels['newmessageonly'] = 'new message only';
+$labels['replyandforwardonly'] = 'replies and forwards only';
+$labels['replysignatureabove'] = 'When replying or forwarding place signature above the quote';
+$labels['insertsignature'] = 'Insert signature';
+
 $labels['folder']  = 'Folder';
 $labels['folders']  = 'Folders';
 $labels['foldername']  = 'Folder name';
diff --git a/program/localization/pl_PL/labels.inc b/program/localization/pl_PL/labels.inc
index 654a2d9..56e7c83 100644
--- a/program/localization/pl_PL/labels.inc
+++ b/program/localization/pl_PL/labels.inc
@@ -281,10 +281,9 @@
 $labels['maintenance'] = 'Konserwacja';
 $labels['newmessage'] = 'Nowa wiadomość';
 $labels['listoptions'] = 'Opcje list';
-$labels['top_posting'] = 'Odpowiadaj powyżej treści wiadomości (niezalecane)';
-$labels['auto_add_sig'] = 'Automatycznie wstaw podpis';
-$labels['new_msg_only'] = 'tylko nowe wiadomości';
-$labels['reply_forward_only'] = 'tylko dla edycji, przekazywania i odpowiedzi';
-$labels['insertsig'] = 'Wstaw podpis';
+$labels['autoaddsignature'] = 'Automatycznie wstaw podpis';
+$labels['newmessageonly'] = 'tylko nowe wiadomości';
+$labels['replyandforwardonly'] = 'tylko dla edycji, przekazywania i odpowiedzi';
+$labels['insertsignature'] = 'Wstaw podpis';
 
 ?>
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 0f4b6ac..3a8a776 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -103,6 +103,7 @@
 }
 // set current mailbox in client environment
 $OUTPUT->set_env('mailbox', $IMAP->get_mailbox_name());
+$OUTPUT->set_env('sig_above', $CONFIG['sig_above']);
 $OUTPUT->set_env('top_posting', $CONFIG['top_posting']);
 
 // get reference message and set compose mode
@@ -117,12 +118,15 @@
   $compose_mode = RCUBE_COMPOSE_DRAFT;
 }
 
-if (!$CONFIG['show_sig'])
+$config_show_sig = $RCMAIL->config->get('show_sig', 1);
+if ($config_show_sig == 1)
   $OUTPUT->set_env('show_sig', true);
-else if ($CONFIG['show_sig'] == 2 && empty($compose_mode))
+else if ($config_show_sig == 2 && (empty($compose_mode) || $compose_mode == RCUBE_COMPOSE_EDIT || $compose_mode == RCUBE_COMPOSE_DRAFT))
   $OUTPUT->set_env('show_sig', true);
-else if ($CONFIG['show_sig'] == 3 && ($compose_mode == RCUBE_COMPOSE_REPLY || $compose_mode == RCUBE_COMPOSE_FORWARD))
+else if ($config_show_sig == 3 && ($compose_mode == RCUBE_COMPOSE_REPLY || $compose_mode == RCUBE_COMPOSE_FORWARD))
   $OUTPUT->set_env('show_sig', true);
+else
+  $OUTPUT->set_env('show_sig', false);
 
 if (!empty($msg_uid))
 {
@@ -518,18 +522,14 @@
 
 function rcmail_create_reply_body($body, $bodyIsHtml)
 {
-  global $MESSAGE;
-  
-  $rcmail = rcmail::get_instance();
+  global $RCMAIL, $MESSAGE;
 
-  if (! $bodyIsHtml)
-  {
+  if (!$bodyIsHtml) {
     // try to remove the signature
-    if (!$rcmail->config->get('top_posting') && ($sp = strrpos($body, '-- ')) !== false && ($sp == 0 || $body{$sp-1} == "\n"))
-      {
+    if ($RCMAIL->config->get('strip_existing_sig', true) && ($sp = strrpos($body, '-- ')) !== false && ($sp == 0 || $body{$sp-1} == "\n")) {
       if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
         $body = substr($body, 0, max(0, $sp-1));
-      }
+    }
 
     // soft-wrap message first
     $body = rcmail_wrap_quoted($body, 75);
@@ -541,15 +541,15 @@
       $a_lines = preg_split('/\r?\n/', $body);
 
       // add > to each line
-      for($n=0; $n<sizeof($a_lines); $n++) {
+      for ($n=0; $n<sizeof($a_lines); $n++) {
         if (strpos($a_lines[$n], '>')===0)
           $a_lines[$n] = '>'.$a_lines[$n];
         else
           $a_lines[$n] = '> '.$a_lines[$n];
-        }
+      }
  
       $body = join("\n", $a_lines);
-      }
+    }
 
     // add title line(s)
     $prefix = rc_wordwrap(sprintf("On %s, %s wrote:\n",
@@ -557,12 +557,11 @@
       $MESSAGE->get_header('from')), 76);
 
     $suffix = '';
-
-    if ($rcmail->config->get('top_posting'))
+    
+    if ($RCMAIL->config->get('top_posting'))
       $prefix = "\n\n\n" . $prefix;
   }
-  else
-  {
+  else {
     // save inline images to files
     $cid_map = rcmail_write_inline_attachments($MESSAGE);
     // set is_safe flag (we need this for html body washing)
@@ -573,12 +572,12 @@
     // build reply (quote content)
     $prefix = sprintf("On %s, %s wrote:<br />\n",
       $MESSAGE->headers->date,
-      htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $rcmail->output->get_charset()));
+      htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $RCMAIL->output->get_charset()));
     $prefix .= '<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">';
-
-    if ($rcmail->config->get('top_posting')) {
-	  $prefix = "<p></p>" . $prefix;
-	  $suffix = "</blockquote>";
+    
+    if ($RCMAIL->config->get('top_posting')) {
+      $prefix = "<p></p>" . $prefix;
+      $suffix = "</blockquote>";
     }
     else {
       $suffix = "</blockquote><p></p>";
diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index e451d57..30a7951 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -409,6 +409,7 @@
     
     $blocks = array(
       'main' => array('name' => Q(rcube_label('mainoptions'))),
+      'sig' => array('name' => Q(rcube_label('signatureoptions'))),
     );
 
     // Show checkbox for HTML Editor
@@ -443,7 +444,7 @@
       $select_param_folding->add(rcube_label('2047folding'), 2);
 
       $blocks['main']['options']['mime_param_folding'] = array(
-	'advanced' => true,
+        'advanced' => true,
         'title' => html::label($field_id, Q(rcube_label('mimeparamfolding'))),
         'content' => $select_param_folding->show($config['mime_param_folding']),
       );
@@ -451,25 +452,47 @@
     
     if (!isset($no_override['top_posting'])) {
       $field_id = 'rcmfd_top_posting';
-      $input_topposting = new html_checkbox(array('name' => '_top_posting', 'id' => $field_id, 'value' => 1));
+      $select_replymode = new html_select(array('name' => '_top_posting', 'id' => $field_id));
+      $select_replymode->add(rcube_label('replybottomposting'), 0);
+      $select_replymode->add(rcube_label('replytopposting'), 1);
 
       $blocks['main']['options']['top_posting'] = array(
-	'title' => html::label($field_id, Q(rcube_label('top_posting'))),
-	'content' => $input_topposting->show($config['top_posting']?1:0),
+        'title' => html::label($field_id, Q(rcube_label('whenreplying'))),
+        'content' => $select_replymode->show($config['top_posting']?1:0),
       );
     }
 
     if (!isset($no_override['show_sig'])) {
       $field_id = 'rcmfd_show_sig';
       $select_show_sig = new html_select(array('name' => '_show_sig', 'id' => $field_id));
-      $select_show_sig->add(rcube_label('always'), 0);
-      $select_show_sig->add(rcube_label('never'), 1);
-      $select_show_sig->add(rcube_label('new_msg_only'), 2);
-      $select_show_sig->add(rcube_label('reply_forward_only'), 3);
+      $select_show_sig->add(rcube_label('never'), 0);
+      $select_show_sig->add(rcube_label('always'), 1);
+      $select_show_sig->add(rcube_label('newmessageonly'), 2);
+      $select_show_sig->add(rcube_label('replyandforwardonly'), 3);
 
-      $blocks['main']['options']['show_sig'] = array(
-	'title' => html::label($field_id, Q(rcube_label('auto_add_sig'))),
-        'content' => $select_show_sig->show(intval($config['show_sig'])),
+      $blocks['sig']['options']['show_sig'] = array(
+        'title' => html::label($field_id, Q(rcube_label('autoaddsignature'))),
+        'content' => $select_show_sig->show($config['show_sig']),
+      );
+    }
+
+    if (!isset($no_override['sig_above'])) {
+      $field_id = 'rcmfd_sig_above';
+      $input_sigabove = new html_checkbox(array('name' => '_sig_above', 'id' => $field_id, 'value' => 1));
+
+      $blocks['sig']['options']['sig_above'] = array(
+        'title' => html::label($field_id, Q(rcube_label('replysignatureabove'))),
+        'content' => $input_sigabove->show($config['sig_above']?1:0),
+      );
+    }
+
+    if (!isset($no_override['strip_existing_sig'])) {
+      $field_id = 'rcmfd_strip_existing_sig';
+      $input_stripexistingsig = new html_checkbox(array('name' => '_strip_existing_sig', 'id' => $field_id, 'value' => 1));
+
+      $blocks['sig']['options']['strip_existing_sig'] = array(
+        'title' => html::label($field_id, Q(rcube_label('replyremovesignature'))),
+        'content' => $input_stripexistingsig->show($config['strip_existing_sig']?1:0),
       );
     }
 
diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc
index e38a695..824e8f6 100644
--- a/program/steps/settings/save_prefs.inc
+++ b/program/steps/settings/save_prefs.inc
@@ -62,8 +62,10 @@
       'htmleditor'         => isset($_POST['_htmleditor']) ? TRUE : FALSE,
       'draft_autosave'     => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0,
       'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0,
-      'show_sig'           => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 0,
-      'top_posting'        => isset($_POST['_top_posting']) ? TRUE : FALSE,
+      'show_sig'           => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
+      'top_posting'        => !empty($_POST['_top_posting']),
+      'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
+      'sig_above'          => isset($_POST['_sig_above']) && !empty($_POST['_top_posting']),
     );
 
   break;
diff --git a/skins/default/images/mail_toolbar.gif b/skins/default/images/mail_toolbar.gif
index 4e2cecb..cceeced 100644
--- a/skins/default/images/mail_toolbar.gif
+++ b/skins/default/images/mail_toolbar.gif
Binary files differ
diff --git a/skins/default/images/mail_toolbar.png b/skins/default/images/mail_toolbar.png
index e6f8029..87fbaf2 100644
--- a/skins/default/images/mail_toolbar.png
+++ b/skins/default/images/mail_toolbar.png
Binary files differ
diff --git a/skins/default/templates/compose.html b/skins/default/templates/compose.html
index 35b1989..661ec4d 100644
--- a/skins/default/templates/compose.html
+++ b/skins/default/templates/compose.html
@@ -20,7 +20,7 @@
       <roundcube:button command="send" type="link" class="buttonPas send" classAct="button send" classSel="button sendSel" title="sendmessage" content=" " />
       <roundcube:button command="spellcheck" type="link" class="buttonPas spellcheck" classAct="button spellcheck" classSel="button spellcheckSel" title="checkspelling" content=" " />
       <roundcube:button command="add-attachment" type="link" class="buttonPas attach" classAct="button attach" classSel="button attachSel" title="addattachment" content=" " />
-      <roundcube:button command="insert-sig" type="link" class="buttonPas insertsig" classAct="button insertsig" classSel="button insertsigSel" title="insertsig" content=" " />
+      <roundcube:button command="insert-sig" type="link" class="buttonPas insertsig" classAct="button insertsig" classSel="button insertsigSel" title="insertsignature" content=" " />
       <roundcube:button command="savedraft" type="link" class="buttonPas savedraft" classAct="button savedraft" classSel="button savedraftSel" title="savemessage" content=" " />
       <roundcube:container name="toolbar" id="compose-toolbar" />
     </td>

--
Gitblit v1.9.1