Skip to content

✨ Add greeting code data to responses #94

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 1 commit into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ def initialize(host, port_or_options = {},
else
@usessl = false
end
@responses = Hash.new([].freeze)
@responses = Hash.new {|h, k| h[k] = [] }
@tagged_responses = {}
@response_handlers = []
@tagged_response_arrival = new_cond
Expand All @@ -2150,6 +2150,7 @@ def initialize(host, port_or_options = {},
if @greeting.nil?
raise Error, "connection closed"
end
record_untagged_response_code(@greeting)
if @greeting.name == "BYE"
raise ByeResponseError, @greeting
end
Expand Down Expand Up @@ -2214,10 +2215,7 @@ def receive_responses
end
when UntaggedResponse
record_response(resp.name, resp.data)
if resp.data.instance_of?(ResponseText) &&
(code = resp.data.code)
record_response(code.name, code.data)
end
record_untagged_response_code(resp)
if resp.name == "BYE" && @logout_command_tag.nil?
@sock.close
@exception = ByeResponseError.new(resp)
Expand Down Expand Up @@ -2295,6 +2293,13 @@ def get_response
return @parser.parse(buff)
end

def record_untagged_response_code(resp)
if resp.data.instance_of?(ResponseText) &&
(code = resp.data.code)
record_response(code.name, code.data)
end
end

def record_response(name, data)
unless @responses.has_key?(name)
@responses[name] = []
Expand Down
5 changes: 5 additions & 0 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,12 @@ def test_responses
end
begin
imap = Net::IMAP.new(server_addr, port: port)
# responses available before SELECT/EXAMINE
assert_equal(%w[IMAP4REV1 AUTH=PLAIN STARTTLS],
imap.responses("CAPABILITY", &:last))
resp = imap.select "INBOX"
# responses are cleared after SELECT/EXAMINE
assert_equal(nil, imap.responses("CAPABILITY", &:last))
assert_equal([Net::IMAP::TaggedResponse, "RUBY0001", "OK"],
[resp.class, resp.tag, resp.name])
assert_equal([172], imap.responses { _1["EXISTS"] })
Expand Down