lib/sup/imap.rb in sup-0.0.5 vs lib/sup/imap.rb in sup-0.0.6
- old
+ new
@@ -110,11 +110,25 @@
Redwood::reporting_thread do
begin
#raise Net::IMAP::ByeResponseError, "simulated imap failure"
@imap = Net::IMAP.new host, port, ssl?
say "Logging in..."
- @imap.authenticate 'LOGIN', @username, @password
+
+ ## although RFC1730 claims that "If an AUTHENTICATE command
+ ## fails with a NO response, the client may try another", in
+ ## practice it seems like they will also send BAD responses.
+ begin
+ @imap.authenticate 'CRAM-MD5', @username, @password
+ rescue Net::IMAP::BadResponseError, Net::IMAP::NoResponseError => e
+ Redwood::log "CRAM-MD5 authentication failed: #{e.class}. Trying LOGIN auth..."
+ begin
+ @imap.authenticate 'LOGIN', @username, @password
+ rescue Net::IMAP::BadResponseError, Net::IMAP::NoResponseError => e
+ Redwood::log "LOGIN authentication failed: #{e.class}. Trying plain-text LOGIN..."
+ @imap.login @username, @password
+ end
+ end
scan_mailbox
say "Successfully connected to #{@parsed_uri}."
rescue SocketError, Net::IMAP::Error, SourceError => e
exception = e
ensure
@@ -188,19 +202,19 @@
@imap = nil
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
message += " It is likely that messages have been deleted from this IMAP mailbox. Please run sup-import --rebuild #{to_s} to correct this problem." if opts[:suggest_rebuild]
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
## build a fake unique id
def make_id imap_stuff