From 74728935122fe35ed97c40092080cc7dfd4b7052 Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Mon, 06 Dec 2010 06:13:55 -0500 Subject: [PATCH] - Fix plaintext versions of HTML messages don't contain placeholders for emotions (#1485206) --- CHANGELOG | 1 + program/include/main.inc | 38 ++++++++++++++++++++++++++++++++++++++ program/steps/utils/html2text.inc | 7 ++++++- program/steps/mail/sendmail.inc | 12 ++++++++---- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8f9b0b5..312c4a2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ - Add possibility to move a subfolder into root folder (#1486791) - Fix copying all messages in a folder copies only messages from current page - Improve performance of moving or copying of all messages in a folder +- Fix plaintext versions of HTML messages don't contain placeholders for emotions (#1485206) RELEASE 0.5-BETA ---------------- diff --git a/program/include/main.inc b/program/include/main.inc index 6d4e19c..ad0bccd 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -1647,6 +1647,43 @@ /** + * Replaces TinyMCE's emoticon images with plain-text representation + * + * @param string HTML content + * @return string HTML content + */ +function rcmail_replace_emoticons($html) +{ + $emoticons = array( + '8-)' => 'smiley-cool', + ':-#' => 'smiley-foot-in-mouth', + ':-*' => 'smiley-kiss', + ':-X' => 'smiley-sealed', + ':-P' => 'smiley-tongue-out', + ':-@' => 'smiley-yell', + ":'(" => 'smiley-cry', + ':-(' => 'smiley-frown', + ':-D' => 'smiley-laughing', + ':-)' => 'smiley-smile', + ':-/' => 'smiley-undecided', + ':-X' => 'smiley-embarassed', + '0:-)' => 'smiley-innocent', + ':-|' => 'smiley-money-mouth', + ':-0' => 'smiley-surprised', + ';-)' => 'smiley-wink', + ); + + foreach ($emoticons as $idx => $file) { + // <img title="Cry" src="http://.../program/js/tiny_mce/plugins/emotions/img/smiley-cry.gif" border="0" alt="Cry" /> + $search[] = '/<img title="[a-z ]+" src="https?:\/\/[a-z0-9_.\/-]+\/tiny_mce\/plugins\/emotions\/img\/'.$file.'.gif"[^>]+\/>/i'; + $replace[] = $idx; + } + + return preg_replace($search, $replace, $html); +} + + +/** * Check if working in SSL mode * * @param integer HTTPS port number @@ -1881,3 +1918,4 @@ flush(); } } + diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 95b4909..a796c7b 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -70,7 +70,7 @@ function rcmail_get_identity($id) { global $USER, $OUTPUT; - + if ($sql_arr = $USER->get_identity($id)) { $out = $sql_arr; $out['mailto'] = $sql_arr['email']; @@ -100,7 +100,7 @@ // remove any null-byte characters before parsing $body = preg_replace('/\x00/', '', $body); - + $searchstr = 'program/js/tiny_mce/plugins/emotions/img/'; $offset = 0; @@ -192,6 +192,7 @@ return implode(', ', $result); } + /****** compose message ********/ @@ -441,13 +442,16 @@ $MAIL_MIME->setHTMLBody($plugin['body']); + // replace emoticons + $plugin['body'] = rcmail_replace_emoticons($plugin['body']); + // add a plain text version of the e-mail as an alternative part. $h2t = new html2text($plugin['body'], false, true, 0); $plainTextPart = rc_wordwrap($h2t->get_text(), $LINE_LENGTH, "\r\n"); $plainTextPart = wordwrap($plainTextPart, 998, "\r\n", true); if (!$plainTextPart) { - // empty message body breaks attachment handling in drafts - $plainTextPart = "\r\n"; + // empty message body breaks attachment handling in drafts + $plainTextPart = "\r\n"; } else { // make sure all line endings are CRLF (#1486712) diff --git a/program/steps/utils/html2text.inc b/program/steps/utils/html2text.inc index ef74ec4..15c6a52 100644 --- a/program/steps/utils/html2text.inc +++ b/program/steps/utils/html2text.inc @@ -19,7 +19,12 @@ */ -$converter = new html2text($HTTP_RAW_POST_DATA); +$html = $HTTP_RAW_POST_DATA; + +// Replace emoticon images with its text representation +$html = rcmail_replace_emoticons($html); + +$converter = new html2text($html); header('Content-Type: text/plain; charset=UTF-8'); print rtrim($converter->get_text()); -- Gitblit v1.9.1