@@ -1949,9 +1949,13 @@ def uid_expunge(uid_set)
1949
1949
# * +Range+
1950
1950
# * <tt>-1</tt> and +:*+ -- both translate to <tt>*</tt>
1951
1951
# * responds to +#to_sequence_set+
1952
- # * nested +Array+
1952
+ # * +Array+, when each element is one of the above types, a positive
1953
+ # +Integer+, a sequence-set formatted +String+, or a deeply nested
1954
+ # +Array+ of these same types.
1953
1955
# * Any +String+ is sent verbatim when it is a valid \IMAP atom,
1954
1956
# and encoded as an \IMAP quoted or literal string otherwise.
1957
+ # * Any other nested +Array+ is encoded as a parenthesized list, to group
1958
+ # multiple search keys (e.g., for use with +OR+ and +NOT+).
1955
1959
# * Any other +Integer+ (besides <tt>-1</tt>) will be sent as +#to_s+.
1956
1960
# * +Date+ objects will be encoded as an \IMAP date (see ::encode_date).
1957
1961
#
@@ -1976,13 +1980,13 @@ def uid_expunge(uid_set)
1976
1980
# The following searches send the exact same command to the server:
1977
1981
#
1978
1982
# # criteria array, charset arg
1979
- # imap.search(%w[OR UNSEEN FLAGGED SUBJECT foo], "UTF-8")
1983
+ # imap.search(["OR", " UNSEEN", %w( FLAGGED SUBJECT foo) ], "UTF-8")
1980
1984
# # criteria string, charset arg
1981
- # imap.search("OR UNSEEN FLAGGED SUBJECT foo", "UTF-8")
1985
+ # imap.search("OR UNSEEN ( FLAGGED SUBJECT foo) ", "UTF-8")
1982
1986
# # criteria array contains charset arg
1983
- # imap.search(%w[CHARSET UTF-8 OR UNSEEN FLAGGED SUBJECT foo])
1987
+ # imap.search([* %w[CHARSET UTF-8], "OR", " UNSEEN", %w( FLAGGED SUBJECT foo) ])
1984
1988
# # criteria string contains charset arg
1985
- # imap.search("CHARSET UTF-8 OR UNSEEN FLAGGED SUBJECT foo")
1989
+ # imap.search("CHARSET UTF-8 OR UNSEEN ( FLAGGED SUBJECT foo) ")
1986
1990
#
1987
1991
# ===== Search keys
1988
1992
#
@@ -3208,11 +3212,20 @@ def coerce_search_arg_to_seqset?(obj)
3208
3212
case obj
3209
3213
when Set , -1 , :* then true
3210
3214
when Range then true
3211
- when Array then true
3215
+ when Array then obj . all? { coerce_search_array_arg_to_seqset? _1 }
3212
3216
else obj . respond_to? ( :to_sequence_set )
3213
3217
end
3214
3218
end
3215
3219
3220
+ def coerce_search_array_arg_to_seqset? ( obj )
3221
+ case obj
3222
+ when Integer then obj . positive? || obj == -1
3223
+ when String then ResponseParser ::Patterns ::SEQUENCE_SET_STR . match? ( obj . b )
3224
+ else
3225
+ coerce_search_arg_to_seqset? ( obj )
3226
+ end
3227
+ end
3228
+
3216
3229
def build_ssl_ctx ( ssl )
3217
3230
if ssl
3218
3231
params = ( Hash . try_convert ( ssl ) || { } ) . freeze
0 commit comments