Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/mail#36 - Fix invalid unicode characters in bounce processing #13396

Merged
merged 3 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CRM/Mailing/Event/BAO/Bounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public static function create(&$params) {
}
}

// replace any invalid unicode characters with replacement characters
$params['bounce_reason'] = mb_convert_encoding($params['bounce_reason'], 'UTF-8', 'UTF-8');

// CRM-11989
$params['bounce_reason'] = mb_strcut($params['bounce_reason'], 0, 254);

Expand Down
17 changes: 15 additions & 2 deletions tests/phpunit/CRM/Utils/Mail/EmailProcessorTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

/**
* Class CRM_Utils_EmailProcessorTest
* Class CRM_Utils_Mail_EmailProcessorTest
* @group headless
*/

class CRM_Utils_EmailProcessorTest extends CiviUnitTestCase {
class CRM_Utils_Mail_EmailProcessorTest extends CiviUnitTestCase {

/**
* Event queue record.
Expand Down Expand Up @@ -54,6 +54,19 @@ public function testBounceProcessing() {
$this->checkMailingBounces(1);
}

/**
* Test the job processing function can handle invalid characters.
*/
public function testBounceProcessingInvalidCharacter() {
$this->setUpMailing();
$mail = 'test_invalid_character.eml';

copy(__DIR__ . '/data/bounces/' . $mail, __DIR__ . '/data/mail/' . $mail);
$this->callAPISuccess('job', 'fetch_bounces', array());
$this->assertFalse(file_exists(__DIR__ . '/data/mail/' . $mail));
$this->checkMailingBounces(1);
}

/**
* Tests that a multipart related email does not cause pain & misery & fatal errors.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Delivered-To: my@example.com
Received: by 10.2.13.84 with SMTP id 1234567890;
Wed, 19 Dec 2018 10:01:11 +0100 (CET)
Return-Path: <>
From: Postmaster@example.com
To: b.2.1.aaaaaaaaaaaaaaaa@example.com
Subject: Delivery Status Notification (Failure)
Message-ID: <abc.def.fhi@example.com>
Date: Wed, 19 Dec 2018 10:01:07 +0100
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status; boundary="==IFJRGLKFGIR18927894UHRUHIHD"

--==IFJRGLKFGIR18927894UHRUHIHD
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Your message

Subject: test

was not delivered to:

my@example.com

because:

Benutzer my (my@example.com) nicht im Domino-Verzeichnis aufgef=FChrt


--==IFJRGLKFGIR18927894UHRUHIHD
Content-Type: message/delivery-status

Reporting-MTA: dns;srv.example.com

Final-Recipient: rfc822;my@example.com
Action: failed
Status: 5.0.0
Diagnostic-Code: X-Notes; Benutzer my (my@example.com) nicht im Domino-Verzeichnis aufgef�hrt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The invalid character is a \x81 in aufgefhrt between f and h.


--==IFJRGLKFGIR18927894UHRUHIHD