@@ -242,6 +242,41 @@ def self.[](config)
242
242
# Use +SASL-IR+ when it is supported by the server and the mechanism.
243
243
attr_accessor :sasl_ir , type : :boolean
244
244
245
+ # The maximum allowed server response size. When +nil+, there is no limit
246
+ # on response size.
247
+ #
248
+ # The default value (512 MiB, since +v0.5.7+) is <em>very high</em> and
249
+ # unlikely to be reached. To use a lower limit, fetch message bodies in
250
+ # chunks rather than all at once. A _much_ lower value should be used
251
+ # with untrusted servers (for example, when connecting to a user-provided
252
+ # hostname).
253
+ #
254
+ # <em>Please Note:</em> this only limits the size per response. It does
255
+ # not prevent a flood of individual responses and it does not limit how
256
+ # many unhandled responses may be stored on the responses hash. See
257
+ # Net::IMAP@Unbounded+memory+use.
258
+ #
259
+ # Socket reads are limited to the maximum remaining bytes for the current
260
+ # response: max_response_size minus the bytes that have already been read.
261
+ # When the limit is reached, or reading a +literal+ _would_ go over the
262
+ # limit, ResponseTooLargeError is raised and the connection is closed.
263
+ # See also #socket_read_limit.
264
+ #
265
+ # Note that changes will not take effect immediately, because the receiver
266
+ # thread may already be waiting for the next response using the previous
267
+ # value. Net::IMAP#noop can force a response and enforce the new setting
268
+ # immediately.
269
+ #
270
+ # ==== Versioned Defaults
271
+ #
272
+ # Net::IMAP#max_response_size <em>was added in +v0.2.5+ and +v0.3.9+ as an
273
+ # attr_accessor, and in +v0.4.20+ and +v0.5.7+ as a delegator to this
274
+ # config attribute.</em>
275
+ #
276
+ # * original: +nil+ <em>(no limit)</em>
277
+ # * +0.5+: 512 MiB
278
+ attr_accessor :max_response_size , type : Integer?
279
+
245
280
# Controls the behavior of Net::IMAP#responses when called without any
246
281
# arguments (+type+ or +block+).
247
282
#
@@ -419,6 +454,7 @@ def defaults_hash
419
454
open_timeout : 30 ,
420
455
idle_response_timeout : 5 ,
421
456
sasl_ir : true ,
457
+ max_response_size : nil ,
422
458
responses_without_block : :silence_deprecation_warning ,
423
459
parser_use_deprecated_uidplus_data : true ,
424
460
parser_max_deprecated_uidplus_data_size : 1000 ,
@@ -430,6 +466,7 @@ def defaults_hash
430
466
431
467
version_defaults [ 0 r] = Config [ :default ] . dup . update (
432
468
sasl_ir : false ,
469
+ max_response_size : nil ,
433
470
parser_use_deprecated_uidplus_data : true ,
434
471
parser_max_deprecated_uidplus_data_size : 10_000 ,
435
472
) . freeze
@@ -444,6 +481,7 @@ def defaults_hash
444
481
) . freeze
445
482
446
483
version_defaults [ 0.5 r] = Config [ 0.4 r] . dup . update (
484
+ max_response_size : 512 << 20 , # 512 MiB
447
485
responses_without_block : :warn ,
448
486
parser_use_deprecated_uidplus_data : :up_to_max_size ,
449
487
parser_max_deprecated_uidplus_data_size : 100 ,
0 commit comments