Class: Net::IMAP::ESearchResult
- Inherits:
-
Object
- Object
- Net::IMAP::ESearchResult
- Defined in:
- lib/net/imap/esearch_result.rb
Overview
An “extended search” response (ESEARCH). ESearchResult should be returned (instead of SearchResult) by IMAP#search, IMAP#uid_search, IMAP#sort, and IMAP#uid_sort under any of the following conditions:
-
Return options were specified for IMAP#search or IMAP#uid_search. The server must support a search extension which allows RFC4466
returnoptions, such asESEARCH,PARTIAL, orIMAP4rev2. -
Return options were specified for IMAP#sort or IMAP#uid_sort. The server must support the
ESORTextension [RFC5267].NOTE: IMAP#search and IMAP#uid_search do not support
ESORTyet. -
The server supports
IMAP4rev2but notIMAP4rev1, orIMAP4rev2has been enabled.IMAP4rev2requiresESEARCHresults.
Note that some servers may claim to support a search extension which requires an ESEARCH result, such as PARTIAL, but still only return a SEARCH result when return options are specified.
Some search extensions may result in the server sending ESearchResult responses after the initiating command has completed. Use IMAP#add_response_handler to handle these responses.
Compatibility with SearchResult
Note that both SearchResult and ESearchResult implement each, to_a, and to_sequence_set. These methods can be used regardless of whether the server returns SEARCH or ESEARCH data (or no data).
Defined Under Namespace
Classes: PartialResult
Instance Method Summary collapse
-
#all ⇒ Object
:call-seq: all -> sequence set or nil.
-
#count ⇒ Object
:call-seq: count -> integer or nil.
-
#each ⇒ Object
When either #all or #partial contains a SequenceSet of message sequence numbers or UIDs,
eachyields each integer in the set. -
#initialize(tag: nil, uid: nil, data: nil) ⇒ ESearchResult
constructor
A new instance of ESearchResult.
-
#max ⇒ Object
:call-seq: max -> integer or nil.
-
#min ⇒ Object
:call-seq: min -> integer or nil.
-
#modseq ⇒ Object
:call-seq: modseq -> integer or nil.
-
#partial ⇒ Object
:call-seq: partial -> PartialResult or nil.
-
#to_a ⇒ Object
:call-seq: to_a -> Array of integers.
-
#to_sequence_set ⇒ Object
:call-seq: to_sequence_set -> SequenceSet or nil.
Constructor Details
#initialize(tag: nil, uid: nil, data: nil) ⇒ ESearchResult
Returns a new instance of ESearchResult.
35 36 37 38 39 40 |
# File 'lib/net/imap/esearch_result.rb', line 35 def initialize(tag: nil, uid: nil, data: nil) tag => String | nil; tag = -tag if tag uid => true | false | nil; uid = !!uid data => Array | nil; data ||= []; data.freeze super end |
Instance Method Details
#all ⇒ Object
:call-seq: all -> sequence set or nil
A SequenceSet containing all message sequence numbers or UIDs that satisfy the SEARCH criteria.
Returns nil when the associated search command has no results, or when the ALL return option was not specified but other return options were.
Requires ESEARCH [RFC4731] or IMAP4rev2 [RFC9051].
See also: #to_a
153 |
# File 'lib/net/imap/esearch_result.rb', line 153 def all; data.assoc("ALL")&.last end |
#count ⇒ Object
164 |
# File 'lib/net/imap/esearch_result.rb', line 164 def count; data.assoc("COUNT")&.last end |
#each ⇒ Object
When either #all or #partial contains a SequenceSet of message sequence numbers or UIDs, each yields each integer in the set.
When both #all and #partial are nil, either because the server returned no results or because ALL and PARTIAL were not included in the IMAP#search RETURN options, #each does not yield.
Note that SearchResult also implements #each, so it can be used without checking if the server returned SEARCH or ESEARCH data.
Related: #to_sequence_set, #to_a, #all, #partial
86 87 88 89 90 |
# File 'lib/net/imap/esearch_result.rb', line 86 def each(&) return to_enum(__callee__) unless block_given? to_sequence_set.each_number(&) self end |
#max ⇒ Object
139 |
# File 'lib/net/imap/esearch_result.rb', line 139 def max; data.assoc("MAX")&.last end |
#min ⇒ Object
128 |
# File 'lib/net/imap/esearch_result.rb', line 128 def min; data.assoc("MIN")&.last end |
#modseq ⇒ Object
:call-seq: modseq -> integer or nil
The highest mod-sequence of all messages being returned.
Returns nil when the associated search command has no results, or when the MODSEQ search criterion wasn’t specified.
Note that there is no search return option for MODSEQ. It will be returned whenever the CONDSTORE extension has been enabled. Using the MODSEQ search criteria will implicitly enable CONDSTORE.
179 |
# File 'lib/net/imap/esearch_result.rb', line 179 def modseq; data.assoc("MODSEQ")&.last end |
#partial ⇒ Object
221 |
# File 'lib/net/imap/esearch_result.rb', line 221 def partial; data.assoc("PARTIAL")&.last end |
#to_a ⇒ Object
:call-seq: to_a -> Array of integers
When either #all or #partial contains a SequenceSet of message sequence numbers or UIDs, to_a returns that set as an array of integers.
When both #all and #partial are nil, either because the server returned no results or because neither ALL or PARTIAL were included in the IMAP#search RETURN options, #to_a returns an empty array.
Note that SearchResult also implements to_a, so it can be used without checking if the server returned SEARCH or ESEARCH data.
Related: #each, #to_sequence_set, #all, #partial
55 |
# File 'lib/net/imap/esearch_result.rb', line 55 def to_a; to_sequence_set.numbers end |
#to_sequence_set ⇒ Object
:call-seq: to_sequence_set -> SequenceSet or nil
When either #all or #partial contains a SequenceSet of message sequence numbers or UIDs, to_sequence_set returns that sequence set.
When both #all and #partial are nil, either because the server returned no results or because neither ALL or PARTIAL were included in the IMAP#search RETURN options, #to_sequence_set returns SequenceSet.empty.
Note that SearchResult also implements to_sequence_set, so it can be used without checking if the server returned SEARCH or ESEARCH data.
Related: #each, #to_a, #all, #partial
71 72 73 |
# File 'lib/net/imap/esearch_result.rb', line 71 def to_sequence_set all || partial&.to_sequence_set || SequenceSet.empty end |