Skip to content

Commit 3017877

Browse files
committed
♻️ Refactor continue-req to new parser style
1 parent ab7d3ee commit 3017877

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/net/imap/response_data.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class TaggedResponse < Struct.new(:tag, :name, :data, :raw_data)
108108
# UntaggedResponse#data when the response type is a "condition" ("OK", "NO",
109109
# "BAD", "PREAUTH", or "BYE").
110110
class ResponseText < Struct.new(:code, :text)
111+
# Used to avoid an allocation when ResponseText is empty
112+
EMPTY = new(nil, "").freeze
113+
111114
##
112115
# method: code
113116
# :call-seq: code -> ResponseCode or nil

lib/net/imap/response_parser.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def unescape_quoted(quoted)
283283
Token = Struct.new(:symbol, :value)
284284

285285
def_char_matchers :SP, " ", :T_SPACE
286+
def_char_matchers :PLUS, "+", :T_PLUS
286287

287288
def_char_matchers :lpar, "(", :T_LPAR
288289
def_char_matchers :rpar, ")", :T_RPAR
@@ -421,15 +422,16 @@ def response
421422
return result
422423
end
423424

425+
# RFC3501 & RFC9051:
426+
# continue-req = "+" SP (resp-text / base64) CRLF
427+
#
428+
# n.b: base64 is valid resp-text. And in the spirit of RFC9051 Appx E 23
429+
# (and to workaround existing servers), we use the following grammar:
430+
#
431+
# continue-req = "+" (SP (resp-text)) CRLF
424432
def continue_req
425-
match(T_PLUS)
426-
token = lookahead
427-
if token.symbol == T_SPACE
428-
shift_token
429-
return ContinuationRequest.new(resp_text, @str)
430-
else
431-
return ContinuationRequest.new(ResponseText.new(nil, ""), @str)
432-
end
433+
PLUS!
434+
ContinuationRequest.new(SP? ? resp_text : ResponseText::EMPTY, @str)
433435
end
434436

435437
def response_untagged

0 commit comments

Comments
 (0)