net-smtp 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/net/smtp.rb +31 -20
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd4c86f571640cbc5441b71f2b0bb89d9cf2b39be60e539dac54b9fc040c7343
4
- data.tar.gz: dbe764b541202fe9c38437ca405eb910ba56b2909424ab37fa5d5cb82b719b50
3
+ metadata.gz: a873c949eb563b55b9ea2d29eaecdf2bad09006b7cc2aab14954971021619de1
4
+ data.tar.gz: c7ed69e3a3e56805953b5ff7ed8f31288eeb4bd113a13e559b38fca5fd85e1cf
5
5
  SHA512:
6
- metadata.gz: fd4c00192ae2ea98feb77d2426f41a9ca1b408350b74d3f937f02dea06ae9bf4d00f6d37cbebcf6e379f0cb9c8fcb0d03125ecc488f4cb74286deba1e40fa9c9
7
- data.tar.gz: ffc30083a8984d0dd10351e06acca9dd491846d6cc5e3310b5dfb30d436569da7dc26fa2f253a55789bb0feb2484542be37f448fd51d3c7c66105213c7159666
6
+ metadata.gz: 87fcd365f156b81c1124182b09973665607f201909e3bdd8463a007dadda060f6cde0069d4c8db9127233a61531b276b9a0b15e93b77f691a04baacd4c09c6cc
7
+ data.tar.gz: d8930794d97b2c1dbb8e507bc72b6a4e2f58da8f7e14a6546e87aed8082bbaf7be7c0cde7adeb6c80f66d57c6237edeaf5bc07fbbba6e63905e7c5dcf3777ba1
data/lib/net/smtp.rb CHANGED
@@ -179,7 +179,7 @@ module Net
179
179
  # user: 'Your Account', secret: 'Your Password', authtype: :cram_md5)
180
180
  #
181
181
  class SMTP < Protocol
182
- VERSION = "0.2.2"
182
+ VERSION = "0.3.0"
183
183
 
184
184
  Revision = %q$Revision$.split[1]
185
185
 
@@ -215,11 +215,23 @@ module Net
215
215
  # server. +port+ is the port to connect to; it defaults to
216
216
  # port 25.
217
217
  #
218
+ # If +tls+ is true, enable TLS. The default is false.
219
+ # If +starttls+ is :always, enable STARTTLS, if +:auto+, use STARTTLS when the server supports it,
220
+ # if false, disable STARTTLS.
221
+ #
222
+ # If +tls_verify+ is true, verify the server's certificate. The default is true.
223
+ # If the hostname in the server certificate is different from +address+,
224
+ # it can be specified with +tls_hostname+.
225
+ #
226
+ # Additional SSLContext params can be added to +ssl_context_params+ hash argument and are passed to
227
+ # +OpenSSL::SSL::SSLContext#set_params+
228
+ #
229
+ # +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
218
230
  # This method does not open the TCP connection. You can use
219
231
  # SMTP.start instead of SMTP.new if you want to do everything
220
232
  # at once. Otherwise, follow SMTP.new with SMTP#start.
221
233
  #
222
- def initialize(address, port = nil)
234
+ def initialize(address, port = nil, tls: false, starttls: :auto, tls_verify: true, tls_hostname: nil, ssl_context_params: nil)
223
235
  @address = address
224
236
  @port = (port || SMTP.default_port)
225
237
  @esmtp = true
@@ -230,10 +242,13 @@ module Net
230
242
  @read_timeout = 60
231
243
  @error_occurred = false
232
244
  @debug_output = nil
233
- @tls = false
234
- @starttls = :auto
245
+ @tls = tls
246
+ @starttls = starttls
235
247
  @ssl_context_tls = nil
236
248
  @ssl_context_starttls = nil
249
+ @tls_verify = tls_verify
250
+ @tls_hostname = tls_hostname
251
+ @ssl_context_params = ssl_context_params
237
252
  end
238
253
 
239
254
  # Provide human-readable stringification of class state.
@@ -417,7 +432,7 @@ module Net
417
432
 
418
433
  #
419
434
  # :call-seq:
420
- # start(address, port = nil, helo: 'localhost', user: nil, secret: nil, authtype: nil, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) { |smtp| ... }
435
+ # 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| ... }
421
436
  # start(address, port = nil, helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
422
437
  #
423
438
  # Creates a new Net::SMTP object and connects to the server.
@@ -454,6 +469,11 @@ module Net
454
469
  # or other authentication token; and +authtype+ is the authentication
455
470
  # type, one of :plain, :login, or :cram_md5. See the discussion of
456
471
  # SMTP Authentication in the overview notes.
472
+ #
473
+ # If +tls+ is true, enable TLS. The default is false.
474
+ # If +starttls+ is :always, enable STARTTLS, if +:auto+, use STARTTLS when the server supports it,
475
+ # if false, disable STARTTLS.
476
+ #
457
477
  # If +tls_verify+ is true, verify the server's certificate. The default is true.
458
478
  # If the hostname in the server certificate is different from +address+,
459
479
  # it can be specified with +tls_hostname+.
@@ -478,6 +498,7 @@ module Net
478
498
  #
479
499
  def SMTP.start(address, port = nil, *args, helo: nil,
480
500
  user: nil, secret: nil, password: nil, authtype: nil,
501
+ tls: false, starttls: :auto,
481
502
  tls_verify: true, tls_hostname: nil, ssl_context_params: nil,
482
503
  &block)
483
504
  raise ArgumentError, "wrong number of arguments (given #{args.size + 2}, expected 1..6)" if args.size > 4
@@ -485,7 +506,7 @@ module Net
485
506
  user ||= args[1]
486
507
  secret ||= password || args[2]
487
508
  authtype ||= args[3]
488
- new(address, port).start(helo: helo, user: user, secret: secret, authtype: authtype, tls_verify: tls_verify, tls_hostname: tls_hostname, ssl_context_params: ssl_context_params, &block)
509
+ 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)
489
510
  end
490
511
 
491
512
  # +true+ if the SMTP session has been started.
@@ -495,7 +516,7 @@ module Net
495
516
 
496
517
  #
497
518
  # :call-seq:
498
- # start(helo: 'localhost', user: nil, secret: nil, authtype: nil, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) { |smtp| ... }
519
+ # start(helo: 'localhost', user: nil, secret: nil, authtype: nil) { |smtp| ... }
499
520
  # start(helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
500
521
  #
501
522
  # Opens a TCP connection and starts the SMTP session.
@@ -510,14 +531,6 @@ module Net
510
531
  # the type of authentication to attempt; it must be one of
511
532
  # :login, :plain, and :cram_md5. See the notes on SMTP Authentication
512
533
  # in the overview.
513
- # If +tls_verify+ is true, verify the server's certificate. The default is true.
514
- # If the hostname in the server certificate is different from +address+,
515
- # it can be specified with +tls_hostname+.
516
- #
517
- # Additional SSLContext params can be added to +ssl_context_params+ hash argument and are passed to
518
- # +OpenSSL::SSL::SSLContext#set_params+
519
- #
520
- # +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
521
534
  #
522
535
  # === Block Usage
523
536
  #
@@ -556,17 +569,16 @@ module Net
556
569
  # * Net::ReadTimeout
557
570
  # * IOError
558
571
  #
559
- def start(*args, helo: nil,
560
- user: nil, secret: nil, password: nil, authtype: nil, tls_verify: true, tls_hostname: nil, ssl_context_params: nil)
572
+ def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil)
561
573
  raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..4)" if args.size > 4
562
574
  helo ||= args[0] || 'localhost'
563
575
  user ||= args[1]
564
576
  secret ||= password || args[2]
565
577
  authtype ||= args[3]
566
578
  if defined?(OpenSSL::VERSION)
567
- ssl_context_params = ssl_context_params ? ssl_context_params : {}
579
+ ssl_context_params = @ssl_context_params || {}
568
580
  unless ssl_context_params.has_key?(:verify_mode)
569
- ssl_context_params[:verify_mode] = tls_verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
581
+ ssl_context_params[:verify_mode] = @tls_verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
570
582
  end
571
583
  if @tls && @ssl_context_tls.nil?
572
584
  @ssl_context_tls = SMTP.default_ssl_context(ssl_context_params)
@@ -574,7 +586,6 @@ module Net
574
586
  if @starttls && @ssl_context_starttls.nil?
575
587
  @ssl_context_starttls = SMTP.default_ssl_context(ssl_context_params)
576
588
  end
577
- @tls_hostname = tls_hostname
578
589
  end
579
590
  if block_given?
580
591
  begin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-smtp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-09 00:00:00.000000000 Z
11
+ date: 2021-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-protocol