From a63f14ec4045e82f47b237663bcf09939a0eadc5 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Sat, 29 Aug 2015 01:52:57 -0400 Subject: [PATCH] Emoticons-related code refactoring --- program/steps/mail/compose.inc | 41 +++++++++++++++++++++++++++-------------- 1 files changed, 27 insertions(+), 14 deletions(-) diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 505f5d6..85e5e27 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -317,7 +317,8 @@ // #1486037: remove "mailto:" prefix $COMPOSE['param']['to'] = preg_replace('/^mailto:/i', '', $mailto[0]); // #1490346: decode the recipient address - $COMPOSE['param']['to'] = urldecode($COMPOSE['param']['to']); + // #1490510: use raw encoding for correct "+" character handling as specified in RFC6068 + $COMPOSE['param']['to'] = rawurldecode($COMPOSE['param']['to']); // Supported case-insensitive tokens in mailto URL $url_tokens = array('to', 'cc', 'bcc', 'reply-to', 'in-reply-to', 'references', 'subject', 'body'); @@ -498,8 +499,7 @@ $text = $html = $sql_arr['signature']; if ($sql_arr['html_signature']) { - $h2t = new rcube_html2text($html, false, true); - $text = trim($h2t->get_text()); + $text = $RCMAIL->html2text($html); } else { $t2h = new rcube_text2html($text, false); @@ -873,9 +873,8 @@ if ($part->ctype_secondary == 'html') { // use html part if it has been used for message (pre)viewing // decrease line length for quoting - $len = $COMPOSE['mode'] == RCUBE_COMPOSE_REPLY ? $LINE_LENGTH-2 : $LINE_LENGTH; - $txt = new rcube_html2text($body, false, true, $len); - $body = $txt->get_text(); + $len = $COMPOSE['mode'] == RCUBE_COMPOSE_REPLY ? $LINE_LENGTH-2 : $LINE_LENGTH; + $body = $RCMAIL->html2text($body, array('width' => $len)); } else { if ($part->ctype_secondary == 'plain' && $part->ctype_parameters['format'] == 'flowed') { @@ -1499,6 +1498,27 @@ } } +/** + * Creates reply subject by removing common subject + * prefixes/suffixes from the original message subject + */ +function rcmail_reply_subject($subject) +{ + $subject = trim($subject); + + // replace Re:, Re[x]:, Re-x (#1490497) + $prefix = '/^(re:|re\[\d\]:|re-\d:)\s*/i'; + do { + $subject = preg_replace($prefix, '', $subject, -1, $count); + } + while ($count); + + // replace (was: ...) (#1489375) + $subject = preg_replace('/\s*\([wW]as:[^\)]+\)\s*$/', '', $subject); + + return 'Re: ' . $subject; +} + function rcmail_compose_subject($attrib) { global $MESSAGE, $COMPOSE; @@ -1521,13 +1541,7 @@ } // create a reply-subject else if ($COMPOSE['mode'] == RCUBE_COMPOSE_REPLY) { - if (preg_match('/^re:/i', $MESSAGE->subject)) - $subject = $MESSAGE->subject; - else - $subject = 'Re: '.$MESSAGE->subject; - - // replace (was: ...) (#1489375) - $subject = preg_replace('/\s*\([wW]as:[^\)]+\)\s*$/', '', $subject); + $subject = rcmail_reply_subject($MESSAGE->subject); } // create a forward-subject else if ($COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD) { @@ -1547,7 +1561,6 @@ return $out; } - function rcmail_compose_attachment_list($attrib) { -- Gitblit v1.9.1