Skip to content

Commit 6a840b5

Browse files
committed
♻️ Simplify BADCHARSET parsing
1 parent 113d3f7 commit 6a840b5

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

lib/net/imap/response_parser.rb

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ def resp_text_code
15071507
when "UNSEEN" then SP!; nz_number # rev1 only
15081508
when "APPENDUID" then SP!; resp_code_apnd__data # rev2, UIDPLUS
15091509
when "COPYUID" then SP!; resp_code_copy__data # rev2, UIDPLUS
1510-
when "BADCHARSET" then charset_list
1510+
when "BADCHARSET" then SP? ? charset__list : []
15111511
when "ALERT", "PARSE", "READ-ONLY", "READ-WRITE", "TRYCREATE"
15121512
when "NOMODSEQ" # CONDSTORE
15131513
else
@@ -1523,17 +1523,9 @@ def text_chars_except_rbra
15231523
match_re(CTEXT_REGEXP, '1*<any TEXT-CHAR except "]">')[0]
15241524
end
15251525

1526-
def charset_list
1527-
result = []
1528-
if accept(T_SPACE)
1529-
match(T_LPAR)
1530-
result << charset
1531-
while accept(T_SPACE)
1532-
result << charset
1533-
end
1534-
match(T_RPAR)
1535-
end
1536-
result
1526+
# "(" charset *(SP charset) ")"
1527+
def charset__list
1528+
lpar; list = [charset]; while SP? do list << charset end; rpar; list
15371529
end
15381530

15391531
# already matched: "APPENDUID"
@@ -1644,13 +1636,7 @@ def flag_list
16441636
# See https://www.rfc-editor.org/errata/rfc3501
16451637
#
16461638
# charset = atom / quoted
1647-
def charset
1648-
if token = accept(T_QUOTED)
1649-
token.value
1650-
else
1651-
atom
1652-
end
1653-
end
1639+
def charset; quoted? || atom end
16541640

16551641
# RFC7162:
16561642
# mod-sequence-value = 1*DIGIT

0 commit comments

Comments
 (0)