Mautic: Clear Bounces not working correctly

Some emails are parsed, while others are not. It depends on the format of the email. Here are some highlights:

Files of interest:


The process as I understand it is the following:

Step 1. 

On Mailbox.php you define what emails are considered for un-subscription. The default criteria es UNSEEN, which the process will consider only not unread emails to then parse and consider to unsubscribe. 

I changed the criteria to ALL, which will scan ALL emails on the Inbox of your mail (I did this because I use a dedicated email to send, and clear the Inbox frequently. It is not recommended you use the ALL criteria on a big inbox because it will take forever. 

To accomplish this you need to change this code on Mailbox.php:

public function searchMailbox($criteria = self::CRITERIA_UNSEEN)
$mailsIds = imap_search($this->getImapStream(), $criteria, SE_UID);
return $mailsIds ? $mailsIds : [];


public function searchMailbox($criteria = self::ALL)
$mailsIds = imap_search($this->getImapStream(), 'ALL', SE_UID);
return $mailsIds ? $mailsIds : [];

Step 2.

Once you have the ids, it goes to Bounce.php, but the code dies in:

$bounce = (new Parser($this->message))->parse();

This line sends the message texts to DsnParser.php to have them parsed and the relevant information resolved. But for the lines that do not work there's a null return from DsnParser.php

The problem arises on DsnParser.php on the following lines,

$dsnMessage = ($message->dsnMessage) ? $message->dsnMessage : $message->textPlain;
$dsnReport = $message->dsnReport;

Were for some reason, dsnReport comes back empty for some format of emails.

I'm stuck there, not sure how the dsnReport works...

Leave a Reply

Your email address will not be published. Required fields are marked *