@@ -1930,17 +1930,53 @@ def uid_expunge(uid_set)
1930
1930
end
1931
1931
1932
1932
# Sends a {SEARCH command [IMAP4rev1 §6.4.4]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.4.4]
1933
- # to search the mailbox for messages that match the given searching
1934
- # criteria, and returns message sequence numbers. +keys+ can either be a
1935
- # string holding the entire search string, or a single-dimension array of
1936
- # search keywords and arguments.
1937
- #
1938
- # Returns a SearchResult object. SearchResult inherits from Array (for
1933
+ # to search the mailbox for messages that match the given search +criteria+,
1934
+ # and returns a SearchResult. SearchResult inherits from Array (for
1939
1935
# backward compatibility) but adds SearchResult#modseq when the +CONDSTORE+
1940
1936
# capability has been enabled.
1941
1937
#
1938
+ # +criteria+ is one or more search keys and their arguments, which may be
1939
+ # provided as an array or a string.
1940
+ # See {"Search criteria"}[rdoc-ref:#search@Search+criteria], below.
1941
+ #
1942
+ # * When +criteria+ is an array, each member is a +SEARCH+ command argument:
1943
+ # * Any SequenceSet sends SequenceSet#valid_string.
1944
+ # +Range+, <tt>-1</tt>, and nested +Array+ elements are converted to
1945
+ # SequenceSet.
1946
+ # * Any +String+ is sent verbatim when it is a valid \IMAP atom,
1947
+ # and encoded as an \IMAP quoted or literal string otherwise.
1948
+ # * Any other +Integer+ (besides <tt>-1</tt>) will be sent as +#to_s+.
1949
+ # * +Date+ objects will be encoded as an \IMAP date (see ::encode_date).
1950
+ #
1951
+ # * When +criteria+ is a string, it will be sent directly to the server
1952
+ # <em>without any validation or encoding</em>. *WARNING:* This is
1953
+ # vulnerable to injection attacks when external inputs are used.
1954
+ #
1955
+ # +charset+ is the name of the {registered character
1956
+ # set}[https://www.iana.org/assignments/character-sets/character-sets.xhtml]
1957
+ # used by strings in the search +criteria+. When +charset+ isn't specified,
1958
+ # either <tt>"US-ASCII"</tt> or <tt>"UTF-8"</tt> is assumed, depending on
1959
+ # the server's capabilities. +charset+ may be sent inside +criteria+
1960
+ # instead of as a separate argument.
1961
+ #
1942
1962
# Related: #uid_search
1943
1963
#
1964
+ # ===== For example:
1965
+ #
1966
+ # p imap.search(["SUBJECT", "hello", "NOT", "SEEN"])
1967
+ # #=> [1, 6, 7, 8]
1968
+ #
1969
+ # The following searches send the exact same command to the server:
1970
+ #
1971
+ # # criteria array, charset arg
1972
+ # imap.search(%w[OR UNSEEN FLAGGED SUBJECT foo], "UTF-8")
1973
+ # # criteria string, charset arg
1974
+ # imap.search("OR UNSEEN FLAGGED SUBJECT foo", "UTF-8")
1975
+ # # criteria array contains charset arg
1976
+ # imap.search(%w[CHARSET UTF-8 OR UNSEEN FLAGGED SUBJECT foo])
1977
+ # # criteria string contains charset arg
1978
+ # imap.search("CHARSET UTF-8 OR UNSEEN FLAGGED SUBJECT foo")
1979
+ #
1944
1980
# ===== Search criteria
1945
1981
#
1946
1982
# For a full list of search criteria,
@@ -1982,18 +2018,13 @@ def uid_expunge(uid_set)
1982
2018
#
1983
2019
# TO <string>:: messages with <string> in their TO field.
1984
2020
#
1985
- # ===== For example:
1986
- #
1987
- # p imap.search(["SUBJECT", "hello", "NOT", "NEW"])
1988
- # #=> [1, 6, 7, 8]
1989
- #
1990
2021
# ===== Capabilities
1991
2022
#
1992
- # If [ CONDSTORE[https://www.rfc-editor.org/rfc/rfc7162.html] ] is supported
2023
+ # If CONDSTORE[https://www.rfc-editor.org/rfc/rfc7162.html] is supported
1993
2024
# and enabled for the selected mailbox, a non-empty SearchResult will
1994
2025
# include a +MODSEQ+ value.
1995
2026
# imap.select("mbox", condstore: true)
1996
- # result = imap.search(["SUBJECT", "hi there", "not", "new")
2027
+ # result = imap.search(["SUBJECT", "hi there", "not", "new"] )
1997
2028
# #=> Net::IMAP::SearchResult[1, 6, 7, 8, modseq: 5594]
1998
2029
# result.modseq # => 5594
1999
2030
def search ( keys , charset = nil )
@@ -2008,7 +2039,7 @@ def search(keys, charset = nil)
2008
2039
# backward compatibility) but adds SearchResult#modseq when the +CONDSTORE+
2009
2040
# capability has been enabled.
2010
2041
#
2011
- # See #search for documentation of search criteria .
2042
+ # See #search for documentation of parameters .
2012
2043
def uid_search ( keys , charset = nil )
2013
2044
return search_internal ( "UID SEARCH" , keys , charset )
2014
2045
end
0 commit comments