From 54c694689f3747697994cd940320513ac527a933 Mon Sep 17 00:00:00 2001 From: Mantas Date: Wed, 4 Nov 2020 13:54:43 +0200 Subject: [PATCH] =?UTF-8?q?Fixes=20#3233=20-=20ProtonMail=20Bridge=20error?= =?UTF-8?q?:=20Can=E2=80=99t=20use=20Channel::Driver::Imap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/channel/driver/imap.rb | 35 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/app/models/channel/driver/imap.rb b/app/models/channel/driver/imap.rb index bf089846d..bdeb92024 100644 --- a/app/models/channel/driver/imap.rb +++ b/app/models/channel/driver/imap.rb @@ -134,19 +134,12 @@ example @imap.select(folder) end - # sort messages by date on server (if not supported), if not fetch messages via search (first in, first out) - filter = ['ALL'] - if keep_on_server && check_type != 'check' && check_type != 'verify' - filter = %w[NOT SEEN] - end - - message_ids = nil - timeout(6.minutes) do - - message_ids = @imap.sort(['DATE'], filter, 'US-ASCII') - rescue - message_ids = @imap.search(filter) - + message_ids = timeout(6.minutes) do + if keep_on_server && check_type != 'check' && check_type != 'verify' + fetch_unread_message_ids + else + fetch_all_message_ids + end end # check mode only @@ -369,6 +362,22 @@ example } end + def fetch_all_message_ids + fetch_message_ids %w[ALL] + end + + def fetch_unread_message_ids + fetch_message_ids %w[NOT SEEN] + rescue + fetch_message_ids %w[UNSEEN] + end + + def fetch_message_ids(filter) + @imap.sort(['DATE'], filter, 'US-ASCII') + rescue + @imap.search(filter) + end + def disconnect return if !@imap