diff --git a/app/bundles/EmailBundle/EventListener/ProcessReplySubscriber.php b/app/bundles/EmailBundle/EventListener/ProcessReplySubscriber.php index 25c6460e05b..3de35f470c5 100644 --- a/app/bundles/EmailBundle/EventListener/ProcessReplySubscriber.php +++ b/app/bundles/EmailBundle/EventListener/ProcessReplySubscriber.php @@ -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"); } /** diff --git a/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php b/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php index d917a853b16..44827dba4f7 100644 --- a/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php +++ b/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php @@ -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 : []; } /**