Skip to content

Commit 6413656

Browse files
committed
✨ Coerce search args with SequenceSet.try_convert
1 parent d31ecf7 commit 6413656

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/net/imap.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,7 @@ def uid_expunge(uid_set)
19481948
# * +Set+
19491949
# * +Range+
19501950
# * <tt>-1</tt> and +:*+ -- both translate to <tt>*</tt>
1951+
# * responds to +#to_sequence_set+
19511952
# * nested +Array+
19521953
# * Any +String+ is sent verbatim when it is a valid \IMAP atom,
19531954
# and encoded as an \IMAP quoted or literal string otherwise.
@@ -3208,7 +3209,7 @@ def coerce_search_arg_to_seqset?(obj)
32083209
when Set, -1, :* then true
32093210
when Range then true
32103211
when Array then true
3211-
else false
3212+
else obj.respond_to?(:to_sequence_set)
32123213
end
32133214
end
32143215

test/net/imap/test_imap.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,13 @@ def test_unselect
12301230
imap.search([:*])
12311231
assert_equal "*", server.commands.pop.args
12321232

1233+
seqset_coercible = Object.new
1234+
def seqset_coercible.to_sequence_set
1235+
Net::IMAP::SequenceSet[1..9]
1236+
end
1237+
imap.search([seqset_coercible])
1238+
assert_equal "1:9", server.commands.pop.args
1239+
12331240
server.on "UID SEARCH", &search_resp
12341241
assert_equal search_result, imap.uid_search(["subject", "hello",
12351242
[1..22, 30..-1]])

0 commit comments

Comments
 (0)