Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed fetching messages for campaign replies #6376

Merged
merged 1 commit into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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