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 8, 2024
1 parent a90782d commit 8323ce3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 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 search +criteria+,
# and returns a SearchResult. SearchResult inherits from Array (for
Expand Down Expand Up @@ -2174,10 +2177,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 @@ -2187,8 +2193,8 @@ def search(keys, charset = nil)
# capability has been enabled.
#
# See #search for documentation of parameters.
def uid_search(keys, charset = nil)
return search_internal("UID SEARCH", keys, charset)
def uid_search(...)
search_internal("UID SEARCH", ...)
end

# :call-seq:
Expand Down Expand Up @@ -3117,7 +3123,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 8323ce3

Please sign in to comment.