Skip to content

Commit

Permalink
Merge pull request #6376 from mautic-inc/bug.campaign-replyto-fix
Browse files Browse the repository at this point in the history
Fixed fetching messages for campaign replies
  • Loading branch information
escopecz committed Sep 24, 2018
2 parents c813cc7 + c124868 commit e908e87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 9 additions & 3 deletions app/bundles/EmailBundle/EventListener/ProcessReplySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ public function onEmailConfig(MonitoredEmailEvent $event)
*/
public function onEmailPreFetch(ParseEmailEvent $event)
{
$lastFetch = $this->cache->get(self::CACHE_KEY);
if ($lastFetch) {
$event->setCriteriaRequest(self::BUNDLE, self::FOLDER_KEY, Mailbox::CRITERIA_UID.' '.$lastFetch.':*');
if (!$lastFetchedUID = $this->cache->get(self::CACHE_KEY)) {
return;
}

$startingUID = $lastFetchedUID + 1;

// Using * will return the last UID even if the starting UID doesn't exist so let's just use a highball number
$endingUID = $startingUID + 1000000000;

$event->setCriteriaRequest(self::BUNDLE, self::FOLDER_KEY, Mailbox::CRITERIA_UID." $startingUID:$endingUID");
}

/**
Expand Down
14 changes: 12 additions & 2 deletions app/bundles/EmailBundle/MonitoredEmail/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,19 @@ public function fetchUnread($folder = null)
*/
public function searchMailbox($criteria = self::CRITERIA_ALL)
{
$mailsIds = imap_search($this->getImapStream(), $criteria, SE_UID);
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);

return $mailsIds ? $mailsIds : [];
$mailIds = [];
foreach ($messages as $message) {
$mailIds[] = $message->uid;
}
} else {
$mailIds = imap_search($this->getImapStream(), $criteria, SE_UID);
}

return $mailIds ? $mailIds : [];
}

/**
Expand Down

0 comments on commit e908e87

Please sign in to comment.