Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bjoernalbers/mail into bj…
Browse files Browse the repository at this point in the history
…oernalbers-master
  • Loading branch information
Mikel Lindsaar committed Dec 23, 2010
2 parents 09e02bb + ac781e5 commit 0ba8ed8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/mail/network/retriever_methods/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ def start(config=Mail::Configuration.instance, &block)
raise ArgumentError.new("Mail::Retrievable#imap_start takes a block") unless block_given?

imap = Net::IMAP.new(settings[:address], settings[:port], settings[:enable_ssl], nil, false)
imap.login(settings[:user_name], settings[:password])
if settings[:authentication].nil?
imap.login(settings[:user_name], settings[:password])
else
# Note that Net::IMAP#authenticate('LOGIN', ...) is not equal with Net::IMAP#login(...)!
# (see also http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/net/imap/rdoc/classes/Net/IMAP.html#M000718)
imap.authenticate(settings[:authentication], settings[:user_name], settings[:password])
end

yield imap
ensure
Expand Down
23 changes: 23 additions & 0 deletions spec/mail/network/retriever_methods/imap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,29 @@
MockIMAP.should be_disconnected
end
end

describe "authentication mechanism" do
before(:each) do
@imap = MockIMAP.new
MockIMAP.stub!(:new).and_return(@imap)
end
it "should be login by default" do
@imap.should_not_receive(:authenticate)
@imap.should_receive(:login).with('foo', 'secret')
Mail.defaults do
retriever_method :imap, {:user_name => 'foo', :password => 'secret'}
end
messages = Mail.find
end
it "should be changeable" do
@imap.should_receive(:authenticate).with('CRAM-MD5', 'foo', 'secret')
@imap.should_not_receive(:login)
Mail.defaults do
retriever_method :imap, {:authentication => 'CRAM-MD5', :user_name => 'foo', :password => 'secret'}
end
messages = Mail.find
end
end

end

0 comments on commit 0ba8ed8

Please sign in to comment.