From 52043bfdc5163e6d9c71209b5b6f4a5802f8267c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 2 Jun 2016 16:00:45 +0200 Subject: [PATCH] Fetch older emails first (to keep possibility for references header follow up detection). --- app/models/channel/driver/imap.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/channel/driver/imap.rb b/app/models/channel/driver/imap.rb index 65324f27b..1fa7b16b8 100644 --- a/app/models/channel/driver/imap.rb +++ b/app/models/channel/driver/imap.rb @@ -85,7 +85,12 @@ returns @imap.select(options[:folder]) end - message_ids = @imap.search(['ALL']) + begin + message_ids = @imap.sort(['DATE'], ['ALL'], 'US-ASCII') + rescue => e + Rails.logger.error "Unable to use imap sort: #{e.inspect}, use imap search now" + message_ids = @imap.search(['ALL']) + end # check mode only if check_type == 'check'