From 37cfa0a43b542add71b7d8ae9cfcae345448835c Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 16 Dec 2019 15:13:37 +0100 Subject: [PATCH 1/2] Fix malformed characters in HTML message with charset meta tag not in head (#7116) --- CHANGELOG | 1 + program/steps/mail/func.inc | 10 ++++------ tests/MailFunc.php | 5 +++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1ec2a43f6..172b853e5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -31,6 +31,7 @@ CHANGELOG Roundcube Webmail - Fix bug where 'text' attribute on body tag was ignored when displaying HTML message (#7109) - Fix bug where next message wasn't displayed after delete in List mode (#7096) - Fix so number of contacts in a group is not limited to 200 when redirecting to mail composer from Contacts (#6972) +- Fix malformed characters in HTML message with charset meta tag not in head (#7116) RELEASE 1.4.1 ------------- diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index ae396cff1..094e877dc 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -839,12 +839,10 @@ function rcmail_wash_html($html, $p, $cid_replaces = array()) // washtml's DOMDocument methods cannot work without that $meta = ''; - // remove old meta tag and add the new one, making sure - // that it is placed in the head (#1488093) - $html = preg_replace('/]+charset=[a-z0-9_"-]+[^>]*>/Ui', $meta, $html, -1, $rcount); - if (!$rcount) { - $html = preg_replace('/(]*>)/Ui', '\\1'.$meta, $html, -1, $rcount); - } + // remove old meta tag and add the new one, making sure that it is placed in the head (#3510, #7116) + $html = preg_replace('/]+charset=[a-z0-9_"-]+[^>]*>/Ui', '', $html, -1); + $html = preg_replace('/(]*>)/Ui', '\\1'.$meta, $html, -1, $rcount); + if (!$rcount) { // Note: HTML without tag may still be a valid input (#6713) if (($pos = stripos($html, 'assertTrue(strpos($washed, "$meta") === 0, "Meta tag insertion (5)"); + + $body = 'Test1
Test2'; + $washed = rcmail_wash_html($body, $args); + $this->assertTrue(strpos($washed, "$meta") === 0, "Meta tag insertion (6)"); + $this->assertTrue(strpos($washed, "Test2") > 0, "Meta tag insertion (7)"); } /** From 52caed0d66532d167e3acf1d11237b3c1d7b451a Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 16 Dec 2019 15:19:42 +0100 Subject: [PATCH 2/2] Remove optional argument leftover --- program/steps/mail/func.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 094e877dc..ed75b2d8a 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -840,7 +840,7 @@ function rcmail_wash_html($html, $p, $cid_replaces = array()) $meta = ''; // remove old meta tag and add the new one, making sure that it is placed in the head (#3510, #7116) - $html = preg_replace('/]+charset=[a-z0-9_"-]+[^>]*>/Ui', '', $html, -1); + $html = preg_replace('/]+charset=[a-z0-9_"-]+[^>]*>/Ui', '', $html); $html = preg_replace('/(]*>)/Ui', '\\1'.$meta, $html, -1, $rcount); if (!$rcount) {