@@ -35,16 +35,16 @@ def initialize(tag: nil, uid: nil, data: nil)
3535
3636 # :call-seq: to_a -> Array of integers
3737 #
38- # When #all contains a SequenceSet of message sequence
38+ # When either #all or #partial contains a SequenceSet of message sequence
3939 # numbers or UIDs, +to_a+ returns that set as an array of integers.
4040 #
41- # When #all is +nil+, either because the server
42- # returned no results or because +ALL+ was not included in
41+ # When both #all and #partial are +nil+, either because the server
42+ # returned no results or because +ALL+ and +PARTIAL+ were not included in
4343 # the IMAP#search +RETURN+ options, #to_a returns an empty array.
4444 #
4545 # Note that SearchResult also implements +to_a+, so it can be used without
4646 # checking if the server returned +SEARCH+ or +ESEARCH+ data.
47- def to_a ; all &.numbers || [ ] end
47+ def to_a ; all &.numbers || partial &. to_a || [ ] end
4848
4949 ##
5050 # attr_reader: tag
@@ -135,6 +135,46 @@ def count; data.assoc("COUNT")&.last end
135135 # and +ESEARCH+ {[RFC4731]}[https://www.rfc-editor.org/rfc/rfc4731.html#section-3.2].
136136 def modseq ; data . assoc ( "MODSEQ" ) &.last end
137137
138+ # Returned by ESearchResult#partial.
139+ #
140+ # Requires +PARTIAL+ {[RFC9394]}[https://www.rfc-editor.org/rfc/rfc9394.html]
141+ # or <tt>CONTEXT=SEARCH</tt>/<tt>CONTEXT=SORT</tt>
142+ # {[RFC5267]}[https://www.rfc-editor.org/rfc/rfc5267.html]
143+ #
144+ # See also: #to_a
145+ class PartialResult < Data . define ( :range , :results )
146+ def initialize ( range :, results :)
147+ range => Range
148+ results = SequenceSet [ results ] unless results . nil?
149+ super
150+ end
151+
152+ ##
153+ # method: range
154+ # :call-seq: range -> range
155+
156+ ##
157+ # method: results
158+ # :call-seq: results -> sequence set or nil
159+
160+ # Converts #results to an array of integers.
161+ #
162+ # See also: ESearchResult#to_a.
163+ def to_a ; results &.numbers || [ ] end
164+ end
165+
166+ # :call-seq: partial -> PartialResult or nil
167+ #
168+ # A PartialResult containing a subset of the message sequence numbers or
169+ # UIDs that satisfy the SEARCH criteria.
170+ #
171+ # Requires +PARTIAL+ {[RFC9394]}[https://www.rfc-editor.org/rfc/rfc9394.html]
172+ # or <tt>CONTEXT=SEARCH</tt>/<tt>CONTEXT=SORT</tt>
173+ # {[RFC5267]}[https://www.rfc-editor.org/rfc/rfc5267.html]
174+ #
175+ # See also: #to_a
176+ def partial ; data . assoc ( "PARTIAL" ) &.last end
177+
138178 end
139179 end
140180end
0 commit comments