Permalink
Browse files

Merge branch 'imap' of https://github.com/dball/mail into dball-imap

  • Loading branch information...
2 parents 41c5b32 + 96efeb2 commit 3d7f25bfa53598c1d88d2b178d02c86b84b43827 @mikel mikel committed Dec 10, 2010
View
6 lib/mail/network/retriever_methods/imap.rb
@@ -74,7 +74,11 @@ def find(options={}, &block)
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]
View
15 spec/mail/network/retriever_methods/imap_spec.rb
@@ -33,6 +33,21 @@
MockIMAP.should be_disconnected
end
+ it "should get all emails and yield the imap, uid, and email when given a block of arity 3" do
+ MockIMAP.should be_disconnected
+
+ messages = []
+ uids = []
+ Mail.all do |message, imap, uid|
+ MockIMAP.should === imap
+ messages << message
+ uids << uid
+ end
+ messages.map { |m| m.raw_source }.sort.should == MockIMAP.examples.map { |m| m.attr['RFC822']}.sort
+ uids.sort.should == MockIMAP.examples.map { |m| m.number }.sort
+
+ MockIMAP.should be_disconnected
+ end
end
describe "find and options" do
View
3 spec/spec_helper.rb
@@ -176,10 +176,11 @@ def self.new(*args)
end
class MockIMAPFetchData
- attr_reader :attr
+ attr_reader :attr, :number
def initialize(rfc822, number)
@attr = { 'RFC822' => rfc822 }
+ @number = number
end
end

0 comments on commit 3d7f25b

Please sign in to comment.