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:

/app/bundles/EmailBundle/MonitoredEmail/Processor/Bounce/DsnParser.php
/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php:
/app/bundles/EmailBundle/MonitoredEmail/Processor/Bounce.php

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_ALL)
{
if (preg_match('/'.self::CRITERIA_UID.' ((\d+):(\d+|\*))/', $criteria, $matches)) {
// PHP imap_search does not support UID n:* so use imap_fetch_overview instead
$messages = imap_fetch_overview($this->getImapStream(), $matches[1], FT_UID);

to this:

public function searchMailbox($criteria = self::CRITERIA_ALL)
{
$criteria = 'SINCE "'.date("Y-m-d").'"';
#$criteria = 'ALL';
if (preg_match('/'.self::CRITERIA_UID.' ((\d+):(\d+|\*))/', $criteria, $matches)) {
// PHP imap_search does not support UID n:* so use imap_fetch_overview instead
$messages = imap_fetch_overview($this->getImapStream(), $matches[1], FT_UID);

This will check all the emails received today

Update 2019/10/02

To have the program scan the contents of the bounced email correctly you need to edit the BodyParser.php accordingly, this is usually on the following destination:

../app/bundles/EmailBundle/MonitoredEmail/Processor/Bounce/BodyParser.php

Leave a Reply

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