net-smtp 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/net/smtp.rb +66 -12
  3. data/net-smtp.gemspec +1 -3
  4. metadata +4 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a873c949eb563b55b9ea2d29eaecdf2bad09006b7cc2aab14954971021619de1
4
- data.tar.gz: c7ed69e3a3e56805953b5ff7ed8f31288eeb4bd113a13e559b38fca5fd85e1cf
3
+ metadata.gz: 642b3ab1e326ac890c33653e8293421558c50a8d6cdc3483b5c41edb26bdaebe
4
+ data.tar.gz: 8c31ba69f42e11a41eda04a31cffe375bcca4cee447b9bc1b1cda218a8f905f3
5
5
  SHA512:
6
- metadata.gz: 87fcd365f156b81c1124182b09973665607f201909e3bdd8463a007dadda060f6cde0069d4c8db9127233a61531b276b9a0b15e93b77f691a04baacd4c09c6cc
7
- data.tar.gz: d8930794d97b2c1dbb8e507bc72b6a4e2f58da8f7e14a6546e87aed8082bbaf7be7c0cde7adeb6c80f66d57c6237edeaf5bc07fbbba6e63905e7c5dcf3777ba1
6
+ metadata.gz: a2b5433005fe906635edee7e0bb1c9d0d81a6fff1da5af97ad39b16bf7e8a3330dafa9d9a513a3e83b17fe5a53c1489e07f52445c8cdefd81192f83a8cc4f6e7
7
+ data.tar.gz: be1a223db50575fbb0f14ebac46af142b0f109d422049d5ae49c57a0548c4560904931d8b8c75cc35e95c1978ad9c620ed059bee541d7b443f7a3668e1df2a43
data/lib/net/smtp.rb CHANGED
@@ -35,8 +35,13 @@ module Net
35
35
  attr_reader :response
36
36
 
37
37
  def initialize(response, message: nil)
38
- @response = response
39
- @message = message
38
+ if response.is_a?(::Net::SMTP::Response)
39
+ @response = response
40
+ @message = message
41
+ else
42
+ @response = nil
43
+ @message = message || response
44
+ end
40
45
  end
41
46
 
42
47
  def message
@@ -179,7 +184,7 @@ module Net
179
184
  # user: 'Your Account', secret: 'Your Password', authtype: :cram_md5)
180
185
  #
181
186
  class SMTP < Protocol
182
- VERSION = "0.3.0"
187
+ VERSION = "0.3.2"
183
188
 
184
189
  Revision = %q$Revision$.split[1]
185
190
 
@@ -251,6 +256,15 @@ module Net
251
256
  @ssl_context_params = ssl_context_params
252
257
  end
253
258
 
259
+ # If +true+, verify th server's certificate.
260
+ attr_accessor :tls_verify
261
+
262
+ # The hostname for verifying hostname in the server certificatate.
263
+ attr_accessor :tls_hostname
264
+
265
+ # Hash for additional SSLContext parameters.
266
+ attr_accessor :ssl_context_params
267
+
254
268
  # Provide human-readable stringification of class state.
255
269
  def inspect
256
270
  "#<#{self.class} #{@address}:#{@port} started=#{@started}>"
@@ -274,11 +288,14 @@ module Net
274
288
  capable?('STARTTLS')
275
289
  end
276
290
 
291
+ # true if the EHLO response contains +key+.
277
292
  def capable?(key)
278
293
  return nil unless @capabilities
279
294
  @capabilities[key] ? true : false
280
295
  end
281
- private :capable?
296
+
297
+ # The server capabilities by EHLO response
298
+ attr_reader :capabilities
282
299
 
283
300
  # true if server advertises AUTH PLAIN.
284
301
  # You cannot get valid value before opening SMTP session.
@@ -631,7 +648,7 @@ module Net
631
648
  do_helo helo_domain
632
649
  if ! tls? and (starttls_always? or (capable_starttls? and starttls_auto?))
633
650
  unless capable_starttls?
634
- raise SMTPUnsupportedCommand.new(nil, message: "STARTTLS is not supported on this server")
651
+ raise SMTPUnsupportedCommand, "STARTTLS is not supported on this server"
635
652
  end
636
653
  starttls
637
654
  @socket = new_internet_message_io(tlsconnect(s, @ssl_context_starttls))
@@ -703,9 +720,9 @@ module Net
703
720
  # binary message with this method. +msgstr+ should include both
704
721
  # the message headers and body.
705
722
  #
706
- # +from_addr+ is a String representing the source mail address.
723
+ # +from_addr+ is a String or Net::SMTP::Address representing the source mail address.
707
724
  #
708
- # +to_addr+ is a String or Strings or Array of Strings, representing
725
+ # +to_addr+ is a String or Net::SMTP::Address or Array of them, representing
709
726
  # the destination mail address or addresses.
710
727
  #
711
728
  # === Example
@@ -716,6 +733,12 @@ module Net
716
733
  # ['dest@example.com', 'dest2@example.com']
717
734
  # end
718
735
  #
736
+ # Net::SMTP.start('smtp.example.com') do |smtp|
737
+ # smtp.send_message msgstr,
738
+ # Net::SMTP::Address.new('from@example.com', size: 12345),
739
+ # Net::SMTP::Address.new('dest@example.com', notify: :success)
740
+ # end
741
+ #
719
742
  # === Errors
720
743
  #
721
744
  # This method may raise:
@@ -752,9 +775,9 @@ module Net
752
775
  #
753
776
  # === Parameters
754
777
  #
755
- # +from_addr+ is a String representing the source mail address.
778
+ # +from_addr+ is a String or Net::SMTP::Address representing the source mail address.
756
779
  #
757
- # +to_addr+ is a String or Strings or Array of Strings, representing
780
+ # +to_addr+ is a String or Net::SMTP::Address or Array of them, representing
758
781
  # the destination mail address or addresses.
759
782
  #
760
783
  # === Example
@@ -904,8 +927,10 @@ module Net
904
927
  getok("EHLO #{domain}")
905
928
  end
906
929
 
930
+ # +from_addr+ is +String+ or +Net::SMTP::Address+
907
931
  def mailfrom(from_addr)
908
- getok("MAIL FROM:<#{from_addr}>")
932
+ addr = Address.new(from_addr)
933
+ getok((["MAIL FROM:<#{addr.address}>"] + addr.parameters).join(' '))
909
934
  end
910
935
 
911
936
  def rcptto_list(to_addrs)
@@ -916,7 +941,7 @@ module Net
916
941
  begin
917
942
  rcptto addr
918
943
  rescue SMTPAuthenticationError
919
- unknown_users << addr.dump
944
+ unknown_users << addr.to_s.dump
920
945
  else
921
946
  ok_users << addr
922
947
  end
@@ -929,8 +954,10 @@ module Net
929
954
  ret
930
955
  end
931
956
 
957
+ # +to_addr+ is +String+ or +Net::SMTP::Address+
932
958
  def rcptto(to_addr)
933
- getok("RCPT TO:<#{to_addr}>")
959
+ addr = Address.new(to_addr)
960
+ getok((["RCPT TO:<#{addr.address}>"] + addr.parameters).join(' '))
934
961
  end
935
962
 
936
963
  # This method sends a message.
@@ -1139,6 +1166,33 @@ module Net
1139
1166
  @debug_output << msg + "\n" if @debug_output
1140
1167
  end
1141
1168
 
1169
+ # Address with parametres for MAIL or RCPT command
1170
+ class Address
1171
+ # mail address [String]
1172
+ attr_reader :address
1173
+ # parameters [Array<String>]
1174
+ attr_reader :parameters
1175
+
1176
+ # :call-seq:
1177
+ # initialize(address, parameter, ...)
1178
+ #
1179
+ # address +String+ or +Net::SMTP::Address+
1180
+ # parameter +String+ or +Hash+
1181
+ def initialize(address, *args, **kw_args)
1182
+ if address.kind_of? Address
1183
+ @address = address.address
1184
+ @parameters = address.parameters
1185
+ else
1186
+ @address = address
1187
+ @parameters = (args + [kw_args]).map{|param| Array(param)}.flatten(1).map{|param| Array(param).compact.join('=')}
1188
+ end
1189
+ end
1190
+
1191
+ def to_s
1192
+ @address
1193
+ end
1194
+ end
1195
+
1142
1196
  end # class SMTP
1143
1197
 
1144
1198
  SMTPSession = SMTP # :nodoc:
data/net-smtp.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.description = %q{Simple Mail Transfer Protocol client library for Ruby.}
18
18
  spec.homepage = "https://github.com/ruby/net-smtp"
19
19
  spec.licenses = ["Ruby", "BSD-2-Clause"]
20
- spec.required_ruby_version = ">= 2.5.0"
20
+ spec.required_ruby_version = ">= 2.6.0"
21
21
 
22
22
  spec.metadata["homepage_uri"] = spec.homepage
23
23
  spec.metadata["source_code_uri"] = spec.homepage
@@ -30,6 +30,4 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  spec.add_dependency "net-protocol"
33
- spec.add_dependency "digest"
34
- spec.add_dependency "timeout"
35
33
  end
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.3.0
4
+ version: 0.3.2
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-14 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-protocol
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: digest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: timeout
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
27
  description: Simple Mail Transfer Protocol client library for Ruby.
56
28
  email:
57
29
  - matz@ruby-lang.org
@@ -77,14 +49,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
49
  requirements:
78
50
  - - ">="
79
51
  - !ruby/object:Gem::Version
80
- version: 2.5.0
52
+ version: 2.6.0
81
53
  required_rubygems_version: !ruby/object:Gem::Requirement
82
54
  requirements:
83
55
  - - ">="
84
56
  - !ruby/object:Gem::Version
85
57
  version: '0'
86
58
  requirements: []
87
- rubygems_version: 3.2.22
59
+ rubygems_version: 3.4.0.dev
88
60
  signing_key:
89
61
  specification_version: 4
90
62
  summary: Simple Mail Transfer Protocol client library for Ruby.