lib/mail/network/retriever_methods/imap.rb in mail-2.3.3 vs lib/mail/network/retriever_methods/imap.rb in mail-2.4.0
- old
+ new
@@ -52,18 +52,20 @@
# mailbox: mailbox to search the email(s) in. The default is 'INBOX'.
# what: last or first emails. The default is :first.
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
# count: number of emails to retrieve. The default value is 10. A value of 1 returns an
# instance of Message, not an array of Message instances.
+ # ready_only: will ensure that no writes are made to the inbox during the session.
+ # This is helpful when you don't want your messages to be set to read automatically. Default is false.
# delete_after_find: flag for whether to delete each retreived email after find. Default
# is false. Use #find_and_delete if you would like this to default to true.
#
def find(options={}, &block)
options = validate_options(options)
start do |imap|
- imap.select(options[:mailbox])
+ options[:read_only] ? imap.select(options[:mailbox]) : imap.examine(options[:mailbox])
message_ids = imap.uid_search(options[:keys])
message_ids.reverse! if options[:what].to_sym == :last
message_ids = message_ids.first(options[:count]) if options[:count].is_a?(Integer)
message_ids.reverse! if (options[:what].to_sym == :last && options[:order].to_sym == :asc) ||
@@ -99,11 +101,10 @@
def delete_all(mailbox='INBOX')
mailbox ||= 'INBOX'
mailbox = Net::IMAP.encode_utf7(mailbox)
start do |imap|
- imap.select(mailbox)
imap.uid_search(['ALL']).each do |message_id|
imap.uid_store(message_id, "+FLAGS", [Net::IMAP::DELETED])
end
imap.expunge
end
@@ -128,9 +129,10 @@
options[:order] ||= :asc
options[:what] ||= :first
options[:keys] ||= 'ALL'
options[:delete_after_find] ||= false
options[:mailbox] = Net::IMAP.encode_utf7(options[:mailbox])
+ options[:read_only] ||= false
options
end
# Start an IMAP session and ensures that it will be closed in any case.