Skip to content

Commit

Permalink
♻️ Forward all search/uid_search arguments
Browse files Browse the repository at this point in the history
Forward all `#search` and `#uid_search` arguments to `#search_internal`.
This simplifies future changes to search parameters.
  • Loading branch information
nevans committed Nov 7, 2024
1 parent d723c6d commit cb444ff
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,9 @@ def uid_expunge(uid_set)
end
end

# :call-seq:
# search(criteria, charset = nil) -> result
#
# Sends a {SEARCH command [IMAP4rev1 §6.4.4]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.4.4]
# to search the mailbox for messages that match the given searching
# criteria, and returns message sequence numbers. +keys+ can either be a
Expand Down Expand Up @@ -1996,10 +1999,13 @@ def uid_expunge(uid_set)
# result = imap.search(["SUBJECT", "hi there", "not", "new")
# #=> Net::IMAP::SearchResult[1, 6, 7, 8, modseq: 5594]
# result.modseq # => 5594
def search(keys, charset = nil)
return search_internal("SEARCH", keys, charset)
def search(...)
search_internal("SEARCH", ...)
end

# :call-seq:
# uid_search(criteria, charset = nil) -> result
#
# Sends a {UID SEARCH command [IMAP4rev1 §6.4.8]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.4.8]
# to search the mailbox for messages that match the given searching
# criteria, and returns unique identifiers (<tt>UID</tt>s).
Expand All @@ -2008,7 +2014,7 @@ def search(keys, charset = nil)
# backward compatibility) but adds SearchResult#modseq when the +CONDSTORE+
# capability has been enabled.
#
# See #search for documentation of search criteria.
# See #search for documentation of parameters.
def uid_search(keys, charset = nil)
return search_internal("UID SEARCH", keys, charset)
end
Expand Down Expand Up @@ -2939,7 +2945,7 @@ def enforce_logindisabled?
end
end

def search_internal(cmd, keys, charset)
def search_internal(cmd, keys, charset = nil)
keys = normalize_searching_criteria(keys)
args = charset ? ["CHARSET", charset, *keys] : keys
synchronize do
Expand Down

0 comments on commit cb444ff

Please sign in to comment.