Skip to content

Commit

Permalink
🚧 Add ESearchResult methods for handling UPDATE return data
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Dec 9, 2024
1 parent 27ec443 commit effb958
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion lib/net/imap/esearch_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,63 @@ def initialize(position:, set:)
# A SequenceSet of updates to the search context.

##
# method: set
# Returns #set
def to_sequence_set; set end

# Converts #set to an array of numbers (UIDs or sequence numbers).
def to_a; set.numbers end

# :call-seq: update(context) -> updated context
#
# Given a SequenceSet +context+, returns a new SequenceSet, updated by
# +self+.
def update(context) update! context.dup end

# :call-seq: update!(context) -> updated context
#
# Modifies a SequenceSet +context+ by the updates in +self+.
# Implemented by subclasses.
def update(context) raise "implemented by subclasses" end
end

# Returned by ESearchResult#addto and ESearchResult#updates.
#
# Requires <tt>CONTEXT=SEARCH</tt>/<tt>CONTEXT=SORT</tt>
# {[RFC5267]}[https://www.rfc-editor.org/rfc/rfc5267.html]
class AddToContext < ContextUpdate
alias additions set

# Updates context by adding #additions.
#
# *NOTE:* positions other than zero are not currently supported.
def update!(context)
if position.zero?
context.merge additions
else
raise "Positions other than zero are not currently supported."
# TODO: context.insert additions
end
end
end

# Returned by ESearchResult#removefrom and ESearchResult#updates.
#
# Requires <tt>CONTEXT=SEARCH</tt>/<tt>CONTEXT=SORT</tt>
# {[RFC5267]}[https://www.rfc-editor.org/rfc/rfc5267.html]
class RemoveFromContext < ContextUpdate
alias removals set

# Updates context by subtracting #additions.
#
# *NOTE:* positions other than zero are not currently supported.
def update!(context)
if position.zero?
context.subtract removals
else
raise "Positions other than zero are not currently supported."
# TODO: context.remove removals
end
end
end

# :call-seq: updates -> array of context updates, or nil
Expand Down

0 comments on commit effb958

Please sign in to comment.