Skip to content

Commit

Permalink
try to handle soft bounces
Browse files Browse the repository at this point in the history
  • Loading branch information
amrfayad committed Sep 5, 2016
1 parent 4b0ff75 commit 28f4c2b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Bounces.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function getEmailsThatBounced() {
$response = array();
$headers = @imap_headers($this->c);
$max_message_count = sizeof($headers);

$count = 1;
while ($count <= $max_message_count) {
$headerinfo = @imap_headerinfo($this->c, $count);
Expand All @@ -88,17 +87,19 @@ function getEmailsThatBounced() {
$body = @imap_body($this->c, $count);
$user_id = $this->getUserId($body);
$campaign_id = $this->getCampaignId($body);
if ($user_id && $campaign_id) {
$bounce_type = $this->getBounceType($body);
//if ($user_id && $campaign_id) {
$this->messagesFound[] = $count;
$response[] = array(
'user_id' => $user_id,
'campaign_id' => $campaign_id
'campaign_id' => $campaign_id,
'bounce_type' => $bounce_type
);
}
// }
}

$count++;
}
}die();
return $response;
}
function getCampaignId($body) {
Expand Down Expand Up @@ -152,4 +153,15 @@ function end() {
imap_close($this->c);
}

function getBounceType($body)
{
$rules = config('campaigns-mail-tracker.bounce-types');
foreach ($rules as $rule)
{
if (preg_match($rule['regex'], $body)) {
return $rule['bounceType'];
}
}
return null;
}
}

0 comments on commit 28f4c2b

Please sign in to comment.