Skip to content

Commit

Permalink
Merge pull request #13396 from tschuettler/36-dev-mail
Browse files Browse the repository at this point in the history
dev/mail#36 - Fix invalid unicode characters in bounce processing
  • Loading branch information
eileenmcnaughton authored Jan 4, 2019
2 parents 621f12d + 67991a1 commit 313a421
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
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
--==IFJRGLKFGIR18927894UHRUHIHD

0 comments on commit 313a421

Please sign in to comment.