Skip to content

Commit d51d12e

Browse files
committed
♻️ Parse uid-set as sequence-set without *
In addition to letting us delete some code, this is also a step towards replacing `UIDPlusData` with new (incompatible) data structures that store UID sets directly, rather than converted into arrays of integers.
1 parent 7bfffe8 commit d51d12e

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

lib/net/imap/response_parser.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ def charset__list
20052005
def resp_code_apnd__data
20062006
validity = number; SP!
20072007
dst_uids = uid_set # uniqueid ⊂ uid-set
2008-
UIDPlusData.new(validity, nil, dst_uids)
2008+
UIDPlus(validity, nil, dst_uids)
20092009
end
20102010

20112011
# already matched: "COPYUID"
@@ -2015,6 +2015,12 @@ def resp_code_copy__data
20152015
validity = number; SP!
20162016
src_uids = uid_set; SP!
20172017
dst_uids = uid_set
2018+
UIDPlus(validity, src_uids, dst_uids)
2019+
end
2020+
2021+
def UIDPlus(validity, src_uids, dst_uids)
2022+
src_uids &&= src_uids.each_ordered_number.to_a
2023+
dst_uids = dst_uids.each_ordered_number.to_a
20182024
UIDPlusData.new(validity, src_uids, dst_uids)
20192025
end
20202026

@@ -2141,15 +2147,9 @@ def nparens__objectid; NIL? ? nil : parens__objectid end
21412147
# uniqueid = nz-number
21422148
# ; Strictly ascending
21432149
def uid_set
2144-
token = match(T_NUMBER, T_ATOM)
2145-
case token.symbol
2146-
when T_NUMBER then [Integer(token.value)]
2147-
when T_ATOM
2148-
token.value.split(",").flat_map {|range|
2149-
range = range.split(":").map {|uniqueid| Integer(uniqueid) }
2150-
range.size == 1 ? range : Range.new(range.min, range.max).to_a
2151-
}
2152-
end
2150+
set = sequence_set
2151+
parse_error("uid-set cannot contain '*'") if set.include_star?
2152+
set
21532153
end
21542154

21552155
def nil_atom

test/net/imap/test_imap_response_parser.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ def test_fetch_binary_and_binary_size
202202
Net::IMAP.debug = debug
203203
end
204204

205+
test "APPENDUID with '*'" do
206+
parser = Net::IMAP::ResponseParser.new
207+
assert_raise_with_message Net::IMAP::ResponseParseError, /uid-set cannot contain '\*'/ do
208+
parser.parse(
209+
"A004 OK [appendUID 1 1:*] Done\r\n"
210+
)
211+
end
212+
end
213+
205214
test "COPYUID with backwards ranges" do
206215
parser = Net::IMAP::ResponseParser.new
207216
response = parser.parse(
@@ -223,4 +232,13 @@ def test_fetch_binary_and_binary_size
223232
)
224233
end
225234

235+
test "COPYUID with '*'" do
236+
parser = Net::IMAP::ResponseParser.new
237+
assert_raise_with_message Net::IMAP::ResponseParseError, /uid-set cannot contain '\*'/ do
238+
parser.parse(
239+
"A004 OK [copyUID 1 1:* 1:*] Done\r\n"
240+
)
241+
end
242+
end
243+
226244
end

0 commit comments

Comments
 (0)