Skip to content

Commit

Permalink
♻️ De-dup code in normalize_searching_criteria
Browse files Browse the repository at this point in the history
The exact same `RawData` code was used by `search_internal`,
`sort_internal`, and `thread_internal`.  This pulls that logic into
`normalize_searching_criteria`.
  • Loading branch information
nevans committed Nov 7, 2024
1 parent a366a0d commit 726a045
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3118,11 +3118,7 @@ def enforce_logindisabled?
end

def search_internal(cmd, keys, charset)
if keys.instance_of?(String)
keys = [RawData.new(keys)]
else
normalize_searching_criteria(keys)
end
keys = normalize_searching_criteria(keys)
synchronize do
if charset
send_command(cmd, "CHARSET", charset, *keys)
Expand Down Expand Up @@ -3175,31 +3171,24 @@ def copy_internal(cmd, set, mailbox)
end

def sort_internal(cmd, sort_keys, search_keys, charset)
if search_keys.instance_of?(String)
search_keys = [RawData.new(search_keys)]
else
normalize_searching_criteria(search_keys)
end
search_keys = normalize_searching_criteria(search_keys)
synchronize do
send_command(cmd, sort_keys, charset, *search_keys)
clear_responses("SORT").last || []
end
end

def thread_internal(cmd, algorithm, search_keys, charset)
if search_keys.instance_of?(String)
search_keys = [RawData.new(search_keys)]
else
normalize_searching_criteria(search_keys)
end
search_keys = normalize_searching_criteria(search_keys)
synchronize do
send_command(cmd, algorithm, charset, *search_keys)
clear_responses("THREAD").last || []
end
end

def normalize_searching_criteria(keys)
keys.collect! do |i|
def normalize_searching_criteria(criteria)
return RawData.new(criteria) if criteria.is_a?(String)
criteria.map do |i|
case i
when -1, Range, Array
SequenceSet.new(i)
Expand Down

0 comments on commit 726a045

Please sign in to comment.