From 19592c0555c699ba8d54bccd3b31483d1aff0692 Mon Sep 17 00:00:00 2001 From: kimromi Date: Fri, 23 Feb 2018 17:25:38 +0900 Subject: [PATCH] IMAP: fix `delete_all` against a readonly connection Closes #1206 --- CHANGELOG.rdoc | 1 + lib/mail/network/retriever_methods/imap.rb | 2 +- spec/mail/network/retriever_methods/imap_spec.rb | 1 + spec/spec_helper.rb | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 076f1d48f..a274491c0 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -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) diff --git a/lib/mail/network/retriever_methods/imap.rb b/lib/mail/network/retriever_methods/imap.rb index 7a0ec5b4c..e279e6620 100644 --- a/lib/mail/network/retriever_methods/imap.rb +++ b/lib/mail/network/retriever_methods/imap.rb @@ -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 diff --git a/spec/mail/network/retriever_methods/imap_spec.rb b/spec/mail/network/retriever_methods/imap_spec.rb index de83c1adf..65eafb12b 100644 --- a/spec/mail/network/retriever_methods/imap_spec.rb +++ b/spec/mail/network/retriever_methods/imap_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6ca493ad5..386b7e363 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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| @@ -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) @@ -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