lib/mail/network/retriever_methods/imap.rb in mail-2.2.12 vs lib/mail/network/retriever_methods/imap.rb in mail-2.2.13
- old
+ new
@@ -72,11 +72,15 @@
if block_given?
message_ids.each do |message_id|
fetchdata = imap.uid_fetch(message_id, ['RFC822'])[0]
new_message = Mail.new(fetchdata.attr['RFC822'])
new_message.mark_for_delete = true if options[:delete_after_find]
- yield new_message
+ if block.arity == 3
+ yield new_message, imap, message_id
+ else
+ yield new_message
+ end
imap.uid_store(message_id, "+FLAGS", [Net::IMAP::DELETED]) if options[:delete_after_find] && new_message.is_marked_for_delete?
end
imap.expunge if options[:delete_after_find]
else
emails = []
@@ -133,10 +137,16 @@
# Start an IMAP session and ensures that it will be closed in any case.
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
if defined?(imap) && imap && !imap.disconnected?
imap.disconnect