From b29b2a4490ed81fb757ab2ccd76e80e1d16cef34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Sch=C3=BCttler?= Date: Tue, 8 Jan 2019 13:55:50 +0100 Subject: [PATCH] Replace 4-byte utf8 characters with unicode replacement character --- CRM/Mailing/Event/BAO/Bounce.php | 4 ++++ .../CRM/Utils/Mail/data/bounces/test_utf8mb4_character.txt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CRM/Mailing/Event/BAO/Bounce.php b/CRM/Mailing/Event/BAO/Bounce.php index a3f5af0062..9a162c83de 100644 --- a/CRM/Mailing/Event/BAO/Bounce.php +++ b/CRM/Mailing/Event/BAO/Bounce.php @@ -80,6 +80,10 @@ class CRM_Mailing_Event_BAO_Bounce extends CRM_Mailing_Event_DAO_Bounce { // replace any invalid unicode characters with replacement characters $params['bounce_reason'] = mb_convert_encoding($params['bounce_reason'], 'UTF-8', 'UTF-8'); + // dev/mail#37 Replace 4-byte utf8 characaters with the unicode replacement character + // while CiviCRM does not support utf8mb4 for MySQL + $params['bounce_reason'] = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $params['bounce_reason']); + // CRM-11989 $params['bounce_reason'] = mb_strcut($params['bounce_reason'], 0, 254); diff --git a/tests/phpunit/CRM/Utils/Mail/data/bounces/test_utf8mb4_character.txt b/tests/phpunit/CRM/Utils/Mail/data/bounces/test_utf8mb4_character.txt index 938669939d..f97fdd864c 100644 --- a/tests/phpunit/CRM/Utils/Mail/data/bounces/test_utf8mb4_character.txt +++ b/tests/phpunit/CRM/Utils/Mail/data/bounces/test_utf8mb4_character.txt @@ -12,4 +12,4 @@ Auto-Submitted: auto-replied (vacation) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 -SSBhbSBvbiB2YWNhdGlvbiDwn4y0 \ No newline at end of file +8J+MtCBJIGFtIG9uIHZhY2F0aW9uIPCfjLQ= \ No newline at end of file -- 2.25.1