Added plain auth methode.

This commit is contained in:
Martin Edenhofer 2013-01-03 20:01:26 +01:00
parent d6869344fb
commit 2fcfba1bb6

View file

@ -4,10 +4,26 @@ class Channel::IMAP < Channel::EmailParser
include UserInfo include UserInfo
def fetch (channel) def fetch (channel)
puts "fetching imap (#{channel[:options][:host]}/#{channel[:options][:user]})" ssl = false
port = 143
if channel[:options][:ssl].to_s == 'true'
ssl = true
port = 993
end
imap = Net::IMAP.new(channel[:options][:host], 993, true, nil, false ) puts "fetching imap (#{channel[:options][:host]}/#{channel[:options][:user]} port=#{port},ssl=#{ssl})"
imap = Net::IMAP.new( channel[:options][:host], port, ssl, nil, false )
# try LOGIN, if not - try plain
begin
imap.authenticate( 'LOGIN', channel[:options][:user], channel[:options][:password] ) imap.authenticate( 'LOGIN', channel[:options][:user], channel[:options][:password] )
rescue Exception => e
if e.to_s !~ /unsupported\sauthentication\smechanism/i
raise e
end
imap.login( channel[:options][:user], channel[:options][:password] )
end
imap.select('INBOX') imap.select('INBOX')
count = 0 count = 0
count_all = imap.search(['ALL']).count count_all = imap.search(['ALL']).count