net-imap 0.5.11 → 0.6.0

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.
@@ -3,6 +3,7 @@
3
3
  require_relative "config/attr_accessors"
4
4
  require_relative "config/attr_inheritance"
5
5
  require_relative "config/attr_type_coercion"
6
+ require_relative "config/attr_version_defaults"
6
7
 
7
8
  module Net
8
9
  class IMAP
@@ -141,15 +142,7 @@ module Net
141
142
  # Net::IMAP::Config[0.5] == Net::IMAP::Config[0.5r] # => true
142
143
  # Net::IMAP::Config["current"] == Net::IMAP::Config[:current] # => true
143
144
  # Net::IMAP::Config["0.5.6"] == Net::IMAP::Config[0.5r] # => true
144
- def self.version_defaults; @version_defaults end
145
- @version_defaults = Hash.new {|h, k|
146
- # NOTE: String responds to both so the order is significant.
147
- # And ignore non-numeric conversion to zero, because: "wat!?".to_r == 0
148
- (h.fetch(k.to_r, nil) || h.fetch(k.to_f, nil) if k.is_a?(Numeric)) ||
149
- (h.fetch(k.to_sym, nil) if k.respond_to?(:to_sym)) ||
150
- (h.fetch(k.to_r, nil) if k.respond_to?(:to_r) && k.to_r != 0r) ||
151
- (h.fetch(k.to_f, nil) if k.respond_to?(:to_f) && k.to_f != 0.0)
152
- }
145
+ def self.version_defaults; AttrVersionDefaults.version_defaults end
153
146
 
154
147
  # :call-seq:
155
148
  # Net::IMAP::Config[number] -> versioned config
@@ -189,6 +182,7 @@ module Net
189
182
  include AttrAccessors
190
183
  include AttrInheritance
191
184
  include AttrTypeCoercion
185
+ extend AttrVersionDefaults
192
186
 
193
187
  # The debug mode (boolean). The default value is +false+.
194
188
  #
@@ -200,7 +194,7 @@ module Net
200
194
  #
201
195
  # *NOTE:* Versioned default configs inherit #debug from Config.global, and
202
196
  # #load_defaults will not override #debug.
203
- attr_accessor :debug, type: :boolean
197
+ attr_accessor :debug, type: :boolean, default: false
204
198
 
205
199
  # method: debug?
206
200
  # :call-seq: debug? -> boolean
@@ -218,7 +212,7 @@ module Net
218
212
  # See Net::IMAP.new and Net::IMAP#starttls.
219
213
  #
220
214
  # The default value is +30+ seconds.
221
- attr_accessor :open_timeout, type: Integer
215
+ attr_accessor :open_timeout, type: Integer, default: 30
222
216
 
223
217
  # Seconds to wait until an IDLE response is received, after
224
218
  # the client asks to leave the IDLE state.
@@ -226,7 +220,7 @@ module Net
226
220
  # See Net::IMAP#idle and Net::IMAP#idle_done.
227
221
  #
228
222
  # The default value is +5+ seconds.
229
- attr_accessor :idle_response_timeout, type: Integer
223
+ attr_accessor :idle_response_timeout, type: Integer, default: 5
230
224
 
231
225
  # Whether to use the +SASL-IR+ extension when the server and \SASL
232
226
  # mechanism both support it. Can be overridden by the +sasl_ir+ keyword
@@ -240,9 +234,25 @@ module Net
240
234
  # Do not use +SASL-IR+, even when it is supported by the server and the
241
235
  # mechanism.
242
236
  #
237
+ # [+:when_capabilities_cached+]
238
+ # Use +SASL-IR+ when Net::IMAP#capabilities_cached? is +true+ and it is
239
+ # supported by the server and the mechanism, but do not send a
240
+ # +CAPABILITY+ command to discover the server capabilities.
241
+ #
242
+ # <em>(+:when_capabilities_cached+ option was added by +v0.6.0+)</em>
243
+ #
243
244
  # [+true+ <em>(default since +v0.4+)</em>]
244
245
  # Use +SASL-IR+ when it is supported by the server and the mechanism.
245
- attr_accessor :sasl_ir, type: :boolean
246
+ attr_accessor :sasl_ir, type: Enum[
247
+ false, :when_capabilities_cached, true
248
+ ], defaults: {
249
+ 0.0r => false,
250
+ 0.4r => true,
251
+ }
252
+
253
+ # :stopdoc:
254
+ alias sasl_ir? sasl_ir
255
+ # :startdoc:
246
256
 
247
257
  # Controls the behavior of Net::IMAP#login when the +LOGINDISABLED+
248
258
  # capability is present. When enforced, Net::IMAP will raise a
@@ -266,7 +276,10 @@ module Net
266
276
  #
267
277
  attr_accessor :enforce_logindisabled, type: Enum[
268
278
  false, :when_capabilities_cached, true
269
- ]
279
+ ], defaults: {
280
+ 0.0r => false,
281
+ 0.5r => true,
282
+ }
270
283
 
271
284
  # The maximum allowed server response size. When +nil+, there is no limit
272
285
  # on response size.
@@ -300,7 +313,10 @@ module Net
300
313
  #
301
314
  # * original: +nil+ <em>(no limit)</em>
302
315
  # * +0.5+: 512 MiB
303
- attr_accessor :max_response_size, type: Integer?
316
+ attr_accessor :max_response_size, type: Integer?, defaults: {
317
+ 0.0r => nil,
318
+ 0.5r => 512 << 20, # 512 MiB
319
+ }
304
320
 
305
321
  # Controls the behavior of Net::IMAP#responses when called without any
306
322
  # arguments (+type+ or +block+).
@@ -330,7 +346,11 @@ module Net
330
346
  # Note: #responses_without_args is an alias for #responses_without_block.
331
347
  attr_accessor :responses_without_block, type: Enum[
332
348
  :silence_deprecation_warning, :warn, :frozen_dup, :raise,
333
- ]
349
+ ], defaults: {
350
+ 0.0r => :silence_deprecation_warning,
351
+ 0.5r => :warn,
352
+ 0.6r => :frozen_dup,
353
+ }
334
354
 
335
355
  alias responses_without_args responses_without_block # :nodoc:
336
356
  alias responses_without_args= responses_without_block= # :nodoc:
@@ -340,66 +360,69 @@ module Net
340
360
  #
341
361
  # Alias for responses_without_block
342
362
 
343
- # Whether ResponseParser should use the deprecated UIDPlusData or
344
- # CopyUIDData for +COPYUID+ response codes, and UIDPlusData or
345
- # AppendUIDData for +APPENDUID+ response codes.
346
- #
347
- # UIDPlusData stores its data in arrays of numbers, which is vulnerable to
348
- # a memory exhaustion denial of service attack from an untrusted or
349
- # compromised server. Set this option to +false+ to completely block this
350
- # vulnerability. Otherwise, parser_max_deprecated_uidplus_data_size
351
- # mitigates this vulnerability.
363
+ # **NOTE:** <em>+UIDPlusData+ has been removed since +v0.6.0+, and this
364
+ # config option only affects deprecation warnings.
365
+ # This config option will be **removed** in +v0.7.0+.</em>
352
366
  #
353
- # AppendUIDData and CopyUIDData are _mostly_ backward-compatible with
354
- # UIDPlusData. Most applications should be able to upgrade with little
355
- # or no changes.
367
+ # ResponseParser always returns CopyUIDData for +COPYUID+ response codes,
368
+ # and AppendUIDData for +APPENDUID+ response codes. Previously, this
369
+ # option determined when UIDPlusData would be returned instead.
356
370
  #
357
- # <em>(Parser support for +UIDPLUS+ added in +v0.3.2+.)</em>
371
+ # Parser support for +UIDPLUS+ added in +v0.3.2+.
358
372
  #
359
- # <em>(Config option added in +v0.4.19+ and +v0.5.6+.)</em>
373
+ # Config option added in +v0.4.19+ and +v0.5.6+.
360
374
  #
361
- # <em>UIDPlusData will be removed in +v0.6+ and this config setting will
362
- # be ignored.</em>
375
+ # <em>UIDPlusData removed in +v0.6.0+.</em>
363
376
  #
364
- # ==== Valid options
377
+ # ==== Options
365
378
  #
366
379
  # [+true+ <em>(original default)</em>]
367
- # ResponseParser only uses UIDPlusData.
380
+ # <em>Since v0.6.0:</em>
381
+ # Prints a deprecation warning when parsing +COPYUID+ or +APPENDUID+.
368
382
  #
369
383
  # [+:up_to_max_size+ <em>(default since +v0.5.6+)</em>]
370
- # ResponseParser uses UIDPlusData when the +uid-set+ size is below
371
- # parser_max_deprecated_uidplus_data_size. Above that size,
372
- # ResponseParser uses AppendUIDData or CopyUIDData.
384
+ # <em>Since v0.6.0:</em>
385
+ # Prints a deprecation warning when parsing +COPYUID+ or +APPENDUID+.
373
386
  #
374
- # [+false+ <em>(planned default for +v0.6+)</em>]
375
- # ResponseParser _only_ uses AppendUIDData and CopyUIDData.
387
+ # [+false+ <em>(default since +v0.6.0+)</em>]
388
+ # This is the only supported option <em>(since v0.6.0)</em>.
376
389
  attr_accessor :parser_use_deprecated_uidplus_data, type: Enum[
377
390
  true, :up_to_max_size, false
378
- ]
391
+ ], defaults: {
392
+ 0.0r => true,
393
+ 0.5r => :up_to_max_size,
394
+ 0.6r => false,
395
+ }
379
396
 
380
- # The maximum +uid-set+ size that ResponseParser will parse into
381
- # deprecated UIDPlusData. This limit only applies when
382
- # parser_use_deprecated_uidplus_data is not +false+.
397
+ # **NOTE:** <em>+UIDPlusData+ has been removed since +v0.6.0+, and this
398
+ # config option is ignored.
399
+ # This config option will be **removed** in +v0.7.0+.</em>
383
400
  #
384
- # <em>(Parser support for +UIDPLUS+ added in +v0.3.2+.)</em>
401
+ # ResponseParser always returns CopyUIDData for +COPYUID+ response codes,
402
+ # and AppendUIDData for +APPENDUID+ response codes. Previously, this
403
+ # option determined when UIDPlusData would be returned instead.
385
404
  #
386
- # <em>Support for limiting UIDPlusData to a maximum size was added in
387
- # +v0.3.8+, +v0.4.19+, and +v0.5.6+.</em>
405
+ # Parser support for +UIDPLUS+ added in +v0.3.2+.
388
406
  #
389
- # <em>UIDPlusData will be removed in +v0.6+.</em>
407
+ # Support for limiting UIDPlusData to a maximum size was added in
408
+ # +v0.3.8+, +v0.4.19+, and +v0.5.6+.
390
409
  #
391
- # ==== Versioned Defaults
410
+ # <em>UIDPlusData was removed in +v0.6.0+.</em>
392
411
  #
393
- # Because this limit guards against a remote server causing catastrophic
394
- # memory exhaustion, the versioned default (used by #load_defaults) also
395
- # applies to versions without the feature.
412
+ # ==== Versioned Defaults
396
413
  #
397
414
  # * +0.3+ and prior: <tt>10,000</tt>
398
415
  # * +0.4+: <tt>1,000</tt>
399
416
  # * +0.5+: <tt>100</tt>
400
417
  # * +0.6+: <tt>0</tt>
401
418
  #
402
- attr_accessor :parser_max_deprecated_uidplus_data_size, type: Integer
419
+ attr_accessor :parser_max_deprecated_uidplus_data_size, type: Integer,
420
+ defaults: {
421
+ 0.0r => 10_000,
422
+ 0.4r => 1_000,
423
+ 0.5r => 100,
424
+ 0.6r => 0,
425
+ }
403
426
 
404
427
  # Creates a new config object and initialize its attribute with +attrs+.
405
428
  #
@@ -468,85 +491,150 @@ module Net
468
491
  # Returns all config attributes in a hash.
469
492
  def to_h; data.members.to_h { [_1, send(_1)] } end
470
493
 
494
+ # Returns a string representation of overriden config attributes and the
495
+ # inheritance chain.
496
+ #
497
+ # Attributes overridden by ancestors are also inspected, recursively.
498
+ # Attributes that are inherited from default configs are not shown (see
499
+ # Config@Versioned+defaults and Config@Named+defaults).
500
+ #
501
+ # # (Line breaks have been added to the example output for legibility.)
502
+ #
503
+ # Net::IMAP::Config.new(0.4)
504
+ # .new(open_timeout: 10, enforce_logindisabled: true)
505
+ # .inspect
506
+ # #=> "#<Net::IMAP::Config:0x0000745871125410 open_timeout=10 enforce_logindisabled=true
507
+ # # inherits from Net::IMAP::Config[0.4]
508
+ # # inherits from Net::IMAP::Config.global
509
+ # # inherits from Net::IMAP::Config.default>"
510
+ #
511
+ # Non-default attributes are listed after the ancestor config from which
512
+ # they are inherited.
513
+ #
514
+ # # (Line breaks have been added to the example output for legibility.)
515
+ #
516
+ # config = Net::IMAP::Config.global
517
+ # .new(open_timeout: 10, idle_response_timeout: 2)
518
+ # .new(enforce_logindisabled: :when_capabilities_cached, sasl_ir: false)
519
+ # config.inspect
520
+ # #=> "#<Net::IMAP::Config:0x00007ce2a1e20e40 sasl_ir=false enforce_logindisabled=:when_capabilities_cached
521
+ # # inherits from Net::IMAP::Config:0x00007ce2a1e20f80 open_timeout=10 idle_response_timeout=2
522
+ # # inherits from Net::IMAP::Config.global
523
+ # # inherits from Net::IMAP::Config.default>"
524
+ #
525
+ # Net::IMAP.debug = true
526
+ # config.inspect
527
+ # #=> "#<Net::IMAP::Config:0x00007ce2a1e20e40 sasl_ir=false enforce_logindisabled=:when_capabilities_cached
528
+ # # inherits from Net::IMAP::Config:0x00007ce2a1e20f80 open_timeout=10 idle_response_timeout=2
529
+ # # inherits from Net::IMAP::Config.global debug=true
530
+ # # inherits from Net::IMAP::Config.default>"
531
+ #
532
+ # Use +pp+ (see #pretty_print) to inspect _all_ config attributes,
533
+ # including default values.
534
+ #
535
+ # Use #to_h to inspect all config attributes ignoring inheritance.
536
+ def inspect;
537
+ "#<#{inspect_recursive}>"
538
+ end
539
+ alias to_s inspect
540
+
541
+ # Used by PP[https://docs.ruby-lang.org/en/master/PP.html] to create a
542
+ # string representation of all config attributes and the inheritance
543
+ # chain. Inherited attributes are listed with the ancestor config from
544
+ # which they are inherited.
545
+ #
546
+ # pp Config.new[0.4].new(open_timeout: 10, idle_response_timeout: 10)
547
+ # # #<Net::IMAP::Config:0x0000745871125410
548
+ # # open_timeout=10
549
+ # # idle_response_timeout=10
550
+ # # inherits from Net::IMAP::Config[0.4]
551
+ # # responses_without_block=:silence_deprecation_warning
552
+ # # max_response_size=nil
553
+ # # sasl_ir=true
554
+ # # enforce_logindisabled=false
555
+ # # parser_use_deprecated_uidplus_data=true
556
+ # # parser_max_deprecated_uidplus_data_size=1000
557
+ # # inherits from Net::IMAP::Config.global
558
+ # # inherits from Net::IMAP::Config.default
559
+ # # debug=false>
560
+ #
561
+ # Related: #inspect, #to_h.
562
+ def pretty_print(pp)
563
+ pp.group(2, "#<", ">") do
564
+ pretty_print_recursive(pp)
565
+ end
566
+ end
567
+
568
+ # :stopdoc:
569
+
471
570
  protected
472
571
 
473
- def defaults_hash
474
- to_h.reject {|k,v| DEFAULT_TO_INHERIT.include?(k) }
572
+ def named_default?
573
+ equal?(Config.default) ||
574
+ AttrVersionDefaults::VERSIONS.any? { equal? Config[_1] }
475
575
  end
476
576
 
477
- @default = new(
478
- debug: false,
479
- open_timeout: 30,
480
- idle_response_timeout: 5,
481
- sasl_ir: true,
482
- enforce_logindisabled: true,
483
- max_response_size: 512 << 20, # 512 MiB
484
- responses_without_block: :warn,
485
- parser_use_deprecated_uidplus_data: :up_to_max_size,
486
- parser_max_deprecated_uidplus_data_size: 100,
487
- ).freeze
488
-
489
- @global = default.new
490
-
491
- version_defaults[:default] = Config[default.send(:defaults_hash)]
492
-
493
- version_defaults[0r] = Config[:default].dup.update(
494
- sasl_ir: false,
495
- responses_without_block: :silence_deprecation_warning,
496
- enforce_logindisabled: false,
497
- max_response_size: nil,
498
- parser_use_deprecated_uidplus_data: true,
499
- parser_max_deprecated_uidplus_data_size: 10_000,
500
- ).freeze
501
- version_defaults[0.0r] = Config[0r]
502
- version_defaults[0.1r] = Config[0r]
503
- version_defaults[0.2r] = Config[0r]
504
- version_defaults[0.3r] = Config[0r]
505
-
506
- version_defaults[0.4r] = Config[0.3r].dup.update(
507
- sasl_ir: true,
508
- parser_max_deprecated_uidplus_data_size: 1000,
509
- ).freeze
510
-
511
- version_defaults[0.5r] = Config[0.4r].dup.update(
512
- enforce_logindisabled: true,
513
- max_response_size: 512 << 20, # 512 MiB
514
- responses_without_block: :warn,
515
- parser_use_deprecated_uidplus_data: :up_to_max_size,
516
- parser_max_deprecated_uidplus_data_size: 100,
517
- ).freeze
518
-
519
- version_defaults[0.6r] = Config[0.5r].dup.update(
520
- responses_without_block: :frozen_dup,
521
- parser_use_deprecated_uidplus_data: false,
522
- parser_max_deprecated_uidplus_data_size: 0,
523
- ).freeze
524
-
525
- version_defaults[0.7r] = Config[0.6r].dup.update(
526
- ).freeze
527
-
528
- # Safe conversions one way only:
529
- # 0.6r.to_f == 0.6 # => true
530
- # 0.6 .to_r == 0.6r # => false
531
- version_defaults.to_a.each do |k, v|
532
- next unless k in Rational
533
- version_defaults[k.to_f] = v
577
+ def name
578
+ if equal? Config.default then "#{Config}.default"
579
+ elsif equal? Config.global then "#{Config}.global"
580
+ elsif equal? Config[0.0r] then "#{Config}[:original]"
581
+ elsif equal? Config[:default] then "#{Config}[:default]"
582
+ elsif (v = AttrVersionDefaults::VERSIONS.find { equal? Config[_1] })
583
+ "%s[%0.1f]" % [Config, v]
584
+ else
585
+ Kernel.instance_method(:to_s).bind_call(self).delete("<#>")
586
+ end
587
+ end
588
+
589
+ def inspect_recursive(attrs = AttrAccessors.struct.members)
590
+ strings = [name]
591
+ assigned = assigned_attrs_hash(attrs)
592
+ strings.concat assigned.map { "%s=%p" % _1 }
593
+ if parent
594
+ if parent.equal?(Config.default)
595
+ inherited_overrides = []
596
+ elsif parent
597
+ inherited_overrides = attrs - assigned.keys
598
+ inherited_overrides &= DEFAULT_TO_INHERIT if parent.named_default?
599
+ end
600
+ strings << "inherits from #{parent.inspect_recursive(inherited_overrides)}"
601
+ end
602
+ strings.join " "
534
603
  end
535
604
 
536
- current = VERSION.to_r
537
- version_defaults[:original] = Config[0]
538
- version_defaults[:current] = Config[current]
539
- version_defaults[:next] = Config[current + 0.1r]
540
- version_defaults[:future] = Config[current + 0.2r]
605
+ def pretty_print_recursive(pp, attrs = AttrAccessors.struct.members)
606
+ pp.text name
607
+ assigned = assigned_attrs_hash(attrs)
608
+ pp.breakable
609
+ pp.seplist(assigned, ->{pp.breakable}) do |key, val|
610
+ pp.text key.to_s
611
+ pp.text "="
612
+ pp.pp val
613
+ end
614
+ if parent
615
+ pp.breakable if assigned.any?
616
+ pp.nest(2) do
617
+ pp.text "inherits from "
618
+ parent.pretty_print_recursive(pp, attrs - assigned.keys)
619
+ end
620
+ elsif assigned.empty?
621
+ pp.text "(overridden)"
622
+ end
623
+ end
541
624
 
542
- version_defaults.freeze
625
+ def assigned_attrs_hash(attrs)
626
+ own_attrs = attrs.reject { inherited?(_1) }
627
+ own_attrs.to_h { [_1, data[_1]] }
628
+ end
543
629
 
544
- if ($VERBOSE || $DEBUG) && self[:current].to_h != self[:default].to_h
545
- warn "Misconfigured Net::IMAP::Config[:current] => %p,\n" \
546
- " not equal to Net::IMAP::Config[:default] => %p" % [
547
- self[:current].to_h, self[:default].to_h
548
- ]
630
+ def defaults_hash
631
+ to_h.reject {|k,v| DEFAULT_TO_INHERIT.include?(k) }
549
632
  end
633
+
634
+ @default = AttrVersionDefaults.compile_default!
635
+ @global = default.new
636
+ AttrVersionDefaults.compile_version_defaults!
637
+
550
638
  end
551
639
  end
552
640
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Net
4
4
  class IMAP
5
- class ConnectionState < Net::IMAP::Data # :nodoc:
5
+ class ConnectionState < Data # :nodoc:
6
6
  def self.define(symbol, *attrs)
7
7
  symbol => Symbol
8
8
  state = super(*attrs)
@@ -155,57 +155,106 @@ module Net
155
155
 
156
156
  # Common validators of number and nz_number types
157
157
  module NumValidator # :nodoc
158
+ NUMBER_RE = /\A(?:0|[1-9]\d*)\z/
158
159
  module_function
159
160
 
160
- # Check is passed argument valid 'number' in RFC 3501 terminology
161
+ # Check if argument is a valid 'number' according to RFC 3501
162
+ # number = 1*DIGIT
163
+ # ; Unsigned 32-bit integer
164
+ # ; (0 <= n < 4,294,967,296)
161
165
  def valid_number?(num)
162
- # [RFC 3501]
163
- # number = 1*DIGIT
164
- # ; Unsigned 32-bit integer
165
- # ; (0 <= n < 4,294,967,296)
166
- num >= 0 && num < 4294967296
166
+ 0 <= num && num <= 0xffff_ffff
167
167
  end
168
168
 
169
- # Check is passed argument valid 'nz_number' in RFC 3501 terminology
169
+ # Check if argument is a valid 'nz-number' according to RFC 3501
170
+ # nz-number = digit-nz *DIGIT
171
+ # ; Non-zero unsigned 32-bit integer
172
+ # ; (0 < n < 4,294,967,296)
170
173
  def valid_nz_number?(num)
171
- # [RFC 3501]
172
- # nz-number = digit-nz *DIGIT
173
- # ; Non-zero unsigned 32-bit integer
174
- # ; (0 < n < 4,294,967,296)
175
- num != 0 && valid_number?(num)
174
+ 0 < num && num <= 0xffff_ffff
176
175
  end
177
176
 
178
- # Check is passed argument valid 'mod_sequence_value' in RFC 4551 terminology
177
+ # Check if argument is a valid 'mod-sequence-value' according to RFC 4551
178
+ # mod-sequence-value = 1*DIGIT
179
+ # ; Positive unsigned 64-bit integer
180
+ # ; (mod-sequence)
181
+ # ; (1 <= n < 18,446,744,073,709,551,615)
179
182
  def valid_mod_sequence_value?(num)
180
- # mod-sequence-value = 1*DIGIT
181
- # ; Positive unsigned 64-bit integer
182
- # ; (mod-sequence)
183
- # ; (1 <= n < 18,446,744,073,709,551,615)
184
- num >= 1 && num < 18446744073709551615
183
+ 1 <= num && num < 0xffff_ffff_ffff_ffff
184
+ end
185
+
186
+ # Check if argument is a valid 'mod-sequence-valzer' according to RFC 4551
187
+ # mod-sequence-valzer = "0" / mod-sequence-value
188
+ def valid_mod_sequence_valzer?(num)
189
+ 0 <= num && num < 0xffff_ffff_ffff_ffff
185
190
  end
186
191
 
187
192
  # Ensure argument is 'number' or raise DataFormatError
188
193
  def ensure_number(num)
189
194
  return num if valid_number?(num)
190
-
191
- msg = "number must be unsigned 32-bit integer: #{num}"
192
- raise DataFormatError, msg
195
+ raise DataFormatError,
196
+ "number must be unsigned 32-bit integer: #{num}"
193
197
  end
194
198
 
195
- # Ensure argument is 'nz_number' or raise DataFormatError
199
+ # Ensure argument is 'nz-number' or raise DataFormatError
196
200
  def ensure_nz_number(num)
197
201
  return num if valid_nz_number?(num)
198
-
199
- msg = "nz_number must be non-zero unsigned 32-bit integer: #{num}"
200
- raise DataFormatError, msg
202
+ raise DataFormatError,
203
+ "nz-number must be non-zero unsigned 32-bit integer: #{num}"
201
204
  end
202
205
 
203
- # Ensure argument is 'mod_sequence_value' or raise DataFormatError
206
+ # Ensure argument is 'mod-sequence-value' or raise DataFormatError
204
207
  def ensure_mod_sequence_value(num)
205
208
  return num if valid_mod_sequence_value?(num)
209
+ raise DataFormatError,
210
+ "mod-sequence-value must be non-zero unsigned 64-bit integer: #{num}"
211
+ end
212
+
213
+ # Ensure argument is 'mod-sequence-valzer' or raise DataFormatError
214
+ def ensure_mod_sequence_valzer(num)
215
+ return num if valid_mod_sequence_valzer?(num)
216
+ raise DataFormatError,
217
+ "mod-sequence-valzer must be unsigned 64-bit integer: #{num}"
218
+ end
219
+
220
+ # Like #ensure_number, but usable with numeric String input.
221
+ def coerce_number(num)
222
+ case num
223
+ when Integer then ensure_number num
224
+ when NUMBER_RE then ensure_number Integer num
225
+ else
226
+ raise DataFormatError, "%p is not a valid number" % [num]
227
+ end
228
+ end
206
229
 
207
- msg = "mod_sequence_value must be unsigned 64-bit integer: #{num}"
208
- raise DataFormatError, msg
230
+ # Like #ensure_nz_number, but usable with numeric String input.
231
+ def coerce_nz_number(num)
232
+ case num
233
+ when Integer then ensure_nz_number num
234
+ when NUMBER_RE then ensure_nz_number Integer num
235
+ else
236
+ raise DataFormatError, "%p is not a valid nz-number" % [num]
237
+ end
238
+ end
239
+
240
+ # Like #ensure_mod_sequence_value, but usable with numeric String input.
241
+ def coerce_mod_sequence_value(num)
242
+ case num
243
+ when Integer then ensure_mod_sequence_value num
244
+ when NUMBER_RE then ensure_mod_sequence_value Integer num
245
+ else
246
+ raise DataFormatError, "%p is not a valid mod-sequence-value" % [num]
247
+ end
248
+ end
249
+
250
+ # Like #ensure_mod_sequence_valzer, but usable with numeric String input.
251
+ def coerce_mod_sequence_valzer(num)
252
+ case num
253
+ when Integer then ensure_mod_sequence_valzer num
254
+ when NUMBER_RE then ensure_mod_sequence_valzer Integer num
255
+ else
256
+ raise DataFormatError, "%p is not a valid mod-sequence-valzer" % [num]
257
+ end
209
258
  end
210
259
 
211
260
  end
@@ -25,6 +25,12 @@ module Net
25
25
  # Some search extensions may result in the server sending ESearchResult
26
26
  # responses after the initiating command has completed. Use
27
27
  # IMAP#add_response_handler to handle these responses.
28
+ #
29
+ # ==== Compatibility with SearchResult
30
+ #
31
+ # Note that both SearchResult and ESearchResult implement +each+, +to_a+,
32
+ # and +to_sequence_set+. These methods can be used regardless of whether
33
+ # the server returns +SEARCH+ or +ESEARCH+ data (or no data).
28
34
  class ESearchResult < Data.define(:tag, :uid, :data)
29
35
  def initialize(tag: nil, uid: nil, data: nil)
30
36
  tag => String | nil; tag = -tag if tag
@@ -6,7 +6,6 @@ module Net
6
6
  autoload :FetchData, "#{__dir__}/fetch_data"
7
7
  autoload :UIDFetchData, "#{__dir__}/fetch_data"
8
8
  autoload :SearchResult, "#{__dir__}/search_result"
9
- autoload :UIDPlusData, "#{__dir__}/uidplus_data"
10
9
  autoload :AppendUIDData, "#{__dir__}/uidplus_data"
11
10
  autoload :CopyUIDData, "#{__dir__}/uidplus_data"
12
11
  autoload :VanishedData, "#{__dir__}/vanished_data"
@@ -260,8 +259,8 @@ module Net
260
259
  #
261
260
  # === +UIDPLUS+ extension
262
261
  # See {[RFC4315 §3]}[https://www.rfc-editor.org/rfc/rfc4315#section-3].
263
- # * +APPENDUID+, #data is UIDPlusData. See IMAP#append.
264
- # * +COPYUID+, #data is UIDPlusData. See IMAP#copy.
262
+ # * +APPENDUID+, #data is AppendUIDData. See IMAP#append.
263
+ # * +COPYUID+, #data is CopyUIDData. See IMAP#copy.
265
264
  # * +UIDNOTSTICKY+, #data is +nil+. See IMAP#select.
266
265
  #
267
266
  # === +SEARCHRES+ extension
@@ -2017,24 +2017,19 @@ module Net
2017
2017
  CopyUID(validity, src_uids, dst_uids)
2018
2018
  end
2019
2019
 
2020
- def AppendUID(...) DeprecatedUIDPlus(...) || AppendUIDData.new(...) end
2021
- def CopyUID(...) DeprecatedUIDPlus(...) || CopyUIDData.new(...) end
2022
-
2023
2020
  # TODO: remove this code in the v0.6.0 release
2024
2021
  def DeprecatedUIDPlus(validity, src_uids = nil, dst_uids)
2025
2022
  return unless config.parser_use_deprecated_uidplus_data
2026
- compact_uid_sets = [src_uids, dst_uids].compact
2027
- count = compact_uid_sets.map { _1.count_with_duplicates }.max
2028
- max = config.parser_max_deprecated_uidplus_data_size
2029
- if count <= max
2030
- src_uids &&= src_uids.each_ordered_number.to_a
2031
- dst_uids = dst_uids.each_ordered_number.to_a
2032
- UIDPlusData.new(validity, src_uids, dst_uids)
2033
- elsif config.parser_use_deprecated_uidplus_data != :up_to_max_size
2034
- parse_error("uid-set is too large: %d > %d", count, max)
2035
- end
2023
+ warn("#{Config}#parser_use_deprecated_uidplus_data is ignored " \
2024
+ "since v0.6.0. Disable this warning by setting " \
2025
+ "config.parser_use_deprecated_uidplus_data = false.",
2026
+ category: :deprecated, uplevel: 9)
2027
+ nil
2036
2028
  end
2037
2029
 
2030
+ def AppendUID(...) DeprecatedUIDPlus(...) || AppendUIDData.new(...) end
2031
+ def CopyUID(...) DeprecatedUIDPlus(...) || CopyUIDData.new(...) end
2032
+
2038
2033
  ADDRESS_REGEXP = /\G
2039
2034
  \( (?: NIL | #{Patterns::QUOTED_rev2} ) # 1: NAME
2040
2035
  \s (?: NIL | #{Patterns::QUOTED_rev2} ) # 2: ROUTE