]> git.cworth.org Git - sup/commitdiff
fixed login to first try CRAM-MD5 auth, then login auth, then plain login
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 6 Jan 2007 15:55:30 +0000 (15:55 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 6 Jan 2007 15:55:30 +0000 (15:55 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@212 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/imap.rb

index a3dca4775939d54b2f9902a679c9f4f5014f99ee..c123393cfce4f06f2710b4f218db5fd5320a5966 100644 (file)
@@ -112,7 +112,17 @@ class IMAP < Source
         #raise Net::IMAP::ByeResponseError, "simulated imap failure"
         @imap = Net::IMAP.new host, port, ssl?
         say "Logging in..."
-        @imap.authenticate 'LOGIN', @username, @password
+        begin
+          @imap.authenticate 'CRAM-MD5', @username, @password
+        rescue Net::IMAP::BadResponseError, Net::IMAP::NoResponseError => e
+          say "CRAM-MD5 authentication failed: #{e.class}"
+          begin
+            @imap.authenticate 'LOGIN', @username, @password
+          rescue Net::IMAP::BadResponseError, Net::IMAP::NoResponseError => e
+            say "LOGIN authentication failed: #{e.class}"
+            @imap.login @username, @password
+          end
+        end
         scan_mailbox
         say "Successfully connected to #{@parsed_uri}."
       rescue SocketError, Net::IMAP::Error, SourceError => e
@@ -190,7 +200,7 @@ private
     message =
       case e
       when Exception
-        "Error while #{opts[:while]}: #{e.message.chomp}."
+        "Error while #{opts[:while]}: #{e.message.chomp} (#{e.class.name})."
       when String
         e
       end
@@ -199,7 +209,7 @@ private
 
     self.broken_msg = message
     Redwood::log message
-    BufferManager.flash "Error communicating with IMAP server. See log for details."
+    BufferManager.flash "Error communicating with IMAP server. See log for details." if BufferManager.instantiated?
     raise SourceError, message
   end