Skip to content

Commit bc7e458

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 d9fe72a commit bc7e458

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/net/smtp.rb

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

459459
#
460460
# :call-seq:
461-
# 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| ... }
462-
# start(address, port = nil, helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
461+
# 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| ... }
462+
# start(address, port = nil, helo = 'localhost', username = nil, secret = nil, authtype = nil) { |smtp| ... }
463463
#
464464
# Creates a new Net::SMTP object and connects to the server.
465465
#
466466
# This method is equivalent to:
467467
#
468468
# Net::SMTP.new(address, port, tls_verify: flag, tls_hostname: hostname, ssl_context_params: nil)
469-
# .start(helo: helo_domain, user: account, secret: password, authtype: authtype)
469+
# .start(helo: helo_domain, username: account, secret: password, authtype: authtype)
470470
#
471471
# See also: Net::SMTP.new, #start
472472
#
@@ -513,7 +513,7 @@ def debug_output=(arg)
513513
#
514514
# +authtype+ is the SASL authentication mechanism.
515515
#
516-
# +user+ is the authentication or authorization identity.
516+
# +username+ or +user+ is the authentication or authorization identity.
517517
#
518518
# +secret+ or +password+ is your password or other authentication token.
519519
#
@@ -537,15 +537,16 @@ def debug_output=(arg)
537537
#
538538
def SMTP.start(address, port = nil, *args, helo: nil,
539539
user: nil, secret: nil, password: nil, authtype: nil,
540+
username: nil,
540541
tls: false, starttls: :auto,
541542
tls_verify: true, tls_hostname: nil, ssl_context_params: nil,
542543
&block)
543544
raise ArgumentError, "wrong number of arguments (given #{args.size + 2}, expected 1..6)" if args.size > 4
544545
helo ||= args[0] || 'localhost'
545-
user ||= args[1]
546+
username ||= user || args[1]
546547
secret ||= password || args[2]
547548
authtype ||= args[3]
548-
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)
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, username: username, secret: secret, authtype: authtype, &block)
549550
end
550551

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

556557
#
557558
# :call-seq:
558-
# start(helo: 'localhost', user: nil, secret: nil, authtype: nil) { |smtp| ... }
559-
# start(helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
559+
# start(helo: 'localhost', username: nil, secret: nil, authtype: nil) { |smtp| ... }
560+
# start(helo = 'localhost', username = nil, secret = nil, authtype = nil) { |smtp| ... }
560561
#
561562
# Opens a TCP connection and starts the SMTP session.
562563
#
@@ -570,7 +571,7 @@ def started?
570571
#
571572
# +authtype+ is the SASL authentication mechanism.
572573
#
573-
# +user+ is the authentication or authorization identity.
574+
# +username+ or +user+ is the authentication or authorization identity.
574575
#
575576
# +secret+ or +password+ is your password or other authentication token.
576577
#
@@ -594,7 +595,7 @@ def started?
594595
#
595596
# require 'net/smtp'
596597
# smtp = Net::SMTP.new('smtp.mail.server', 25)
597-
# smtp.start(helo: helo_domain, user: account, secret: password, authtype: authtype) do |smtp|
598+
# smtp.start(helo: helo_domain, username: account, secret: password, authtype: authtype) do |smtp|
598599
# smtp.send_message msgstr, '[email protected]', ['[email protected]']
599600
# end
600601
#
@@ -618,10 +619,11 @@ def started?
618619
# * Net::ReadTimeout
619620
# * IOError
620621
#
621-
def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil)
622+
def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil,
623+
username: nil)
622624
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..4)" if args.size > 4
623625
helo ||= args[0] || 'localhost'
624-
user ||= args[1]
626+
username ||= user || args[1]
625627
secret ||= password || args[2]
626628
authtype ||= args[3]
627629
if defined?(OpenSSL::VERSION)
@@ -638,13 +640,13 @@ def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil
638640
end
639641
if block_given?
640642
begin
641-
do_start helo, user, secret, authtype
643+
do_start helo, username, secret, authtype
642644
return yield(self)
643645
ensure
644646
do_finish
645647
end
646648
else
647-
do_start helo, user, secret, authtype
649+
do_start helo, username, secret, authtype
648650
return self
649651
end
650652
end

0 commit comments

Comments
 (0)