net-imap 0.5.1 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of net-imap might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf511b8683c6931cf9ec2d3aa4a55ef634a2cc0e670590a4142d9895594b9191
4
- data.tar.gz: db4ca0b7230553258e0d81a8a5b5cbed4273e30245200db661145ba430af20d0
3
+ metadata.gz: a871e99f51067e3a509aa5a74fe2c49f4d79496bcec2f21ac50c3c5793d2cdbf
4
+ data.tar.gz: 302c03e65954f9a118d877f97ea2296f34a7f50c8b1299e3e4f8b589cb620880
5
5
  SHA512:
6
- metadata.gz: b61a04c6992df7d6ffcf0e5396723966c3f3a5a1c6a596caf413c63d355100c8d2c28096a2261045d52ada4d8e995bba1c4f12864bf65fe1355c331df236eb85
7
- data.tar.gz: 0bc68ec15c5d53f0f437eab5318bf8cdd428dcdc650a98f66e961658ed361b125e866db2d41954e50ce66de5ec143d108e9135f554bd240ff0d7057724d16416
6
+ metadata.gz: 85d97c9729220265da03588f175fea22bcdd27d40cd06910ad35bc01ed64bd0c27b2769790464712572166761f3e82fc4eb6330fef64f45cceb0b3e1007f7126
7
+ data.tar.gz: aa18d53b81e57ddfbdde2b8295ca7324f965fa744846fdd756ec4ca1c30e6e72092b106ff454d100f70d1078ee239f2b3e643bd4650606a2fc3b4ab5a2d0cc1f
data/README.md CHANGED
@@ -50,12 +50,16 @@ end
50
50
 
51
51
  ```ruby
52
52
  imap.select('Mail/sent-mail')
53
- if not imap.list('Mail/', 'sent-apr03')
53
+ if imap.list('Mail/', 'sent-apr03').empty?
54
54
  imap.create('Mail/sent-apr03')
55
55
  end
56
56
  imap.search(["BEFORE", "30-Apr-2003", "SINCE", "1-Apr-2003"]).each do |message_id|
57
- imap.copy(message_id, "Mail/sent-apr03")
58
- imap.store(message_id, "+FLAGS", [:Deleted])
57
+ if imap.capable?(:move) || imap.capable?(:IMAP4rev2)
58
+ imap.move(message_id, "Mail/sent-apr03")
59
+ else
60
+ imap.copy(message_id, "Mail/sent-apr03")
61
+ imap.store(message_id, "+FLAGS", [:Deleted])
62
+ end
59
63
  end
60
64
  imap.expunge
61
65
  ```
data/docs/styles.css CHANGED
@@ -1,24 +1,75 @@
1
1
  /* this is a work in progress. :) */
2
2
 
3
- main .method-header {
4
- background: rgba(27,31,35,0.05);
5
- border: 1px solid #6C8C22;
3
+ /***********************************************
4
+ * Method descriptions
5
+ ***********************************************/
6
+
7
+ main .method-detail {
8
+ display: grid;
9
+ grid-template-columns: 1fr auto;
10
+ justify-content: space-between;
11
+ }
12
+
13
+ main .method-header, main .method-controls {
6
14
  padding: 0.5em;
7
- border-radius: 4px;
8
- /* padding: 0 0.5em; */
9
- /* border-width: 0 1px; */
10
- /* border-color: #6C8C22; */
11
- /* border-style: solid; */
15
+ /* border: 1px solid var(--highlight-color); */
16
+ background: var(--table-header-background-color);
17
+ line-height: 1.6;
18
+ }
19
+
20
+ main .method-header {
21
+ border-right: none;
22
+ border-radius: 4px 0 0 4px;
23
+ }
24
+
25
+ main .method-controls {
26
+ border-left: none;
27
+ border-radius: 0 4px 4px 0;
12
28
  }
13
29
 
14
30
  main .method-description, main .aliases {
31
+ grid-column: 1 / span 2;
15
32
  padding-left: 1em;
16
33
  }
17
34
 
18
- body {
19
- /*
20
- * The default (300) can be too low contrast. Also, many fonts don't
21
- * distinguish between 300->400, so <em>...</em> had no effect.
22
- */
23
- font-weight: 400;
35
+ @media (max-width: 700px) {
36
+ main .method-header, main .method-controls, main .method-description {
37
+ grid-column: 1 / span 2;
38
+ margin: 0;
39
+ }
40
+ main .method-controls {
41
+ background: none;
42
+ }
43
+ }
44
+
45
+ /***********************************************
46
+ * Description lists
47
+ ***********************************************/
48
+
49
+ main dt {
50
+ margin-bottom: 0; /* override rdoc 6.8 */
51
+ float: unset; /* override rdoc 6.8 */
52
+ line-height: 1.5; /* matches `main p` */
53
+ }
54
+
55
+ main dl.note-list dt {
56
+ margin-right: 1em;
57
+ float: left;
58
+ }
59
+
60
+ main dl.note-list dt:has(+ dt) {
61
+ margin-right: 0.25em;
62
+ }
63
+
64
+ main dl.note-list dt:has(+ dt)::after {
65
+ content: ', ';
66
+ font-weight: normal;
67
+ }
68
+
69
+ main dd {
70
+ margin: 0 0 1em 1em;
71
+ }
72
+
73
+ main dd p:first-child {
74
+ margin-top: 0;
24
75
  }
@@ -3,6 +3,7 @@
3
3
  require "date"
4
4
 
5
5
  require_relative "errors"
6
+ require_relative "data_lite"
6
7
 
7
8
  module Net
8
9
  class IMAP < Protocol
@@ -119,80 +120,85 @@ module Net
119
120
  put_string("\\" + symbol.to_s)
120
121
  end
121
122
 
122
- class RawData # :nodoc:
123
+ CommandData = Data.define(:data) do # :nodoc:
123
124
  def send_data(imap, tag)
124
- imap.__send__(:put_string, @data)
125
+ raise NoMethodError, "#{self.class} must implement #{__method__}"
125
126
  end
126
127
 
127
128
  def validate
128
129
  end
129
-
130
- private
131
-
132
- def initialize(data)
133
- @data = data
134
- end
135
130
  end
136
131
 
137
- class Atom # :nodoc:
132
+ class RawData < CommandData # :nodoc:
138
133
  def send_data(imap, tag)
139
- imap.__send__(:put_string, @data)
140
- end
141
-
142
- def validate
143
- end
144
-
145
- private
146
-
147
- def initialize(data)
148
- @data = data
134
+ imap.__send__(:put_string, data)
149
135
  end
150
136
  end
151
137
 
152
- class QuotedString # :nodoc:
138
+ class Atom < CommandData # :nodoc:
153
139
  def send_data(imap, tag)
154
- imap.__send__(:send_quoted_string, @data)
155
- end
156
-
157
- def validate
140
+ imap.__send__(:put_string, data)
158
141
  end
142
+ end
159
143
 
160
- private
161
-
162
- def initialize(data)
163
- @data = data
144
+ class QuotedString < CommandData # :nodoc:
145
+ def send_data(imap, tag)
146
+ imap.__send__(:send_quoted_string, data)
164
147
  end
165
148
  end
166
149
 
167
- class Literal # :nodoc:
150
+ class Literal < CommandData # :nodoc:
168
151
  def send_data(imap, tag)
169
- imap.__send__(:send_literal, @data, tag)
152
+ imap.__send__(:send_literal, data, tag)
170
153
  end
154
+ end
171
155
 
172
- def validate
156
+ class PartialRange < CommandData # :nodoc:
157
+ uint32_max = 2**32 - 1
158
+ POS_RANGE = 1..uint32_max
159
+ NEG_RANGE = -uint32_max..-1
160
+ Positive = ->{ (_1 in Range) and POS_RANGE.cover?(_1) }
161
+ Negative = ->{ (_1 in Range) and NEG_RANGE.cover?(_1) }
162
+
163
+ def initialize(data:)
164
+ min, max = case data
165
+ in Range
166
+ data.minmax.map { Integer _1 }
167
+ in ResponseParser::Patterns::PARTIAL_RANGE
168
+ data.split(":").map { Integer _1 }.minmax
169
+ else
170
+ raise ArgumentError, "invalid partial range input: %p" % [data]
171
+ end
172
+ data = min..max
173
+ unless data in Positive | Negative
174
+ raise ArgumentError, "invalid partial-range: %p" % [data]
175
+ end
176
+ super
177
+ rescue TypeError, RangeError
178
+ raise ArgumentError, "expected range min/max to be Integers"
173
179
  end
174
180
 
175
- private
181
+ def formatted = "%d:%d" % data.minmax
176
182
 
177
- def initialize(data)
178
- @data = data
183
+ def send_data(imap, tag)
184
+ imap.__send__(:put_string, formatted)
179
185
  end
180
186
  end
181
187
 
182
188
  # *DEPRECATED*. Replaced by SequenceSet.
183
- class MessageSet # :nodoc:
189
+ class MessageSet < CommandData # :nodoc:
184
190
  def send_data(imap, tag)
185
- imap.__send__(:put_string, format_internal(@data))
191
+ imap.__send__(:put_string, format_internal(data))
186
192
  end
187
193
 
188
194
  def validate
189
- validate_internal(@data)
195
+ validate_internal(data)
190
196
  end
191
197
 
192
198
  private
193
199
 
194
- def initialize(data)
195
- @data = data
200
+ def initialize(data:)
201
+ super
196
202
  warn("DEPRECATED: #{MessageSet} should be replaced with #{SequenceSet}.",
197
203
  uplevel: 1, category: :deprecated)
198
204
  begin
@@ -246,22 +252,18 @@ module Net
246
252
  end
247
253
  end
248
254
 
249
- class ClientID # :nodoc:
255
+ class ClientID < CommandData # :nodoc:
250
256
 
251
257
  def send_data(imap, tag)
252
- imap.__send__(:send_data, format_internal(@data), tag)
258
+ imap.__send__(:send_data, format_internal(data), tag)
253
259
  end
254
260
 
255
261
  def validate
256
- validate_internal(@data)
262
+ validate_internal(data)
257
263
  end
258
264
 
259
265
  private
260
266
 
261
- def initialize(data)
262
- @data = data
263
- end
264
-
265
267
  def validate_internal(client_id)
266
268
  client_id.to_h.each do |k,v|
267
269
  unless StringFormatter.valid_string?(k)
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Some of the code in this file was copied from the polyfill-data gem.
4
+ #
5
+ # MIT License
6
+ #
7
+ # Copyright (c) 2023 Jim Gay, Joel Drapper, Nicholas Evans
8
+ #
9
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ # of this software and associated documentation files (the "Software"), to deal
11
+ # in the Software without restriction, including without limitation the rights
12
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ # copies of the Software, and to permit persons to whom the Software is
14
+ # furnished to do so, subject to the following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included in all
17
+ # copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ # SOFTWARE.
26
+
27
+
28
+ module Net
29
+ class IMAP
30
+ data_or_object = RUBY_VERSION >= "3.2.0" ? ::Data : Object
31
+ class DataLite < data_or_object
32
+ def encode_with(coder) coder.map = attributes.transform_keys(&:to_s) end
33
+ def init_with(coder) initialize(**coder.map.transform_keys(&:to_sym)) end
34
+ end
35
+
36
+ Data = DataLite
37
+ end
38
+ end
39
+
40
+ # :nocov:
41
+ # Need to skip test coverage for the rest, because it isn't loaded by ruby 3.2+.
42
+ return if RUBY_VERSION >= "3.2.0"
43
+
44
+ module Net
45
+ class IMAP
46
+ # DataLite is a temporary substitute for ruby 3.2's +Data+ class. DataLite
47
+ # is aliased as Net::IMAP::Data, so that code using it won't need to be
48
+ # updated when it is removed.
49
+ #
50
+ # See {ruby 3.2's documentation for Data}[https://docs.ruby-lang.org/en/3.2/Data.html].
51
+ #
52
+ # [When running ruby 3.1]
53
+ # This class reimplements the API for ruby 3.2's +Data+, and should be
54
+ # compatible for nearly all use-cases. This reimplementation <em>will be
55
+ # removed</em> in +net-imap+ 0.6, when support for ruby 3.1 is dropped.
56
+ #
57
+ # _NOTE:_ +net-imap+ no longer supports ruby versions prior to 3.1.
58
+ # [When running ruby >= 3.2]
59
+ # This class inherits from +Data+ and _only_ defines the methods needed
60
+ # for YAML serialization. This will be dropped when +psych+ adds support
61
+ # for +Data+.
62
+ #
63
+ # Some of the code in this class was copied or adapted from the
64
+ # {polyfill-data gem}[https://rubygems.org/gems/polyfill-data], by Jim Gay
65
+ # and Joel Drapper, under the MIT license terms.
66
+ class DataLite
67
+ singleton_class.undef_method :new
68
+
69
+ TYPE_ERROR = "%p is not a symbol nor a string"
70
+ ATTRSET_ERROR = "invalid data member: %p"
71
+ DUP_ERROR = "duplicate member: %p"
72
+ ARITY_ERROR = "wrong number of arguments (given %d, expected %s)"
73
+ private_constant :TYPE_ERROR, :ATTRSET_ERROR, :DUP_ERROR, :ARITY_ERROR
74
+
75
+ # Defines a new Data class.
76
+ #
77
+ # _NOTE:_ Unlike ruby 3.2's +Data.define+, DataLite.define only supports
78
+ # member names which are valid local variable names. Member names can't
79
+ # be keywords (e.g: +next+ or +class+) or start with capital letters, "@",
80
+ # etc.
81
+ def self.define(*args, &block)
82
+ members = args.each_with_object({}) do |arg, members|
83
+ arg = arg.to_str unless arg in Symbol | String if arg.respond_to?(:to_str)
84
+ arg = arg.to_sym if arg in String
85
+ arg in Symbol or raise TypeError, TYPE_ERROR % [arg]
86
+ arg in %r{=} and raise ArgumentError, ATTRSET_ERROR % [arg]
87
+ members.key?(arg) and raise ArgumentError, DUP_ERROR % [arg]
88
+ members[arg] = true
89
+ end
90
+ members = members.keys.freeze
91
+
92
+ klass = ::Class.new(self)
93
+
94
+ klass.singleton_class.undef_method :define
95
+ klass.define_singleton_method(:members) { members }
96
+
97
+ def klass.new(*args, **kwargs, &block)
98
+ if kwargs.size.positive?
99
+ if args.size.positive?
100
+ raise ArgumentError, ARITY_ERROR % [args.size, 0]
101
+ end
102
+ elsif members.size < args.size
103
+ expected = members.size.zero? ? 0 : 0..members.size
104
+ raise ArgumentError, ARITY_ERROR % [args.size, expected]
105
+ else
106
+ kwargs = Hash[members.take(args.size).zip(args)]
107
+ end
108
+ allocate.tap do |instance|
109
+ instance.__send__(:initialize, **kwargs, &block)
110
+ end.freeze
111
+ end
112
+
113
+ klass.singleton_class.alias_method :[], :new
114
+ klass.attr_reader(*members)
115
+
116
+ # Dynamically defined initializer methods are in an included module,
117
+ # rather than directly on DataLite (like in ruby 3.2+):
118
+ # * simpler to handle required kwarg ArgumentErrors
119
+ # * easier to ensure consistent ivar assignment order (object shape)
120
+ # * faster than instance_variable_set
121
+ klass.include(Module.new do
122
+ if members.any?
123
+ kwargs = members.map{"#{_1.name}:"}.join(", ")
124
+ params = members.map(&:name).join(", ")
125
+ ivars = members.map{"@#{_1.name}"}.join(", ")
126
+ attrs = members.map{"attrs[:#{_1.name}]"}.join(", ")
127
+ module_eval <<~RUBY, __FILE__, __LINE__ + 1
128
+ protected
129
+ def initialize(#{kwargs}) #{ivars} = #{params}; freeze end
130
+ def marshal_load(attrs) #{ivars} = #{attrs}; freeze end
131
+ RUBY
132
+ end
133
+ end)
134
+
135
+ klass.module_eval do _1.module_eval(&block) end if block_given?
136
+
137
+ klass
138
+ end
139
+
140
+ ##
141
+ # singleton-method: new
142
+ # call-seq:
143
+ # new(*args) -> instance
144
+ # new(**kwargs) -> instance
145
+ #
146
+ # Constuctor for classes defined with ::define.
147
+ #
148
+ # Aliased as ::[].
149
+
150
+ ##
151
+ # singleton-method: []
152
+ # call-seq:
153
+ # ::[](*args) -> instance
154
+ # ::[](**kwargs) -> instance
155
+ #
156
+ # Constuctor for classes defined with ::define.
157
+ #
158
+ # Alias for ::new
159
+
160
+ ##
161
+ def members; self.class.members end
162
+ def attributes; Hash[members.map {|m| [m, send(m)] }] end
163
+ def to_h(&block) attributes.to_h(&block) end
164
+ def hash; [self.class, attributes].hash end
165
+ def ==(other) self.class == other.class && to_h == other.to_h end
166
+ def eql?(other) self.class == other.class && hash == other.hash end
167
+ def deconstruct; attributes.values end
168
+
169
+ def deconstruct_keys(keys)
170
+ raise TypeError unless keys.is_a?(Array) || keys.nil?
171
+ return attributes if keys&.first.nil?
172
+ attributes.slice(*keys)
173
+ end
174
+
175
+ def with(**kwargs)
176
+ return self if kwargs.empty?
177
+ self.class.new(**attributes.merge(kwargs))
178
+ end
179
+
180
+ def inspect
181
+ __inspect_guard__(self) do |seen|
182
+ return "#<data #{self.class}:...>" if seen
183
+ attrs = attributes.map {|kv| "%s=%p" % kv }.join(", ")
184
+ display = ["data", self.class.name, attrs].compact.join(" ")
185
+ "#<#{display}>"
186
+ end
187
+ end
188
+ alias_method :to_s, :inspect
189
+
190
+ private
191
+
192
+ def initialize_copy(source) super.freeze end
193
+ def marshal_dump; attributes end
194
+
195
+ # Yields +true+ if +obj+ has been seen already, +false+ if it hasn't.
196
+ # Marks +obj+ as seen inside the block, so circuler references don't
197
+ # recursively trigger a SystemStackError (stack level too deep).
198
+ #
199
+ # Making circular references inside a Data object _should_ be very
200
+ # uncommon, but we'll support them for the sake of completeness.
201
+ def __inspect_guard__(obj)
202
+ preexisting = Thread.current[:__net_imap_data__inspect__]
203
+ Thread.current[:__net_imap_data__inspect__] ||= {}.compare_by_identity
204
+ inspect_guard = Thread.current[:__net_imap_data__inspect__]
205
+ if inspect_guard.include?(obj)
206
+ yield true
207
+ else
208
+ begin
209
+ inspect_guard[obj] = true
210
+ yield false
211
+ ensure
212
+ inspect_guard.delete(obj)
213
+ end
214
+ end
215
+ ensure
216
+ unless preexisting.equal?(inspect_guard)
217
+ Thread.current[:__net_imap_data__inspect__] = preexisting
218
+ end
219
+ end
220
+
221
+ end
222
+
223
+ end
224
+ end
225
+ # :nocov:
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Net
4
+ class IMAP
5
+ # An "extended search" response (+ESEARCH+). ESearchResult should be
6
+ # returned (instead of SearchResult) by IMAP#search, IMAP#uid_search,
7
+ # IMAP#sort, and IMAP#uid_sort under any of the following conditions:
8
+ #
9
+ # * Return options were specified for IMAP#search or IMAP#uid_search.
10
+ # The server must support a search extension which allows
11
+ # RFC4466[https://www.rfc-editor.org/rfc/rfc4466.html] +return+ options,
12
+ # such as +ESEARCH+, +PARTIAL+, or +IMAP4rev2+.
13
+ # * Return options were specified for IMAP#sort or IMAP#uid_sort.
14
+ # The server must support the +ESORT+ extension
15
+ # {[RFC5267]}[https://www.rfc-editor.org/rfc/rfc5267.html#section-3].
16
+ #
17
+ # *NOTE:* IMAP#search and IMAP#uid_search do not support +ESORT+ yet.
18
+ # * The server supports +IMAP4rev2+ but _not_ +IMAP4rev1+, or +IMAP4rev2+
19
+ # has been enabled. +IMAP4rev2+ requires +ESEARCH+ results.
20
+ #
21
+ # Note that some servers may claim to support a search extension which
22
+ # requires an +ESEARCH+ result, such as +PARTIAL+, but still only return a
23
+ # +SEARCH+ result when +return+ options are specified.
24
+ #
25
+ # Some search extensions may result in the server sending ESearchResult
26
+ # responses after the initiating command has completed. Use
27
+ # IMAP#add_response_handler to handle these responses.
28
+ class ESearchResult < Data.define(:tag, :uid, :data)
29
+ def initialize(tag: nil, uid: nil, data: nil)
30
+ tag => String | nil; tag = -tag if tag
31
+ uid => true | false | nil; uid = !!uid
32
+ data => Array | nil; data ||= []; data.freeze
33
+ super
34
+ end
35
+
36
+ # :call-seq: to_a -> Array of integers
37
+ #
38
+ # When either #all or #partial contains a SequenceSet of message sequence
39
+ # numbers or UIDs, +to_a+ returns that set as an array of integers.
40
+ #
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
43
+ # the IMAP#search +RETURN+ options, #to_a returns an empty array.
44
+ #
45
+ # Note that SearchResult also implements +to_a+, so it can be used without
46
+ # checking if the server returned +SEARCH+ or +ESEARCH+ data.
47
+ def to_a; all&.numbers || partial&.to_a || [] end
48
+
49
+ ##
50
+ # attr_reader: tag
51
+ #
52
+ # The tag string for the command that caused this response to be returned.
53
+ #
54
+ # When +nil+, this response was not caused by a particular command.
55
+
56
+ ##
57
+ # attr_reader: uid
58
+ #
59
+ # Indicates whether #data in this response refers to UIDs (when +true+) or
60
+ # to message sequence numbers (when +false+).
61
+
62
+ ##
63
+ alias uid? uid
64
+
65
+ ##
66
+ # attr_reader: data
67
+ #
68
+ # Search return data, as an array of <tt>[name, value]</tt> pairs. Most
69
+ # return data corresponds to a search +return+ option with the same name.
70
+ #
71
+ # Note that some return data names may be used more than once per result.
72
+ #
73
+ # This data can be more simply retrieved by #min, #max, #all, #count,
74
+ # #modseq, and other methods.
75
+
76
+ # :call-seq: min -> integer or nil
77
+ #
78
+ # The lowest message number/UID that satisfies the SEARCH criteria.
79
+ #
80
+ # Returns +nil+ when the associated search command has no results, or when
81
+ # the +MIN+ return option wasn't specified.
82
+ #
83
+ # Requires +ESEARCH+ {[RFC4731]}[https://www.rfc-editor.org/rfc/rfc4731.html#section-3.1] or
84
+ # +IMAP4rev2+ {[RFC9051]}[https://www.rfc-editor.org/rfc/rfc9051.html#section-7.3.4].
85
+ def min; data.assoc("MIN")&.last end
86
+
87
+ # :call-seq: max -> integer or nil
88
+ #
89
+ # The highest message number/UID that satisfies the SEARCH criteria.
90
+ #
91
+ # Returns +nil+ when the associated search command has no results, or when
92
+ # the +MAX+ return option wasn't specified.
93
+ #
94
+ # Requires +ESEARCH+ {[RFC4731]}[https://www.rfc-editor.org/rfc/rfc4731.html#section-3.1] or
95
+ # +IMAP4rev2+ {[RFC9051]}[https://www.rfc-editor.org/rfc/rfc9051.html#section-7.3.4].
96
+ def max; data.assoc("MAX")&.last end
97
+
98
+ # :call-seq: all -> sequence set or nil
99
+ #
100
+ # A SequenceSet containing all message sequence numbers or UIDs that
101
+ # satisfy the SEARCH criteria.
102
+ #
103
+ # Returns +nil+ when the associated search command has no results, or when
104
+ # the +ALL+ return option was not specified but other return options were.
105
+ #
106
+ # Requires +ESEARCH+ {[RFC4731]}[https://www.rfc-editor.org/rfc/rfc4731.html#section-3.1] or
107
+ # +IMAP4rev2+ {[RFC9051]}[https://www.rfc-editor.org/rfc/rfc9051.html#section-7.3.4].
108
+ #
109
+ # See also: #to_a
110
+ def all; data.assoc("ALL")&.last end
111
+
112
+ # :call-seq: count -> integer or nil
113
+ #
114
+ # Returns the number of messages that satisfy the SEARCH criteria.
115
+ #
116
+ # Returns +nil+ when the associated search command has no results, or when
117
+ # the +COUNT+ return option wasn't specified.
118
+ #
119
+ # Requires +ESEARCH+ {[RFC4731]}[https://www.rfc-editor.org/rfc/rfc4731.html#section-3.1] or
120
+ # +IMAP4rev2+ {[RFC9051]}[https://www.rfc-editor.org/rfc/rfc9051.html#section-7.3.4].
121
+ def count; data.assoc("COUNT")&.last end
122
+
123
+ # :call-seq: modseq -> integer or nil
124
+ #
125
+ # The highest +mod-sequence+ of all messages being returned.
126
+ #
127
+ # Returns +nil+ when the associated search command has no results, or when
128
+ # the +MODSEQ+ search criterion wasn't specified.
129
+ #
130
+ # Note that there is no search +return+ option for +MODSEQ+. It will be
131
+ # returned whenever the +CONDSTORE+ extension has been enabled. Using the
132
+ # +MODSEQ+ search criteria will implicitly enable +CONDSTORE+.
133
+ #
134
+ # Requires +CONDSTORE+ {[RFC7162]}[https://www.rfc-editor.org/rfc/rfc7162.html]
135
+ # and +ESEARCH+ {[RFC4731]}[https://www.rfc-editor.org/rfc/rfc4731.html#section-3.2].
136
+ def modseq; data.assoc("MODSEQ")&.last end
137
+
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
+
178
+ end
179
+ end
180
+ end