Skip to content

Commit 26176ef

Browse files
committed
Add username keyword param to start
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.
1 parent 5b60464 commit 26176ef

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

lib/net/smtp.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,15 @@ def debug_output=(arg)
459459

460460
#
461461
# :call-seq:
462-
# 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| ... }
463-
# start(address, port = nil, helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
462+
# 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| ... }
463+
# start(address, port = nil, helo = 'localhost', username = nil, secret = nil, authtype = nil) { |smtp| ... }
464464
#
465465
# Creates a new Net::SMTP object and connects to the server.
466466
#
467467
# This method is equivalent to:
468468
#
469469
# Net::SMTP.new(address, port, tls_verify: flag, tls_hostname: hostname, ssl_context_params: nil)
470-
# .start(helo: helo_domain, user: account, secret: password, authtype: authtype)
470+
# .start(helo: helo_domain, username: account, secret: password, authtype: authtype)
471471
#
472472
# See also: Net::SMTP.new, #start
473473
#
@@ -514,7 +514,7 @@ def debug_output=(arg)
514514
#
515515
# +authtype+ is the SASL authentication mechanism.
516516
#
517-
# +user+ is the authentication or authorization identity.
517+
# +username+ or +user+ is the authentication or authorization identity.
518518
#
519519
# +secret+ or +password+ is your password or other authentication token.
520520
#
@@ -538,15 +538,16 @@ def debug_output=(arg)
538538
#
539539
def SMTP.start(address, port = nil, *args, helo: nil,
540540
user: nil, secret: nil, password: nil, authtype: nil,
541+
username: nil,
541542
tls: false, starttls: :auto,
542543
tls_verify: true, tls_hostname: nil, ssl_context_params: nil,
543544
&block)
544545
raise ArgumentError, "wrong number of arguments (given #{args.size + 2}, expected 1..6)" if args.size > 4
545546
helo ||= args[0] || 'localhost'
546-
user ||= args[1]
547+
username ||= user || args[1]
547548
secret ||= password || args[2]
548549
authtype ||= args[3]
549-
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)
550+
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)
550551
end
551552

552553
# +true+ if the \SMTP session has been started.
@@ -556,8 +557,8 @@ def started?
556557

557558
#
558559
# :call-seq:
559-
# start(helo: 'localhost', user: nil, secret: nil, authtype: nil) { |smtp| ... }
560-
# start(helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
560+
# start(helo: 'localhost', username: nil, secret: nil, authtype: nil) { |smtp| ... }
561+
# start(helo = 'localhost', username = nil, secret = nil, authtype = nil) { |smtp| ... }
561562
#
562563
# Opens a TCP connection and starts the SMTP session.
563564
#
@@ -571,7 +572,7 @@ def started?
571572
#
572573
# +authtype+ is the SASL authentication mechanism.
573574
#
574-
# +user+ is the authentication or authorization identity.
575+
# +username+ or +user+ is the authentication or authorization identity.
575576
#
576577
# +secret+ or +password+ is your password or other authentication token.
577578
#
@@ -595,7 +596,7 @@ def started?
595596
#
596597
# require 'net/smtp'
597598
# smtp = Net::SMTP.new('smtp.mail.server', 25)
598-
# smtp.start(helo: helo_domain, user: account, secret: password, authtype: authtype) do |smtp|
599+
# smtp.start(helo: helo_domain, username: account, secret: password, authtype: authtype) do |smtp|
599600
# smtp.send_message msgstr, 'from@example.com', ['dest@example.com']
600601
# end
601602
#
@@ -619,10 +620,11 @@ def started?
619620
# * Net::ReadTimeout
620621
# * IOError
621622
#
622-
def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil)
623+
def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil,
624+
username: nil)
623625
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..4)" if args.size > 4
624626
helo ||= args[0] || 'localhost'
625-
user ||= args[1]
627+
username ||= user || args[1]
626628
secret ||= password || args[2]
627629
authtype ||= args[3]
628630
if defined?(OpenSSL::VERSION)
@@ -639,13 +641,13 @@ def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil
639641
end
640642
if block_given?
641643
begin
642-
do_start helo, user, secret, authtype
644+
do_start helo, username, secret, authtype
643645
return yield(self)
644646
ensure
645647
do_finish
646648
end
647649
else
648-
do_start helo, user, secret, authtype
650+
do_start helo, username, secret, authtype
649651
return self
650652
end
651653
end

0 commit comments

Comments
 (0)