Skip to content

Commit a366a0d

Browse files
committed
📚 Document all known standard search keys
Rather than only list a subset of search keys, this documents them all.
1 parent f0d7c3d commit a366a0d

File tree

1 file changed

+170
-23
lines changed

1 file changed

+170
-23
lines changed

lib/net/imap.rb

Lines changed: 170 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,46 +1977,193 @@ def uid_expunge(uid_set)
19771977
# # criteria string contains charset arg
19781978
# imap.search("CHARSET UTF-8 OR UNSEEN FLAGGED SUBJECT foo")
19791979
#
1980-
# ===== Search criteria
1980+
# ===== Search keys
19811981
#
1982-
# For a full list of search criteria,
1982+
# For full definitions of the standard search +criteria+,
19831983
# see [{IMAP4rev1 §6.4.4}[https://www.rfc-editor.org/rfc/rfc3501.html#section-6.4.4]],
19841984
# or [{IMAP4rev2 §6.4.4}[https://www.rfc-editor.org/rfc/rfc9051.html#section-6.4.4]],
19851985
# in addition to documentation for
1986-
# any [CAPABILITIES[https://www.iana.org/assignments/imap-capabilities/imap-capabilities.xhtml]]
1987-
# reported by #capabilities which may define additional search filters, e.g:
1986+
# any #capabilities which may define additional search filters, such as
19881987
# +CONDSTORE+, +WITHIN+, +FILTERS+, <tt>SEARCH=FUZZY</tt>, +OBJECTID+, or
1989-
# +SAVEDATE+. The following are some common search criteria:
1988+
# +SAVEDATE+.
1989+
#
1990+
# With the exception of <em>sequence-set</em> and <em>parenthesized
1991+
# list</em>, all search keys are composed of prefix label with zero or more
1992+
# arguments. The number and type of arguments is specific to each search
1993+
# key.
1994+
#
1995+
# +ALL+::
1996+
# Matches every message in the mailbox.
1997+
#
1998+
# (_search-key_ _search-key_...)::
1999+
# Combines one or more _search-key_ arguments to match
2000+
# messages which match all contained search keys. Useful for +OR+, +NOT+,
2001+
# and other search keys with _search-key_ arguments.
2002+
#
2003+
# _Note:_ this search key has no label.
2004+
#
2005+
# +OR+ _search-key_ _search-key_::
2006+
# Matches messages which match either _search-key_ argument.
2007+
#
2008+
# +NOT+ _search-key_::
2009+
# Matches messages which do not match _search-key_.
2010+
#
2011+
# _sequence-set_::
2012+
# Matches messages with message sequence numbers in _sequence-set_.
2013+
#
2014+
# _Note:_ this search key has no label.
2015+
#
2016+
# <em>+UIDONLY+ must *not* be enabled.</em>
2017+
# {[RFC9586]}[https://www.rfc-editor.org/rfc/rfc9586.html]
2018+
#
2019+
# +UID+ _sequence-set_::
2020+
# Matches messages with a UID in _sequence-set_.
2021+
#
2022+
# +ANSWERED+::
2023+
# +UNANSWERED+::
2024+
# Matches messages with or without the <tt>\\Answered</tt> flag.
2025+
# +DELETED+::
2026+
# +UNDELETED+::
2027+
# Matches messages with or without the <tt>\\Deleted</tt> flag.
2028+
# +DRAFT+::
2029+
# +UNDRAFT+::
2030+
# Matches messages with or without the <tt>\\Draft</tt> flag.
2031+
# +FLAGGED+::
2032+
# +UNFLAGGED+::
2033+
# Matches messages with or without the <tt>\\Flagged</tt> flag.
2034+
# +SEEN+::
2035+
# +UNSEEN+::
2036+
# Matches messages with or without the <tt>\\Seen</tt> flag.
2037+
#
2038+
# +KEYWORD+ _keyword_::
2039+
# +UNKEYWORD+ _keyword_::
2040+
# Matches messages with or without the specified _keyword_.
2041+
#
2042+
# +BCC+ _substring_::
2043+
# Matches when _substring_ is in the envelope's BCC field.
2044+
# +CC+ _substring_::
2045+
# Matches when _substring_ is in the envelope's CC field.
2046+
# +FROM+ _substring_::
2047+
# Matches when _substring_ is in the envelope's FROM field.
2048+
# +SUBJECT+ _substring_::
2049+
# Matches when _substring_ is in the envelope's SUBJECT field.
2050+
# +TO+ _substring_::
2051+
# Matches when _substring_ is in the envelope's TO field.
2052+
#
2053+
# +HEADER+ _field_ _substring_::
2054+
# Matches when _substring_ is in the specified header _field_.
2055+
#
2056+
# +BODY+ _string_::
2057+
# Matches when _string_ is in the body of the message.
2058+
# Does not match on header fields.
2059+
#
2060+
# The server _may_ use flexible matching, rather than simple substring
2061+
# matches. For example, this may use stemming or match only full words.
2062+
#
2063+
# +TEXT+ _string_::
2064+
# Matches when _string_ is in the header or body of the message.
2065+
#
2066+
# The server _may_ use flexible matching, rather than simple substring
2067+
# matches. For example, this may use stemming or match only full words.
2068+
#
2069+
# +BEFORE+ _date_::
2070+
# +ON+ _date_::
2071+
# +SINCE+ _date_::
2072+
# Matches when the +INTERNALDATE+ is earlier than, on, or later than
2073+
# _date_.
2074+
#
2075+
# +SENTBEFORE+ _date_::
2076+
# +SENTON+ _date_::
2077+
# +SENTSINCE+ _date_::
2078+
# Matches when the +Date+ header is earlier than, on, or later than _date_.
2079+
#
2080+
# +SMALLER+ _bytes_::
2081+
# +LARGER+ _bytes_::
2082+
# Matches when +RFC822.SIZE+ is smaller/larger than _bytes_.
2083+
#
2084+
# ====== Removed from +IMAP4rev2+
2085+
#
2086+
# The <tt>\\Recent</tt> flag has been removed from +IMAP4rev2+. So these
2087+
# search keys require the +IMAP4rev1+ capability.
19902088
#
1991-
# <message set>:: a set of message sequence numbers. "<tt>,</tt>" indicates
1992-
# an interval, "+:+" indicates a range. For instance,
1993-
# "<tt>2,10:12,15</tt>" means "<tt>2,10,11,12,15</tt>".
2089+
# +RECENT+::
2090+
# +UNRECENT+::
2091+
# Matches messages with or without the <tt>\\Recent</tt> flag.
2092+
#
2093+
# +NEW+::
2094+
# Equivalent to <tt>(RECENT UNSEEN)</tt>.
2095+
#
2096+
# ====== Extension search keys
2097+
#
2098+
# The search keys described below are defined by standard \IMAP extensions.
2099+
#
2100+
# +OLDER+ _interval_::
2101+
# +YOUNGER+ _interval_::
2102+
# Matches when +INTERNALDATE+ is more/less than _interval_ seconds ago.
2103+
#
2104+
# <em>Requires the +WITHIN+ capability</em>.
2105+
# {[RFC5032]}[https://www.rfc-editor.org/rfc/rfc5032.html]
2106+
#
2107+
# +ANNOTATION+ _entry_ _attr_ _value_::
2108+
# Matches messages that have annotations with entries matching _entry_,
2109+
# attributes matching _attr_, and _value_ in the attribute's values.
2110+
#
2111+
# <em>Requires the +ANNOTATE-EXPERIMENT-1+ capability</em>.
2112+
# {[RFC5257]}[https://www.rfc-editor.org/rfc/rfc5257.html].
2113+
#
2114+
# +FILTER+ _filter_::
2115+
# References a _filter_ that is stored on the server and matches all
2116+
# messages which would be matched by that filter's search criteria.
2117+
#
2118+
# <em>Requires the +FILTERS+ capability</em>.
2119+
# {[RFC5466]}[https://www.rfc-editor.org/rfc/rfc5466.html#section-3.1]
2120+
#
2121+
# +FUZZY+ _search-key_::
2122+
# Uses fuzzy matching for the specified search key.
2123+
#
2124+
# <em>Requires the <tt>SEARCH=FUZZY</tt> capability.</em>
2125+
# {[RFC6203]}[https://www.rfc-editor.org/rfc/rfc6203.html#section-6].
19942126
#
1995-
# BEFORE <date>:: messages with an internal date strictly before
1996-
# <b><date></b>. The date argument has a format similar
1997-
# to <tt>8-Aug-2002</tt>, and can be formatted using
1998-
# Net::IMAP.format_date.
2127+
# +MODSEQ+ _modseq_::
2128+
# Matches when +MODSEQ+ is greater than or equal to _modseq_.
19992129
#
2000-
# BODY <string>:: messages that contain <string> within their body.
2130+
# <em>Requires the +CONDSTORE+ capability</em>.
2131+
# {[RFC7162]}[https://www.rfc-editor.org/rfc/rfc7162.html#section-3.1.5].
20012132
#
2002-
# CC <string>:: messages containing <string> in their CC field.
2133+
# +MODSEQ+ _entry_ _entry-type_ _modseq_::
2134+
# Matches when a specific metadata _entry_ has been updated since
2135+
# _modseq_.
20032136
#
2004-
# FROM <string>:: messages that contain <string> in their FROM field.
2137+
# For flags, the corresponding _entry_ name is
2138+
# <tt>"/flags/#{flag_name}"</tt>, where _flag_name_ includes the
2139+
# <tt>\\</tt> prefix. _entry-type_ can be one of <tt>"shared"</tt>,
2140+
# <tt>"priv"</tt> (private), or <tt>"all"</tt>.
20052141
#
2006-
# NEW:: messages with the \Recent, but not the \Seen, flag set.
2142+
# <em>Requires the +CONDSTORE+ capability</em>.
2143+
# {[RFC7162]}[https://www.rfc-editor.org/rfc/rfc7162.html#section-3.1.5].
20072144
#
2008-
# NOT <search-key>:: negate the following search key.
2145+
# +EMAILID+ _objectid_::
2146+
# +THREADID+ _objectid_::
2147+
# Matches when +EMAILID+/+THREADID+ is equal to _objectid_
2148+
# (substring matches are not supported).
20092149
#
2010-
# OR <search-key> <search-key>:: "or" two search keys together.
2150+
# <em>Requires the +OBJECTID+ capability</em>.
2151+
# {[RFC8474]}[https://www.rfc-editor.org/rfc/rfc8474.html#section-6]
20112152
#
2012-
# ON <date>:: messages with an internal date exactly equal to <date>,
2013-
# which has a format similar to 8-Aug-2002.
2153+
# +SAVEDATESUPPORTED+::
2154+
# Matches every message in the mailbox when the mailbox supports the save
2155+
# date attribute. Otherwise, it matches no messages.
20142156
#
2015-
# SINCE <date>:: messages with an internal date on or after <date>.
2157+
# <em>Requires the +SAVEDATE+ capability</em>.
2158+
# {[RFC8514]}[https://www.rfc-editor.org/rfc/rfc8514.html#section-4.3]
20162159
#
2017-
# SUBJECT <string>:: messages with <string> in their subject.
2160+
# +SAVEDBEFORE+ _date_::
2161+
# +SAVEDON+ _date_::
2162+
# +SAVEDSINCE+ _date_::
2163+
# Matches when the save date is earlier than, on, or later than _date_.
20182164
#
2019-
# TO <string>:: messages with <string> in their TO field.
2165+
# <em>Requires the +SAVEDATE+ capability.</em>
2166+
# {[RFC8514]}[https://www.rfc-editor.org/rfc/rfc8514.html#section-4.3]
20202167
#
20212168
# ===== Capabilities
20222169
#

0 commit comments

Comments
 (0)