diff --git a/lib/net/imap.rb b/lib/net/imap.rb index d82612ba..da928184 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -2188,7 +2188,7 @@ def enable(*capabilities) .join(' ') synchronize do send_command("ENABLE #{capabilities}") - result = clear_responses("ENABLED").last + result = clear_responses("ENABLED").last || [] @utf8_strings ||= result.include? "UTF8=ACCEPT" @utf8_strings ||= result.include? "IMAP4REV2" result @@ -2642,7 +2642,7 @@ def search_internal(cmd, keys, charset) else send_command(cmd, *keys) end - clear_responses("SEARCH").last + clear_responses("SEARCH").last || [] end end @@ -2691,7 +2691,7 @@ def sort_internal(cmd, sort_keys, search_keys, charset) normalize_searching_criteria(search_keys) synchronize do send_command(cmd, sort_keys, charset, *search_keys) - clear_responses("SORT").last + clear_responses("SORT").last || [] end end @@ -2704,7 +2704,7 @@ def thread_internal(cmd, algorithm, search_keys, charset) normalize_searching_criteria(search_keys) synchronize do send_command(cmd, algorithm, charset, *search_keys) - clear_responses("THREAD").last + clear_responses("THREAD").last || [] end end diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb index 02bc233a..6e24aa11 100644 --- a/test/net/imap/test_imap.rb +++ b/test/net/imap/test_imap.rb @@ -1138,6 +1138,47 @@ def test_unselect end end + test("missing server ENABLED response") do + with_fake_server do |server, imap| + server.on "ENABLE", &:done_ok + enabled = imap.enable "foo", "bar", "baz" + assert_equal [], enabled + end + end + + test("missing server SEARCH response") do + with_fake_server do |server, imap| + server.on "SEARCH", &:done_ok + server.on "UID SEARCH", &:done_ok + found = imap.search ["subject", "hello"] + assert_equal [], found + found = imap.uid_search ["subject", "hello"] + assert_equal [], found + end + end + + test("missing server SORT response") do + with_fake_server do |server, imap| + server.on "SORT", &:done_ok + server.on "UID SORT", &:done_ok + found = imap.sort ["INTERNALDATE"], ["subject", "hello"], "UTF-8" + assert_equal [], found + found = imap.uid_sort ["INTERNALDATE"], ["subject", "hello"], "UTF-8" + assert_equal [], found + end + end + + test("missing server THREAD response") do + with_fake_server do |server, imap| + server.on "THREAD", &:done_ok + server.on "UID THREAD", &:done_ok + found = imap.thread "REFERENCES", ["subject", "hello"], "UTF-8" + assert_equal [], found + found = imap.uid_thread "REFERENCES", ["subject", "hello"], "UTF-8" + assert_equal [], found + end + end + private def imaps_test(timeout: 10)