net-imap 0.4.24 → 0.5.14
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.
- checksums.yaml +4 -4
- data/Gemfile +10 -1
- data/README.md +10 -4
- data/docs/styles.css +75 -14
- data/lib/net/imap/authenticators.rb +2 -2
- data/lib/net/imap/command_data.rb +73 -78
- data/lib/net/imap/config/attr_type_coercion.rb +22 -10
- data/lib/net/imap/config/attr_version_defaults.rb +93 -0
- data/lib/net/imap/config.rb +70 -94
- data/lib/net/imap/connection_state.rb +48 -0
- data/lib/net/imap/data_encoding.rb +3 -3
- data/lib/net/imap/data_lite.rb +226 -0
- data/lib/net/imap/deprecated_client_options.rb +6 -3
- data/lib/net/imap/errors.rb +6 -0
- data/lib/net/imap/esearch_result.rb +219 -0
- data/lib/net/imap/fetch_data.rb +126 -47
- data/lib/net/imap/flags.rb +1 -1
- data/lib/net/imap/response_data.rb +120 -186
- data/lib/net/imap/response_parser/parser_utils.rb +5 -0
- data/lib/net/imap/response_parser.rb +155 -21
- data/lib/net/imap/response_reader.rb +9 -12
- data/lib/net/imap/sasl/anonymous_authenticator.rb +3 -3
- data/lib/net/imap/sasl/authentication_exchange.rb +52 -20
- data/lib/net/imap/sasl/authenticators.rb +8 -4
- data/lib/net/imap/sasl/client_adapter.rb +77 -26
- data/lib/net/imap/sasl/cram_md5_authenticator.rb +4 -4
- data/lib/net/imap/sasl/digest_md5_authenticator.rb +218 -56
- data/lib/net/imap/sasl/external_authenticator.rb +2 -2
- data/lib/net/imap/sasl/gs2_header.rb +7 -7
- data/lib/net/imap/sasl/login_authenticator.rb +4 -3
- data/lib/net/imap/sasl/oauthbearer_authenticator.rb +6 -6
- data/lib/net/imap/sasl/plain_authenticator.rb +7 -7
- data/lib/net/imap/sasl/protocol_adapters.rb +60 -4
- data/lib/net/imap/sasl/scram_authenticator.rb +10 -10
- data/lib/net/imap/sasl.rb +7 -4
- data/lib/net/imap/sasl_adapter.rb +0 -1
- data/lib/net/imap/search_result.rb +4 -5
- data/lib/net/imap/sequence_set.rb +529 -154
- data/lib/net/imap/stringprep/nameprep.rb +1 -1
- data/lib/net/imap/stringprep/trace.rb +4 -4
- data/lib/net/imap/uidplus_data.rb +2 -84
- data/lib/net/imap/vanished_data.rb +65 -0
- data/lib/net/imap.rb +996 -305
- data/net-imap.gemspec +1 -1
- data/rakelib/rfcs.rake +2 -0
- data/rakelib/string_prep_tables_generator.rb +6 -2
- metadata +7 -2
data/lib/net/imap/config.rb
CHANGED
|
@@ -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
|
|
@@ -75,7 +76,7 @@ module Net
|
|
|
75
76
|
#
|
|
76
77
|
# client = Net::IMAP.new(hostname, config: :future)
|
|
77
78
|
# client.config.sasl_ir # => true
|
|
78
|
-
# client.config.responses_without_block # => :
|
|
79
|
+
# client.config.responses_without_block # => :frozen_dup
|
|
79
80
|
#
|
|
80
81
|
# The versioned default configs inherit certain specific config options from
|
|
81
82
|
# Config.global, for example #debug:
|
|
@@ -109,9 +110,11 @@ module Net
|
|
|
109
110
|
# [+:future+]
|
|
110
111
|
# The _planned_ eventual config for some future +x.y+ version.
|
|
111
112
|
#
|
|
112
|
-
# For example, to
|
|
113
|
+
# For example, to disable all currently deprecated behavior:
|
|
113
114
|
# client = Net::IMAP.new(hostname, config: :future)
|
|
114
|
-
# client.
|
|
115
|
+
# client.config.response_without_args # => :frozen_dup
|
|
116
|
+
# client.responses.frozen? # => true
|
|
117
|
+
# client.responses.values.all?(&:frozen?) # => true
|
|
115
118
|
#
|
|
116
119
|
# == Thread Safety
|
|
117
120
|
#
|
|
@@ -139,15 +142,7 @@ module Net
|
|
|
139
142
|
# Net::IMAP::Config[0.5] == Net::IMAP::Config[0.5r] # => true
|
|
140
143
|
# Net::IMAP::Config["current"] == Net::IMAP::Config[:current] # => true
|
|
141
144
|
# Net::IMAP::Config["0.5.6"] == Net::IMAP::Config[0.5r] # => true
|
|
142
|
-
def self.version_defaults;
|
|
143
|
-
@version_defaults = Hash.new {|h, k|
|
|
144
|
-
# NOTE: String responds to both so the order is significant.
|
|
145
|
-
# And ignore non-numeric conversion to zero, because: "wat!?".to_r == 0
|
|
146
|
-
(h.fetch(k.to_r, nil) || h.fetch(k.to_f, nil) if k.is_a?(Numeric)) ||
|
|
147
|
-
(h.fetch(k.to_sym, nil) if k.respond_to?(:to_sym)) ||
|
|
148
|
-
(h.fetch(k.to_r, nil) if k.respond_to?(:to_r) && k.to_r != 0r) ||
|
|
149
|
-
(h.fetch(k.to_f, nil) if k.respond_to?(:to_f) && k.to_f != 0.0)
|
|
150
|
-
}
|
|
145
|
+
def self.version_defaults; AttrVersionDefaults.version_defaults end
|
|
151
146
|
|
|
152
147
|
# :call-seq:
|
|
153
148
|
# Net::IMAP::Config[number] -> versioned config
|
|
@@ -187,6 +182,7 @@ module Net
|
|
|
187
182
|
include AttrAccessors
|
|
188
183
|
include AttrInheritance
|
|
189
184
|
include AttrTypeCoercion
|
|
185
|
+
extend AttrVersionDefaults
|
|
190
186
|
|
|
191
187
|
# The debug mode (boolean). The default value is +false+.
|
|
192
188
|
#
|
|
@@ -198,7 +194,7 @@ module Net
|
|
|
198
194
|
#
|
|
199
195
|
# *NOTE:* Versioned default configs inherit #debug from Config.global, and
|
|
200
196
|
# #load_defaults will not override #debug.
|
|
201
|
-
attr_accessor :debug, type: :boolean
|
|
197
|
+
attr_accessor :debug, type: :boolean, default: false
|
|
202
198
|
|
|
203
199
|
# method: debug?
|
|
204
200
|
# :call-seq: debug? -> boolean
|
|
@@ -216,7 +212,7 @@ module Net
|
|
|
216
212
|
# See Net::IMAP.new and Net::IMAP#starttls.
|
|
217
213
|
#
|
|
218
214
|
# The default value is +30+ seconds.
|
|
219
|
-
attr_accessor :open_timeout, type: Integer
|
|
215
|
+
attr_accessor :open_timeout, type: Integer, default: 30
|
|
220
216
|
|
|
221
217
|
# Seconds to wait until an IDLE response is received, after
|
|
222
218
|
# the client asks to leave the IDLE state.
|
|
@@ -224,7 +220,7 @@ module Net
|
|
|
224
220
|
# See Net::IMAP#idle and Net::IMAP#idle_done.
|
|
225
221
|
#
|
|
226
222
|
# The default value is +5+ seconds.
|
|
227
|
-
attr_accessor :idle_response_timeout, type: Integer
|
|
223
|
+
attr_accessor :idle_response_timeout, type: Integer, default: 5
|
|
228
224
|
|
|
229
225
|
# Whether to use the +SASL-IR+ extension when the server and \SASL
|
|
230
226
|
# mechanism both support it. Can be overridden by the +sasl_ir+ keyword
|
|
@@ -240,16 +236,46 @@ module Net
|
|
|
240
236
|
#
|
|
241
237
|
# [+true+ <em>(default since +v0.4+)</em>]
|
|
242
238
|
# Use +SASL-IR+ when it is supported by the server and the mechanism.
|
|
243
|
-
attr_accessor :sasl_ir, type: :boolean
|
|
239
|
+
attr_accessor :sasl_ir, type: :boolean, defaults: {
|
|
240
|
+
0.0r => false,
|
|
241
|
+
0.4r => true,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
# Controls the behavior of Net::IMAP#login when the +LOGINDISABLED+
|
|
245
|
+
# capability is present. When enforced, Net::IMAP will raise a
|
|
246
|
+
# LoginDisabledError when that capability is present.
|
|
247
|
+
#
|
|
248
|
+
# <em>(Support for +LOGINDISABLED+ was added in +v0.5.0+.)</em>
|
|
249
|
+
#
|
|
250
|
+
# ==== Valid options
|
|
251
|
+
#
|
|
252
|
+
# [+false+ <em>(original behavior, before support was added)</em>]
|
|
253
|
+
# Send the +LOGIN+ command without checking for +LOGINDISABLED+.
|
|
254
|
+
#
|
|
255
|
+
# [+:when_capabilities_cached+]
|
|
256
|
+
# Enforce the requirement when Net::IMAP#capabilities_cached? is true,
|
|
257
|
+
# but do not send a +CAPABILITY+ command to discover the capabilities.
|
|
258
|
+
#
|
|
259
|
+
# [+true+ <em>(default since +v0.5+)</em>]
|
|
260
|
+
# Only send the +LOGIN+ command if the +LOGINDISABLED+ capability is not
|
|
261
|
+
# present. When capabilities are unknown, Net::IMAP will automatically
|
|
262
|
+
# send a +CAPABILITY+ command first before sending +LOGIN+.
|
|
263
|
+
#
|
|
264
|
+
attr_accessor :enforce_logindisabled, type: Enum[
|
|
265
|
+
false, :when_capabilities_cached, true
|
|
266
|
+
], defaults: {
|
|
267
|
+
0.0r => false,
|
|
268
|
+
0.5r => true,
|
|
269
|
+
}
|
|
244
270
|
|
|
245
271
|
# The maximum allowed server response size. When +nil+, there is no limit
|
|
246
272
|
# on response size.
|
|
247
273
|
#
|
|
248
274
|
# The default value (512 MiB, since +v0.5.7+) is <em>very high</em> and
|
|
249
|
-
# unlikely to be reached.
|
|
250
|
-
#
|
|
251
|
-
#
|
|
252
|
-
#
|
|
275
|
+
# unlikely to be reached. A _much_ lower value should be used with
|
|
276
|
+
# untrusted servers (for example, when connecting to a user-provided
|
|
277
|
+
# hostname). When using a lower limit, message bodies should be fetched
|
|
278
|
+
# in chunks rather than all at once.
|
|
253
279
|
#
|
|
254
280
|
# <em>Please Note:</em> this only limits the size per response. It does
|
|
255
281
|
# not prevent a flood of individual responses and it does not limit how
|
|
@@ -260,7 +286,6 @@ module Net
|
|
|
260
286
|
# response: max_response_size minus the bytes that have already been read.
|
|
261
287
|
# When the limit is reached, or reading a +literal+ _would_ go over the
|
|
262
288
|
# limit, ResponseTooLargeError is raised and the connection is closed.
|
|
263
|
-
# See also #socket_read_limit.
|
|
264
289
|
#
|
|
265
290
|
# Note that changes will not take effect immediately, because the receiver
|
|
266
291
|
# thread may already be waiting for the next response using the previous
|
|
@@ -275,7 +300,10 @@ module Net
|
|
|
275
300
|
#
|
|
276
301
|
# * original: +nil+ <em>(no limit)</em>
|
|
277
302
|
# * +0.5+: 512 MiB
|
|
278
|
-
attr_accessor :max_response_size, type: Integer
|
|
303
|
+
attr_accessor :max_response_size, type: Integer?, defaults: {
|
|
304
|
+
0.0r => nil,
|
|
305
|
+
0.5r => 512 << 20, # 512 MiB
|
|
306
|
+
}
|
|
279
307
|
|
|
280
308
|
# Controls the behavior of Net::IMAP#responses when called without any
|
|
281
309
|
# arguments (+type+ or +block+).
|
|
@@ -305,7 +333,11 @@ module Net
|
|
|
305
333
|
# Note: #responses_without_args is an alias for #responses_without_block.
|
|
306
334
|
attr_accessor :responses_without_block, type: Enum[
|
|
307
335
|
:silence_deprecation_warning, :warn, :frozen_dup, :raise,
|
|
308
|
-
]
|
|
336
|
+
], defaults: {
|
|
337
|
+
0.0r => :silence_deprecation_warning,
|
|
338
|
+
0.5r => :warn,
|
|
339
|
+
0.6r => :frozen_dup,
|
|
340
|
+
}
|
|
309
341
|
|
|
310
342
|
alias responses_without_args responses_without_block # :nodoc:
|
|
311
343
|
alias responses_without_args= responses_without_block= # :nodoc:
|
|
@@ -350,7 +382,11 @@ module Net
|
|
|
350
382
|
# ResponseParser _only_ uses AppendUIDData and CopyUIDData.
|
|
351
383
|
attr_accessor :parser_use_deprecated_uidplus_data, type: Enum[
|
|
352
384
|
true, :up_to_max_size, false
|
|
353
|
-
]
|
|
385
|
+
], defaults: {
|
|
386
|
+
0.0r => true,
|
|
387
|
+
0.5r => :up_to_max_size,
|
|
388
|
+
0.6r => false,
|
|
389
|
+
}
|
|
354
390
|
|
|
355
391
|
# The maximum +uid-set+ size that ResponseParser will parse into
|
|
356
392
|
# deprecated UIDPlusData. This limit only applies when
|
|
@@ -374,7 +410,13 @@ module Net
|
|
|
374
410
|
# * +0.5+: <tt>100</tt>
|
|
375
411
|
# * +0.6+: <tt>0</tt>
|
|
376
412
|
#
|
|
377
|
-
attr_accessor :parser_max_deprecated_uidplus_data_size, type: Integer
|
|
413
|
+
attr_accessor :parser_max_deprecated_uidplus_data_size, type: Integer,
|
|
414
|
+
defaults: {
|
|
415
|
+
0.0r => 10_000,
|
|
416
|
+
0.4r => 1_000,
|
|
417
|
+
0.5r => 100,
|
|
418
|
+
0.6r => 0,
|
|
419
|
+
}
|
|
378
420
|
|
|
379
421
|
# Creates a new config object and initialize its attribute with +attrs+.
|
|
380
422
|
#
|
|
@@ -449,76 +491,10 @@ module Net
|
|
|
449
491
|
to_h.reject {|k,v| DEFAULT_TO_INHERIT.include?(k) }
|
|
450
492
|
end
|
|
451
493
|
|
|
452
|
-
@default =
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
idle_response_timeout: 5,
|
|
456
|
-
sasl_ir: true,
|
|
457
|
-
max_response_size: nil,
|
|
458
|
-
responses_without_block: :silence_deprecation_warning,
|
|
459
|
-
parser_use_deprecated_uidplus_data: true,
|
|
460
|
-
parser_max_deprecated_uidplus_data_size: 1000,
|
|
461
|
-
).freeze
|
|
462
|
-
|
|
463
|
-
@global = default.new
|
|
464
|
-
|
|
465
|
-
version_defaults[:default] = Config[default.send(:defaults_hash)]
|
|
466
|
-
|
|
467
|
-
version_defaults[0r] = Config[:default].dup.update(
|
|
468
|
-
sasl_ir: false,
|
|
469
|
-
max_response_size: nil,
|
|
470
|
-
parser_use_deprecated_uidplus_data: true,
|
|
471
|
-
parser_max_deprecated_uidplus_data_size: 10_000,
|
|
472
|
-
).freeze
|
|
473
|
-
version_defaults[0.0r] = Config[0r]
|
|
474
|
-
version_defaults[0.1r] = Config[0r]
|
|
475
|
-
version_defaults[0.2r] = Config[0r]
|
|
476
|
-
version_defaults[0.3r] = Config[0r]
|
|
477
|
-
|
|
478
|
-
version_defaults[0.4r] = Config[0.3r].dup.update(
|
|
479
|
-
sasl_ir: true,
|
|
480
|
-
parser_max_deprecated_uidplus_data_size: 1000,
|
|
481
|
-
).freeze
|
|
482
|
-
|
|
483
|
-
version_defaults[0.5r] = Config[0.4r].dup.update(
|
|
484
|
-
max_response_size: 512 << 20, # 512 MiB
|
|
485
|
-
responses_without_block: :warn,
|
|
486
|
-
parser_use_deprecated_uidplus_data: :up_to_max_size,
|
|
487
|
-
parser_max_deprecated_uidplus_data_size: 100,
|
|
488
|
-
).freeze
|
|
489
|
-
|
|
490
|
-
version_defaults[0.6r] = Config[0.5r].dup.update(
|
|
491
|
-
responses_without_block: :frozen_dup,
|
|
492
|
-
parser_use_deprecated_uidplus_data: false,
|
|
493
|
-
parser_max_deprecated_uidplus_data_size: 0,
|
|
494
|
-
).freeze
|
|
495
|
-
|
|
496
|
-
version_defaults[0.7r] = Config[0.6r].dup.update(
|
|
497
|
-
).freeze
|
|
498
|
-
|
|
499
|
-
# Safe conversions one way only:
|
|
500
|
-
# 0.6r.to_f == 0.6 # => true
|
|
501
|
-
# 0.6 .to_r == 0.6r # => false
|
|
502
|
-
version_defaults.to_a.each do |k, v|
|
|
503
|
-
next unless k.is_a? Rational
|
|
504
|
-
version_defaults[k.to_f] = v
|
|
505
|
-
end
|
|
506
|
-
|
|
507
|
-
current = VERSION.to_r
|
|
508
|
-
version_defaults[:original] = Config[0]
|
|
509
|
-
version_defaults[:current] = Config[current]
|
|
510
|
-
version_defaults[:next] = Config[current + 0.1r]
|
|
511
|
-
|
|
512
|
-
version_defaults[:future] = Config[0.7r]
|
|
494
|
+
@default = AttrVersionDefaults.compile_default!
|
|
495
|
+
@global = default.new
|
|
496
|
+
AttrVersionDefaults.compile_version_defaults!
|
|
513
497
|
|
|
514
|
-
version_defaults.freeze
|
|
515
|
-
|
|
516
|
-
if ($VERBOSE || $DEBUG) && self[:current].to_h != self[:default].to_h
|
|
517
|
-
warn "Misconfigured Net::IMAP::Config[:current] => %p,\n" \
|
|
518
|
-
" not equal to Net::IMAP::Config[:default] => %p" % [
|
|
519
|
-
self[:current].to_h, self[:default].to_h
|
|
520
|
-
]
|
|
521
|
-
end
|
|
522
498
|
end
|
|
523
499
|
end
|
|
524
500
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Net
|
|
4
|
+
class IMAP
|
|
5
|
+
class ConnectionState < Net::IMAP::Data # :nodoc:
|
|
6
|
+
def self.define(symbol, *attrs)
|
|
7
|
+
symbol => Symbol
|
|
8
|
+
state = super(*attrs)
|
|
9
|
+
state.const_set :NAME, symbol
|
|
10
|
+
state
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def symbol; self.class::NAME end
|
|
14
|
+
def name; self.class::NAME.name end
|
|
15
|
+
alias to_sym symbol
|
|
16
|
+
|
|
17
|
+
def deconstruct; [symbol, *super] end
|
|
18
|
+
|
|
19
|
+
def deconstruct_keys(names)
|
|
20
|
+
hash = super
|
|
21
|
+
hash[:symbol] = symbol if names.nil? || names.include?(:symbol)
|
|
22
|
+
hash[:name] = name if names.nil? || names.include?(:name)
|
|
23
|
+
hash
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_h(&block)
|
|
27
|
+
hash = deconstruct_keys(nil)
|
|
28
|
+
block ? hash.to_h(&block) : hash
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def not_authenticated?; to_sym == :not_authenticated end
|
|
32
|
+
def authenticated?; to_sym == :authenticated end
|
|
33
|
+
def selected?; to_sym == :selected end
|
|
34
|
+
def logout?; to_sym == :logout end
|
|
35
|
+
|
|
36
|
+
NotAuthenticated = define(:not_authenticated)
|
|
37
|
+
Authenticated = define(:authenticated)
|
|
38
|
+
Selected = define(:selected)
|
|
39
|
+
Logout = define(:logout)
|
|
40
|
+
|
|
41
|
+
class << self
|
|
42
|
+
undef :define
|
|
43
|
+
end
|
|
44
|
+
freeze
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -186,7 +186,7 @@ module Net
|
|
|
186
186
|
|
|
187
187
|
# Ensure argument is 'number' or raise DataFormatError
|
|
188
188
|
def ensure_number(num)
|
|
189
|
-
return if valid_number?(num)
|
|
189
|
+
return num if valid_number?(num)
|
|
190
190
|
|
|
191
191
|
msg = "number must be unsigned 32-bit integer: #{num}"
|
|
192
192
|
raise DataFormatError, msg
|
|
@@ -194,7 +194,7 @@ module Net
|
|
|
194
194
|
|
|
195
195
|
# Ensure argument is 'nz_number' or raise DataFormatError
|
|
196
196
|
def ensure_nz_number(num)
|
|
197
|
-
return if valid_nz_number?(num)
|
|
197
|
+
return num if valid_nz_number?(num)
|
|
198
198
|
|
|
199
199
|
msg = "nz_number must be non-zero unsigned 32-bit integer: #{num}"
|
|
200
200
|
raise DataFormatError, msg
|
|
@@ -202,7 +202,7 @@ module Net
|
|
|
202
202
|
|
|
203
203
|
# Ensure argument is 'mod_sequence_value' or raise DataFormatError
|
|
204
204
|
def ensure_mod_sequence_value(num)
|
|
205
|
-
return if valid_mod_sequence_value?(num)
|
|
205
|
+
return num if valid_mod_sequence_value?(num)
|
|
206
206
|
|
|
207
207
|
msg = "mod_sequence_value must be unsigned 64-bit integer: #{num}"
|
|
208
208
|
raise DataFormatError, msg
|
|
@@ -0,0 +1,226 @@
|
|
|
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 = to_h.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 to_h(&block) block ? __to_h__.to_h(&block) : __to_h__ end
|
|
163
|
+
def hash; [self.class, __to_h__].hash end
|
|
164
|
+
def ==(other) self.class == other.class && to_h == other.to_h end
|
|
165
|
+
def eql?(other) self.class == other.class && hash == other.hash end
|
|
166
|
+
def deconstruct; __to_h__.values end
|
|
167
|
+
|
|
168
|
+
def deconstruct_keys(keys)
|
|
169
|
+
raise TypeError unless keys.is_a?(Array) || keys.nil?
|
|
170
|
+
return __to_h__ if keys&.first.nil?
|
|
171
|
+
__to_h__.slice(*keys)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def with(**kwargs)
|
|
175
|
+
return self if kwargs.empty?
|
|
176
|
+
self.class.new(**__to_h__.merge(kwargs))
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def inspect
|
|
180
|
+
__inspect_guard__(self) do |seen|
|
|
181
|
+
return "#<data #{self.class}:...>" if seen
|
|
182
|
+
attrs = __to_h__.map {|kv| "%s=%p" % kv }.join(", ")
|
|
183
|
+
display = ["data", self.class.name, attrs].compact.join(" ")
|
|
184
|
+
"#<#{display}>"
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
alias_method :to_s, :inspect
|
|
188
|
+
|
|
189
|
+
private
|
|
190
|
+
|
|
191
|
+
def initialize_copy(source) super.freeze end
|
|
192
|
+
def marshal_dump; __to_h__ end
|
|
193
|
+
|
|
194
|
+
def __to_h__; Hash[members.map {|m| [m, send(m)] }] end
|
|
195
|
+
|
|
196
|
+
# Yields +true+ if +obj+ has been seen already, +false+ if it hasn't.
|
|
197
|
+
# Marks +obj+ as seen inside the block, so circuler references don't
|
|
198
|
+
# recursively trigger a SystemStackError (stack level too deep).
|
|
199
|
+
#
|
|
200
|
+
# Making circular references inside a Data object _should_ be very
|
|
201
|
+
# uncommon, but we'll support them for the sake of completeness.
|
|
202
|
+
def __inspect_guard__(obj)
|
|
203
|
+
preexisting = Thread.current[:__net_imap_data__inspect__]
|
|
204
|
+
Thread.current[:__net_imap_data__inspect__] ||= {}.compare_by_identity
|
|
205
|
+
inspect_guard = Thread.current[:__net_imap_data__inspect__]
|
|
206
|
+
if inspect_guard.include?(obj)
|
|
207
|
+
yield true
|
|
208
|
+
else
|
|
209
|
+
begin
|
|
210
|
+
inspect_guard[obj] = true
|
|
211
|
+
yield false
|
|
212
|
+
ensure
|
|
213
|
+
inspect_guard.delete(obj)
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
ensure
|
|
217
|
+
unless preexisting.equal?(inspect_guard)
|
|
218
|
+
Thread.current[:__net_imap_data__inspect__] = preexisting
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
# :nocov:
|
|
@@ -83,10 +83,12 @@ module Net
|
|
|
83
83
|
elsif deprecated.empty?
|
|
84
84
|
super host, port: port_or_options
|
|
85
85
|
elsif deprecated.shift
|
|
86
|
-
warn
|
|
86
|
+
warn("DEPRECATED: Call Net::IMAP.new with keyword options",
|
|
87
|
+
uplevel: 1, category: :deprecated)
|
|
87
88
|
super host, port: port_or_options, ssl: create_ssl_params(*deprecated)
|
|
88
89
|
else
|
|
89
|
-
warn
|
|
90
|
+
warn("DEPRECATED: Call Net::IMAP.new with keyword options",
|
|
91
|
+
uplevel: 1, category: :deprecated)
|
|
90
92
|
super host, port: port_or_options, ssl: false
|
|
91
93
|
end
|
|
92
94
|
end
|
|
@@ -113,7 +115,8 @@ module Net
|
|
|
113
115
|
elsif deprecated.first.respond_to?(:to_hash)
|
|
114
116
|
super(**Hash.try_convert(deprecated.first))
|
|
115
117
|
else
|
|
116
|
-
warn
|
|
118
|
+
warn("DEPRECATED: Call Net::IMAP#starttls with keyword options",
|
|
119
|
+
uplevel: 1, category: :deprecated)
|
|
117
120
|
super(**create_ssl_params(*deprecated))
|
|
118
121
|
end
|
|
119
122
|
end
|
data/lib/net/imap/errors.rb
CHANGED
|
@@ -7,6 +7,12 @@ module Net
|
|
|
7
7
|
class Error < StandardError
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
class LoginDisabledError < Error
|
|
11
|
+
def initialize(msg = "Remote server has disabled the LOGIN command", ...)
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
10
16
|
# Error raised when data is in the incorrect format.
|
|
11
17
|
class DataFormatError < Error
|
|
12
18
|
end
|