Skip to content

♻️ Refactor Net::IMAP#get_response (internal) #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3433,22 +3433,27 @@ def get_tagged_response(tag, cmd, timeout = nil)

def get_response
buff = String.new
while true
s = @sock.gets(CRLF)
break unless s
buff.concat(s)
if /\{(\d+)\}\r\n/n =~ s
s = @sock.read($1.to_i)
buff.concat(s)
else
break
catch :eof do
while true
get_response_line(buff)
break unless /\{(\d+)\}\r\n\z/n =~ buff
get_response_literal(buff, $1.to_i)
end
end
return nil if buff.length == 0
if config.debug?
$stderr.print(buff.gsub(/^/n, "S: "))
end
return @parser.parse(buff)
$stderr.print(buff.gsub(/^/n, "S: ")) if config.debug?
@parser.parse(buff)
end

def get_response_line(buff)
line = @sock.gets(CRLF) or throw :eof
buff << line
end

def get_response_literal(buff, literal_size)
literal = String.new(capacity: literal_size)
@sock.read(literal_size, literal) or throw :eof
buff << literal
end

#############################
Expand Down
Loading