Browse Source

Fixes #3233 - ProtonMail Bridge error: Can’t use Channel::Driver::Imap

Mantas 4 years ago
parent
commit
54c694689f
1 changed files with 22 additions and 13 deletions
  1. 22 13
      app/models/channel/driver/imap.rb

+ 22 - 13
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