From effb9585efd3655cbf82bf7435a3862875d24ea4 Mon Sep 17 00:00:00 2001 From: nick evans Date: Sun, 8 Dec 2024 14:03:41 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Add=20ESearchResult=20methods=20?= =?UTF-8?q?for=20handling=20UPDATE=20return=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/net/imap/esearch_result.rb | 42 +++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/net/imap/esearch_result.rb b/lib/net/imap/esearch_result.rb index ea1efdcd..ed556a95 100644 --- a/lib/net/imap/esearch_result.rb +++ b/lib/net/imap/esearch_result.rb @@ -171,8 +171,23 @@ 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. @@ -180,6 +195,19 @@ def initialize(position:, set:) # Requires CONTEXT=SEARCH/CONTEXT=SORT # {[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. @@ -187,7 +215,19 @@ class AddToContext < ContextUpdate # Requires CONTEXT=SEARCH/CONTEXT=SORT # {[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