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 24faaac commit 4372efb
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 @@ -3200,7 +3201,7 @@ def normalize_searching_criteria(criteria)
when Range then SequenceSet[arg]
when Array then SequenceSet[arg]
else
arg
SequenceSet.try_convert(arg) || arg
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 4372efb

Please sign in to comment.