Skip to content

Commit

Permalink
🔧 Add :up_to_max_size config for UIDPlusData
Browse files Browse the repository at this point in the history
When `parser_use_deprecated_uidplus_data` is set to `:up_to_max_size`,
ResponseParser uses UIDPlusData when the `uid-set` size is below
`parser_max_deprecated_uidplus_data_size`.  Above that size,
ResponseParser uses AppendUIDData or CopyUIDData.

This option is now the default for v0.5.
  • Loading branch information
nevans committed Feb 6, 2025
1 parent 2f58d02 commit e58aff6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/net/imap/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,15 @@ def self.[](config)
# [+true+ <em>(original default)</em>]
# ResponseParser only uses UIDPlusData.
#
# [+:up_to_max_size+ <em>(default since +v0.5.6+)</em>]
# ResponseParser uses UIDPlusData when the +uid-set+ size is below
# parser_max_deprecated_uidplus_data_size. Above that size,
# ResponseParser uses AppendUIDData or CopyUIDData.
#
# [+false+ <em>(planned default for +v0.6+)</em>]
# ResponseParser _only_ uses AppendUIDData and CopyUIDData.
attr_accessor :parser_use_deprecated_uidplus_data, type: [
true, false
true, :up_to_max_size, false
]

# The maximum +uid-set+ size that ResponseParser will parse into
Expand Down Expand Up @@ -423,7 +428,7 @@ def defaults_hash
sasl_ir: true,
enforce_logindisabled: true,
responses_without_block: :warn,
parser_use_deprecated_uidplus_data: true,
parser_use_deprecated_uidplus_data: :up_to_max_size,
parser_max_deprecated_uidplus_data_size: 100,
).freeze

Expand Down
2 changes: 1 addition & 1 deletion lib/net/imap/response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ def DeprecatedUIDPlus(validity, src_uids = nil, dst_uids)
src_uids &&= src_uids.each_ordered_number.to_a
dst_uids = dst_uids.each_ordered_number.to_a
UIDPlusData.new(validity, src_uids, dst_uids)
else
elsif config.parser_use_deprecated_uidplus_data != :up_to_max_size
parse_error("uid-set is too large: %d > %d", count, max)
end
end
Expand Down
24 changes: 24 additions & 0 deletions test/net/imap/test_imap_response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ def test_fetch_binary_and_binary_size
assert_equal 100, uidplus.assigned_uids.size
end

test "APPENDUID with parser_use_deprecated_uidplus_data = :up_to_max_size" do
parser = Net::IMAP::ResponseParser.new(config: {
parser_use_deprecated_uidplus_data: :up_to_max_size,
parser_max_deprecated_uidplus_data_size: 100
})
response = parser.parse("A004 OK [APPENDUID 1 101:200] Done\r\n")
assert_instance_of Net::IMAP::UIDPlusData, response.data.code.data
response = parser.parse("A004 OK [APPENDUID 1 100:200] Done\r\n")
assert_instance_of Net::IMAP::AppendUIDData, response.data.code.data
end

test "APPENDUID with parser_use_deprecated_uidplus_data = false" do
parser = Net::IMAP::ResponseParser.new(config: {
parser_use_deprecated_uidplus_data: false,
Expand Down Expand Up @@ -302,6 +313,19 @@ def test_fetch_binary_and_binary_size
assert_equal 100, uidplus.source_uids.size
end

test "COPYUID with parser_use_deprecated_uidplus_data = :up_to_max_size" do
parser = Net::IMAP::ResponseParser.new(config: {
parser_use_deprecated_uidplus_data: :up_to_max_size,
parser_max_deprecated_uidplus_data_size: 100
})
response = parser.parse("A004 OK [COPYUID 1 101:200 1:100] Done\r\n")
copyuid = response.data.code.data
assert_instance_of Net::IMAP::UIDPlusData, copyuid
response = parser.parse("A004 OK [COPYUID 1 100:200 1:101] Done\r\n")
copyuid = response.data.code.data
assert_instance_of Net::IMAP::CopyUIDData, copyuid
end

test "COPYUID with parser_use_deprecated_uidplus_data = false" do
parser = Net::IMAP::ResponseParser.new(config: {
parser_use_deprecated_uidplus_data: false,
Expand Down

0 comments on commit e58aff6

Please sign in to comment.