diff --git a/lib/net/imap.rb b/lib/net/imap.rb index 6bd2f107..397f24b8 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -3151,6 +3151,10 @@ def enforce_logindisabled? end def search_args(keys, charset = nil) + # NOTE: not handling combined RETURN and CHARSET for raw strings + if charset && keys in /\ACHARSET\b/i | Array[/\ACHARSET\z/i, *] + raise ArgumentError, "multiple charset arguments" + end args = normalize_searching_criteria(keys) args.prepend("CHARSET", charset) if charset args diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb index 5fa9d643..fc2ccdd5 100644 --- a/test/net/imap/test_imap.rb +++ b/test/net/imap/test_imap.rb @@ -1265,6 +1265,24 @@ def seqset_coercible.to_sequence_set end end + test("#search/#uid_search with invalid arguments") do + with_fake_server do |server, imap| + server.on "SEARCH" do |cmd| cmd.fail_no "should fail before this" end + server.on "UID SEARCH" do |cmd| cmd.fail_no "should fail before this" end + + assert_raise(ArgumentError) do + imap.search(["charset", "foo", "ALL"], "bar") + end + assert_raise(ArgumentError) do + imap.search("charset foo ALL", "bar") + end + # Parsing return opts is too complicated, for now. + # assert_raise(ArgumentError) do + # imap.search("return () charset foo ALL", "bar") + # end + end + end + test("missing server SEARCH response") do with_fake_server do |server, imap| server.on "SEARCH", &:done_ok