Skip to content

Commit

Permalink
✨ Coerce search args with SequenceSet.try_convert
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Nov 8, 2024
1 parent d31ecf7 commit 6413656
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,7 @@ def uid_expunge(uid_set)
# * +Set+
# * +Range+
# * <tt>-1</tt> and +:*+ -- both translate to <tt>*</tt>
# * responds to +#to_sequence_set+
# * nested +Array+
# * Any +String+ is sent verbatim when it is a valid \IMAP atom,
# and encoded as an \IMAP quoted or literal string otherwise.
Expand Down Expand Up @@ -3208,7 +3209,7 @@ def coerce_search_arg_to_seqset?(obj)
when Set, -1, :* then true
when Range then true
when Array then true
else false
else obj.respond_to?(:to_sequence_set)
end
end

Expand Down
7 changes: 7 additions & 0 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,13 @@ def test_unselect
imap.search([:*])
assert_equal "*", server.commands.pop.args

seqset_coercible = Object.new
def seqset_coercible.to_sequence_set
Net::IMAP::SequenceSet[1..9]
end
imap.search([seqset_coercible])
assert_equal "1:9", server.commands.pop.args

server.on "UID SEARCH", &search_resp
assert_equal search_result, imap.uid_search(["subject", "hello",
[1..22, 30..-1]])
Expand Down

0 comments on commit 6413656

Please sign in to comment.