summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-05-18 09:01:12 +0200
committerAleksander Machniak <alec@alec.pl>2014-05-18 09:01:12 +0200
commit59b765d83927cb9e81bf69656db3a7dbdc1b1b41 (patch)
tree82e2bd73653dd8e53c3f5af29ac69bf0105a1fa0
parent25804ec9cd69705f1b991ccc163e9f1c845fc3e3 (diff)
Don't remove links when html signature is converted to text (#1489621)
Fix so when switching editor mode original version of signature is used (#1488849)
-rw-r--r--CHANGELOG2
-rw-r--r--program/js/app.js62
-rw-r--r--program/steps/mail/compose.inc2
-rw-r--r--tests/Framework/Html2text.php5
-rw-r--r--tests/Framework/Text2Html.php1
5 files changed, 64 insertions, 8 deletions
diff --git a/CHANGELOG b/CHANGELOG
index db21586e7..27286e8e5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -20,6 +20,8 @@ CHANGELOG Roundcube Webmail
- Add configurable LDAP_OPT_DEREF option (#1489864)
- Optimize some framed pages content for better performance (#1489792)
- Improve text messages display and conversion to HTML (#1488937)
+- Don't remove links when html signature is converted to text (#1489621)
+- Fix so when switching editor mode original version of signature is used (#1488849)
- Fix mbox files import
- Fix unintentional draft autosave request if autosave is disabled (#1489882)
- Fix malformed References: header in send/saved mail (#1489891)
diff --git a/program/js/app.js b/program/js/app.js
index 97b8192b2..24d1f19e7 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3439,10 +3439,27 @@ function rcube_webmail()
{
this.stop_spellchecking();
- var input = $('#' + props.id);
+ var ed, curr, content, result,
+ // these non-printable chars are not removed on text2html and html2text
+ // we can use them as temp signature replacement
+ sig_mark = "\u0002\u0003",
+ input = $('#' + props.id),
+ signature = this.env.identity ? this.env.signatures[this.env.identity] : null,
+ is_sig = signature && signature.text && signature.text.length > 1;
+
+ if (props.mode == 'html') {
+ content = input.val();
+
+ // replace current text signature with temp mark
+ if (is_sig)
+ content = content.replace(signature.text, sig_mark);
+
+ // convert to html
+ result = this.plain2html(content, function(data) {
+ // replace signature mark with html version of the signature
+ if (is_sig)
+ data = data.replace(sig_mark, '<div id="_rc_sig">' + signature.html + '</div>');
- if (props.mode == 'html')
- this.plain2html(input.val(), function(data) {
input.val(data);
tinyMCE.execCommand('mceAddControl', false, props.id);
@@ -3451,13 +3468,43 @@ function rcube_webmail()
$(tinyMCE.get(props.id).getBody()).css('font-family', ref.env.default_font);
}, 500);
});
- else
- this.html2plain(tinyMCE.get(props.id).getContent(), function(data) {
+ }
+ else {
+ ed = tinyMCE.get(props.id);
+
+ if (is_sig) {
+ // get current version of signature, we'll need it in
+ // case of html2text conversion abort
+ if (curr = ed.dom.get('_rc_sig'))
+ curr = curr.innerHTML;
+
+ // replace current signature with some non-printable characters
+ // we use non-printable characters, because this replacement
+ // is visible to the user
+ // doing this after getContent() would be hard
+ ed.dom.setHTML('_rc_sig', sig_mark);
+ }
+
+ // get html content
+ content = ed.getContent();
+
+ // convert html to text
+ result = this.html2plain(content, function(data) {
tinyMCE.execCommand('mceRemoveControl', false, props.id);
+
+ // replace signture mark with text version of the signature
+ if (is_sig)
+ data = data.replace(sig_mark, "\n" + signature.text);
+
input.val(data);
});
- return true;
+ // bring back current signature
+ if (!result && curr)
+ ed.dom.setHTML('_rc_sig', curr);
+ }
+
+ return result;
};
this.insert_response = function(key)
@@ -6834,7 +6881,8 @@ function rcube_webmail()
|| (format != 'html' && !(text.replace(/\xC2\xA0|\s/g, '')).length)
) {
// without setTimeout() here, textarea is filled with initial (onload) content
- setTimeout(function() { if (func) func(''); }, 50);
+ if (func)
+ setTimeout(function() { func(''); }, 50);
return true;
}
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 0ceb85db2..a3eb4b8a3 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -611,7 +611,7 @@ function rcmail_compose_header_from($attrib)
$text = $html = $sql_arr['signature'];
if ($sql_arr['html_signature']) {
- $h2t = new rcube_html2text($sql_arr['signature'], false, false);
+ $h2t = new rcube_html2text($sql_arr['signature'], false, true);
$text = trim($h2t->get_text());
}
else {
diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php
index 2c7759f7d..76b1f16cd 100644
--- a/tests/Framework/Html2text.php
+++ b/tests/Framework/Html2text.php
@@ -41,6 +41,11 @@ class rc_html2text extends PHPUnit_Framework_TestCase
'in' => '<b><strong>&#347;</strong></b>',
'out' => 'Ś',
),
+ 6 => array(
+ 'title' => 'Don\'t remove non-printable chars',
+ 'in' => chr(0x002).chr(0x003),
+ 'out' => chr(0x002).chr(0x003),
+ ),
);
}
diff --git a/tests/Framework/Text2Html.php b/tests/Framework/Text2Html.php
index 8d091d5c9..8d1325dee 100644
--- a/tests/Framework/Text2Html.php
+++ b/tests/Framework/Text2Html.php
@@ -63,6 +63,7 @@ class Framework_Text2Html extends PHPUnit_Framework_TestCase
$data[] = array(">aaaa \n>aaaa", "<blockquote>aaaa aaaa</blockquote>", $options);
$data[] = array(">aaaa\n>aaaa", "<blockquote>aaaa<br>aaaa</blockquote>", $options);
$data[] = array(">aaaa \n>bbbb\ncccc dddd", "<blockquote>aaaa bbbb</blockquote>cccc_dddd", $options);
+ $data[] = array(chr(0x002).chr(0x003), chr(0x002).chr(0x003), $options);
$options['flowed'] = false;
$options['wrap'] = true;