Skip to content

Commit

Permalink
Add username keyword param to start
Browse files Browse the repository at this point in the history
Although "user" is a reasonable abbreviation, the parameter is more
accurately described as a "username" or an "authentication identity".
They are synonomous here, with "username" winning when both are present.
  • Loading branch information
nevans committed Oct 15, 2023
1 parent 2cfc961 commit fdc1392
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/net/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,15 @@ def debug_output=(arg)

#
# :call-seq:
# start(address, port = nil, helo: 'localhost', user: nil, secret: nil, authtype: nil, tls: false, starttls: :auto, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) { |smtp| ... }
# start(address, port = nil, helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
# start(address, port = nil, helo: 'localhost', username: nil, secret: nil, authtype: nil, tls: false, starttls: :auto, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) { |smtp| ... }
# start(address, port = nil, helo = 'localhost', username = nil, secret = nil, authtype = nil) { |smtp| ... }
#
# Creates a new Net::SMTP object and connects to the server.
#
# This method is equivalent to:
#
# Net::SMTP.new(address, port, tls_verify: flag, tls_hostname: hostname, ssl_context_params: nil)
# .start(helo: helo_domain, user: account, secret: password, authtype: authtype)
# .start(helo: helo_domain, username: account, secret: password, authtype: authtype)
#
# See also: Net::SMTP.new, #start
#
Expand Down Expand Up @@ -513,7 +513,7 @@ def debug_output=(arg)
#
# +authtype+ is the SASL authentication mechanism.
#
# +user+ is the authentication or authorization identity.
# +username+ or +user+ is the authentication or authorization identity.
#
# +secret+ or +password+ is your password or other authentication token.
#
Expand All @@ -537,15 +537,16 @@ def debug_output=(arg)
#
def SMTP.start(address, port = nil, *args, helo: nil,
user: nil, secret: nil, password: nil, authtype: nil,
username: nil,
tls: false, starttls: :auto,
tls_verify: true, tls_hostname: nil, ssl_context_params: nil,
&block)
raise ArgumentError, "wrong number of arguments (given #{args.size + 2}, expected 1..6)" if args.size > 4
helo ||= args[0] || 'localhost'
user ||= args[1]
username ||= user || args[1]
secret ||= password || args[2]
authtype ||= args[3]
new(address, port, tls: tls, starttls: starttls, tls_verify: tls_verify, tls_hostname: tls_hostname, ssl_context_params: ssl_context_params).start(helo: helo, user: user, secret: secret, authtype: authtype, &block)
new(address, port, tls: tls, starttls: starttls, tls_verify: tls_verify, tls_hostname: tls_hostname, ssl_context_params: ssl_context_params).start(helo: helo, username: username, secret: secret, authtype: authtype, &block)
end

# +true+ if the \SMTP session has been started.
Expand All @@ -555,8 +556,8 @@ def started?

#
# :call-seq:
# start(helo: 'localhost', user: nil, secret: nil, authtype: nil) { |smtp| ... }
# start(helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
# start(helo: 'localhost', username: nil, secret: nil, authtype: nil) { |smtp| ... }
# start(helo = 'localhost', username = nil, secret = nil, authtype = nil) { |smtp| ... }
#
# Opens a TCP connection and starts the SMTP session.
#
Expand All @@ -570,7 +571,7 @@ def started?
#
# +authtype+ is the SASL authentication mechanism.
#
# +user+ is the authentication or authorization identity.
# +username+ or +user+ is the authentication or authorization identity.
#
# +secret+ or +password+ is your password or other authentication token.
#
Expand All @@ -594,7 +595,7 @@ def started?
#
# require 'net/smtp'
# smtp = Net::SMTP.new('smtp.mail.server', 25)
# smtp.start(helo: helo_domain, user: account, secret: password, authtype: authtype) do |smtp|
# smtp.start(helo: helo_domain, username: account, secret: password, authtype: authtype) do |smtp|
# smtp.send_message msgstr, '[email protected]', ['[email protected]']
# end
#
Expand All @@ -618,10 +619,11 @@ def started?
# * Net::ReadTimeout
# * IOError
#
def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil)
def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil,
username: nil)
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..4)" if args.size > 4
helo ||= args[0] || 'localhost'
user ||= args[1]
username ||= user || args[1]
secret ||= password || args[2]
authtype ||= args[3]
if defined?(OpenSSL::VERSION)
Expand All @@ -638,13 +640,13 @@ def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil
end
if block_given?
begin
do_start helo, user, secret, authtype
do_start helo, username, secret, authtype
return yield(self)
ensure
do_finish
end
else
do_start helo, user, secret, authtype
do_start helo, username, secret, authtype
return self
end
end
Expand Down

0 comments on commit fdc1392

Please sign in to comment.