Skip to content
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

Fix: send_message() with recipients as array #55

Merged
merged 1 commit into from
Aug 6, 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
2 changes: 2 additions & 0 deletions lib/net/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ def any_require_smtputf8(addresses)
# * IOError
#
def send_message(msgstr, from_addr, *to_addrs)
to_addrs.flatten!
raise IOError, 'closed session' unless @socket
mailfrom from_addr, any_require_smtputf8(to_addrs)
rcptto_list(to_addrs) {data msgstr}
Expand Down Expand Up @@ -824,6 +825,7 @@ def send_message(msgstr, from_addr, *to_addrs)
# * IOError
#
def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
to_addrs.flatten!
raise IOError, 'closed session' unless @socket
mailfrom from_addr, any_require_smtputf8(to_addrs)
rcptto_list(to_addrs) {data(&block)}
Expand Down
34 changes: 33 additions & 1 deletion test/net/smtp/test_smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ def test_non_continue_auth_login
assert_equal "235", err.response.status
end

def test_send_message
port = fake_server_start
smtp = Net::SMTP.start 'localhost', port
assert_nothing_raised do
smtp.send_message("message", "[email protected]", "[email protected]")
end
end

def test_send_message_with_multiple_recipients
port = fake_server_start
smtp = Net::SMTP.start 'localhost', port
assert_nothing_raised do
smtp.send_message("message", "[email protected]", "[email protected]", "[email protected]")
end
end

def test_send_message_with_multiple_recipients_as_array
port = fake_server_start
smtp = Net::SMTP.start 'localhost', port
assert_nothing_raised do
smtp.send_message("message", "[email protected]", ["[email protected]", "[email protected]"])
end
end

def test_unsuccessful_send_message_server_busy
sock = FakeSocket.new("400 BUSY\r\n")
smtp = Net::SMTP.new 'localhost', 25
Expand Down Expand Up @@ -699,13 +723,21 @@ def fake_server_start(helo: 'localhost', user: nil, password: nil, tls: false, s
else
sock.puts "535 5.7.8 Error: authentication failed: authentication failure\r\n"
end
when /\AMAIL FROM:/, /\ARCPT TO:/
sock.puts "250 2.1.0 Ok\r\n"
when "DATA"
sock.puts "354 End data with <CR><LF>.<CR><LF>\r\n"
in_data = true
when "."
sock.puts "250 2.0.0 Ok: queued as ABCDEFG\r\n"
in_data = false
when "QUIT"
sock.puts "221 2.0.0 Bye\r\n"
sock.close
servers.each(&:close)
break
else
sock.puts "502 5.5.2 Error: command not recognized\r\n"
sock.puts "502 5.5.2 Error: command not recognized\r\n" unless in_data
end
end
end
Expand Down