Skip to content

Commit

Permalink
IMAP: fix delete_all against a readonly connection
Browse files Browse the repository at this point in the history
Closes #1206
  • Loading branch information
kimromi authored and jeremy committed Apr 16, 2018
1 parent 1a8a477 commit 19592c0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Bugs:
* Fix transfer encoding when message encoding is blank. (jakubonty, saks)
* Fix 7bit/base64 content transfer encoding mismatch. (ahorek)
* Fix UTF-8 attachment filename quoting. (ahorek)
* Fix `delete_all` using a readonly IMAP connection. (kimromi)


== Version 2.7.0 (2017-10-31)
Expand Down
2 changes: 1 addition & 1 deletion lib/mail/network/retriever_methods/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def delete_all(mailbox='INBOX')
mailbox = Net::IMAP.encode_utf7(mailbox)

start do |imap|
imap.examine(mailbox)
imap.select(mailbox)
imap.uid_search(['ALL']).each do |uid|
imap.uid_store(uid, "+FLAGS", [Net::IMAP::DELETED])
end
Expand Down
1 change: 1 addition & 0 deletions spec/mail/network/retriever_methods/imap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
expect(Net::IMAP).to receive(:encode_utf7).once
Mail.delete_all

expect(MockIMAP.readonly?).to be_falsey
expect(MockIMAP.examples.size).to eq 0
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def initialize(rfc822, number, flag)
class MockIMAP
@@connection = false
@@mailbox = nil
@@readonly = false
@@marked_for_deletion = []
@@default_examples = {
:default => (0..19).map do |i|
Expand Down Expand Up @@ -270,10 +271,12 @@ def disconnect

def select(mailbox)
@@mailbox = mailbox
@@readonly = false
end

def examine(mailbox)
select(mailbox)
@@readonly = true
end

def uid_search(keys, charset = nil)
Expand All @@ -298,6 +301,7 @@ def expunge
end

def self.mailbox; @@mailbox end # test only
def self.readonly?; @@readonly end # test only

def self.disconnected?; @@connection == false end
def disconnected?; @@connection == false end
Expand Down

0 comments on commit 19592c0

Please sign in to comment.