ronin-support 0.3.0 → 0.4.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog.md +77 -7
- data/README.md +19 -3
- data/gemspec.yml +2 -2
- data/lib/ronin/extensions/regexp.rb +50 -2
- data/lib/ronin/extensions/string.rb +1 -0
- data/lib/ronin/formatting.rb +1 -0
- data/lib/ronin/formatting/extensions.rb +1 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +56 -5
- data/lib/ronin/formatting/extensions/html/string.rb +6 -7
- data/lib/ronin/formatting/extensions/sql/string.rb +34 -0
- data/lib/ronin/formatting/extensions/text/string.rb +0 -180
- data/lib/ronin/fuzzing.rb +21 -0
- data/lib/ronin/fuzzing/extensions.rb +20 -0
- data/lib/ronin/fuzzing/extensions/string.rb +380 -0
- data/lib/ronin/fuzzing/fuzzing.rb +191 -0
- data/lib/ronin/network/esmtp.rb +94 -1
- data/lib/ronin/network/extensions/esmtp/net.rb +2 -82
- data/lib/ronin/network/extensions/http/net.rb +1 -736
- data/lib/ronin/network/extensions/imap/net.rb +1 -103
- data/lib/ronin/network/extensions/pop3/net.rb +1 -71
- data/lib/ronin/network/extensions/smtp/net.rb +2 -157
- data/lib/ronin/network/extensions/ssl/net.rb +1 -132
- data/lib/ronin/network/extensions/tcp/net.rb +2 -296
- data/lib/ronin/network/extensions/telnet/net.rb +1 -135
- data/lib/ronin/network/extensions/udp/net.rb +2 -214
- data/lib/ronin/network/http/http.rb +750 -5
- data/lib/ronin/network/imap.rb +105 -2
- data/lib/ronin/network/mixins.rb +1 -1
- data/lib/ronin/network/mixins/esmtp.rb +49 -52
- data/lib/ronin/network/mixins/http.rb +49 -53
- data/lib/ronin/network/mixins/imap.rb +47 -44
- data/lib/ronin/network/mixins/mixin.rb +58 -0
- data/lib/ronin/network/mixins/pop3.rb +44 -38
- data/lib/ronin/network/mixins/smtp.rb +49 -51
- data/lib/ronin/network/mixins/tcp.rb +56 -69
- data/lib/ronin/network/mixins/telnet.rb +57 -50
- data/lib/ronin/network/mixins/udp.rb +48 -52
- data/lib/ronin/network/network.rb +1 -0
- data/lib/ronin/network/pop3.rb +72 -2
- data/lib/ronin/network/smtp/email.rb +1 -0
- data/lib/ronin/network/smtp/smtp.rb +159 -3
- data/lib/ronin/network/ssl.rb +131 -2
- data/lib/ronin/network/tcp.rb +306 -1
- data/lib/ronin/network/telnet.rb +136 -2
- data/lib/ronin/network/udp.rb +229 -1
- data/lib/ronin/support.rb +2 -3
- data/lib/ronin/support/support.rb +38 -0
- data/lib/ronin/support/version.rb +1 -1
- data/lib/ronin/templates/erb.rb +2 -1
- data/lib/ronin/ui/output/helpers.rb +35 -1
- data/lib/ronin/ui/shell.rb +12 -2
- data/lib/ronin/wordlist.rb +157 -0
- data/spec/extensions/regexp_spec.rb +38 -0
- data/spec/formatting/html/string_spec.rb +1 -1
- data/spec/formatting/sql/string_spec.rb +23 -3
- data/spec/formatting/text/string_spec.rb +0 -110
- data/spec/fuzzing/string_spec.rb +158 -0
- data/spec/wordlist_spec.rb +65 -0
- metadata +35 -27
@@ -17,11 +17,8 @@
|
|
17
17
|
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#
|
19
19
|
|
20
|
+
require 'ronin/network/mixins/mixin'
|
20
21
|
require 'ronin/network/telnet'
|
21
|
-
require 'ronin/ui/output/helpers'
|
22
|
-
require 'ronin/mixin'
|
23
|
-
|
24
|
-
require 'parameters'
|
25
22
|
|
26
23
|
module Ronin
|
27
24
|
module Network
|
@@ -40,34 +37,30 @@ module Ronin
|
|
40
37
|
# * `telnet_ssl` (`Boolean`) - Enable Telnet over SSL. Defaults to `true`.
|
41
38
|
#
|
42
39
|
module Telnet
|
43
|
-
include Mixin
|
44
|
-
|
45
|
-
mixin UI::Output::Helpers, Parameters
|
40
|
+
include Mixin, Network::Telnet
|
46
41
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
:description => 'Telnet host'
|
42
|
+
# Telnet host
|
43
|
+
parameter :host, :type => String,
|
44
|
+
:description => 'Telnet host'
|
51
45
|
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
# Telnet port
|
47
|
+
parameter :port, :type => Integer,
|
48
|
+
:description => 'Telnet port'
|
55
49
|
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
# Telnet user
|
51
|
+
parameter :telnet_user, :type => String,
|
52
|
+
:description => 'Telnet user to login as'
|
59
53
|
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
# Telnet password
|
55
|
+
parameter :telnet_password, :type => String,
|
56
|
+
:description => 'Telnet password to login with'
|
63
57
|
|
64
|
-
|
65
|
-
|
58
|
+
# Telnet proxy
|
59
|
+
parameter :telnet_proxy, :description => 'Telnet proxy'
|
66
60
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
61
|
+
# Enable Telnet SSL
|
62
|
+
parameter :telnet_ssl, :type => true,
|
63
|
+
:description => 'Enable Telnet over SSL'
|
71
64
|
|
72
65
|
protected
|
73
66
|
|
@@ -80,7 +73,7 @@ module Ronin
|
|
80
73
|
# @param [Hash] options
|
81
74
|
# Additional options.
|
82
75
|
#
|
83
|
-
# @option options [Integer] :port (
|
76
|
+
# @option options [Integer] :port (Network::Telnet.default_port)
|
84
77
|
# The port to connect to.
|
85
78
|
#
|
86
79
|
# @option options [Boolean] :binmode
|
@@ -94,7 +87,7 @@ module Ronin
|
|
94
87
|
# Similar to the `:output_log` option, but connection output
|
95
88
|
# is also written in hexdump format.
|
96
89
|
#
|
97
|
-
# @option options [Regexp] :prompt (
|
90
|
+
# @option options [Regexp] :prompt (Network::Telnet.default_prompt)
|
98
91
|
# A regular expression matching the host command-line prompt
|
99
92
|
# sequence, used to determine when a command has finished.
|
100
93
|
#
|
@@ -106,7 +99,7 @@ module Ronin
|
|
106
99
|
# Indicates that the connection shall behave as a normal TCP
|
107
100
|
# connection.
|
108
101
|
#
|
109
|
-
# @option options [Integer] :timeout (
|
102
|
+
# @option options [Integer] :timeout (Network::Telnet.default_timeout)
|
110
103
|
# The number of seconds to wait before timing out both the
|
111
104
|
# initial attempt to connect to host, and all attempts to read
|
112
105
|
# data from the host.
|
@@ -115,7 +108,7 @@ module Ronin
|
|
115
108
|
# The amount of time to wait after seeing what looks like
|
116
109
|
# a prompt.
|
117
110
|
#
|
118
|
-
# @option options [Net::Telnet, IO] :proxy (
|
111
|
+
# @option options [Net::Telnet, IO] :proxy (Network::Telnet.proxy)
|
119
112
|
# A proxy object to used instead of opening a direct connection
|
120
113
|
# to the host.
|
121
114
|
#
|
@@ -142,20 +135,9 @@ module Ronin
|
|
142
135
|
# @api public
|
143
136
|
#
|
144
137
|
def telnet_connect(options={},&block)
|
145
|
-
|
146
|
-
options[:user] ||= self.telnet_user
|
147
|
-
options[:password] ||= self.telnet_password
|
148
|
-
|
149
|
-
options[:proxy] ||= self.telnet_proxy
|
150
|
-
options[:ssl] ||= self.telnet_ssl
|
138
|
+
print_info "Connecting to #{host_port} ..."
|
151
139
|
|
152
|
-
|
153
|
-
print_info "Connecting to #{self.host}:#{self.port} ..."
|
154
|
-
else
|
155
|
-
print_info "Connecting to #{self.host} ..."
|
156
|
-
end
|
157
|
-
|
158
|
-
return ::Net.telnet_connect(self.host,options,&block)
|
140
|
+
return super(self.host,telnet_merge_options(options),&block)
|
159
141
|
end
|
160
142
|
|
161
143
|
#
|
@@ -182,16 +164,41 @@ module Ronin
|
|
182
164
|
# @api public
|
183
165
|
#
|
184
166
|
def telnet_session(options={},&block)
|
185
|
-
|
167
|
+
super(telnet_merge_options(options)) do |sess|
|
186
168
|
yield sess if block_given?
|
187
|
-
sess.close
|
188
169
|
|
189
|
-
|
190
|
-
print_info "Disconnecting to #{self.host}:#{self.port}"
|
191
|
-
else
|
192
|
-
print_info "Disconnecting to #{self.host}"
|
193
|
-
end
|
170
|
+
print "Logging out ..."
|
194
171
|
end
|
172
|
+
|
173
|
+
print_info "Disconnected to #{host_port}"
|
174
|
+
return nil
|
175
|
+
end
|
176
|
+
|
177
|
+
private
|
178
|
+
|
179
|
+
#
|
180
|
+
# Merges the Telnet parameters into the options for {Network::Telnet}
|
181
|
+
# methods.
|
182
|
+
#
|
183
|
+
# @param [Hash] options
|
184
|
+
# The original options.
|
185
|
+
#
|
186
|
+
# @return [Hash]
|
187
|
+
# The merged options.
|
188
|
+
#
|
189
|
+
# @since 0.4.0
|
190
|
+
#
|
191
|
+
# @api private
|
192
|
+
#
|
193
|
+
def telnet_merge_options(options={})
|
194
|
+
options[:port] ||= self.port
|
195
|
+
options[:user] ||= self.telnet_user
|
196
|
+
options[:password] ||= self.telnet_password
|
197
|
+
|
198
|
+
options[:proxy] ||= self.telnet_proxy
|
199
|
+
options[:ssl] ||= self.telnet_ssl
|
200
|
+
|
201
|
+
return options
|
195
202
|
end
|
196
203
|
end
|
197
204
|
end
|
@@ -17,11 +17,8 @@
|
|
17
17
|
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#
|
19
19
|
|
20
|
+
require 'ronin/network/mixins/mixin'
|
20
21
|
require 'ronin/network/udp'
|
21
|
-
require 'ronin/ui/output/helpers'
|
22
|
-
require 'ronin/mixin'
|
23
|
-
|
24
|
-
require 'parameters'
|
25
22
|
|
26
23
|
module Ronin
|
27
24
|
module Network
|
@@ -39,35 +36,31 @@ module Ronin
|
|
39
36
|
# * `server_port` (`Integer`) - UDP server port.
|
40
37
|
#
|
41
38
|
module UDP
|
42
|
-
include Mixin
|
43
|
-
|
44
|
-
mixin UI::Output::Helpers, Parameters
|
39
|
+
include Mixin, Network::UDP
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
:description => 'UDP host'
|
41
|
+
# UDP host
|
42
|
+
parameter :host, :type => String,
|
43
|
+
:description => 'UDP host'
|
50
44
|
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
# UDP port
|
46
|
+
parameter :port, :type => Integer,
|
47
|
+
:description => 'UDP port'
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
# UDP local host
|
50
|
+
parameter :local_host, :type => String,
|
51
|
+
:description => 'UDP local host'
|
58
52
|
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
# UDP local port
|
54
|
+
parameter :local_port, :type => Integer,
|
55
|
+
:description => 'UDP local port'
|
62
56
|
|
63
|
-
|
64
|
-
|
65
|
-
|
57
|
+
# UDP server host
|
58
|
+
parameter :server_host, :type => String,
|
59
|
+
:description => 'UDP server host'
|
66
60
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
61
|
+
# UDP server port
|
62
|
+
parameter :server_port, :type => Integer,
|
63
|
+
:description => 'UDP server port'
|
71
64
|
|
72
65
|
protected
|
73
66
|
|
@@ -98,9 +91,9 @@ module Ronin
|
|
98
91
|
# @api public
|
99
92
|
#
|
100
93
|
def udp_connect(&block)
|
101
|
-
print_info "Connecting to #{
|
94
|
+
print_info "Connecting to #{host_port} ..."
|
102
95
|
|
103
|
-
return
|
96
|
+
return super(self.host,self.port,self.local_host,self.local_port,&block)
|
104
97
|
end
|
105
98
|
|
106
99
|
#
|
@@ -124,10 +117,10 @@ module Ronin
|
|
124
117
|
# @api public
|
125
118
|
#
|
126
119
|
def udp_connect_and_send(data,&block)
|
127
|
-
print_info "Connecting to #{
|
120
|
+
print_info "Connecting to #{host_port} ..."
|
128
121
|
print_debug "Sending data: #{data.inspect}"
|
129
122
|
|
130
|
-
return
|
123
|
+
return super(data,self.host,self.port,self.local_host,self.local_port,&block)
|
131
124
|
end
|
132
125
|
|
133
126
|
#
|
@@ -148,11 +141,11 @@ module Ronin
|
|
148
141
|
# @api public
|
149
142
|
#
|
150
143
|
def udp_session(&block)
|
151
|
-
print_info "Connecting to #{
|
144
|
+
print_info "Connecting to #{host_port} ..."
|
152
145
|
|
153
|
-
|
146
|
+
super(self.host,self.port,self.local_host,self.local_port,&block)
|
154
147
|
|
155
|
-
print_info "Disconnected from #{
|
148
|
+
print_info "Disconnected from #{host_port}"
|
156
149
|
return nil
|
157
150
|
end
|
158
151
|
|
@@ -175,13 +168,9 @@ module Ronin
|
|
175
168
|
# @api public
|
176
169
|
#
|
177
170
|
def udp_server(&block)
|
178
|
-
|
179
|
-
print_info "Listening on #{self.server_host}:#{self.server_port} ..."
|
180
|
-
else
|
181
|
-
print_info "Listening on #{self.server_port} ..."
|
182
|
-
end
|
171
|
+
print_info "Listening on #{server_host_port} ..."
|
183
172
|
|
184
|
-
return
|
173
|
+
return super(self.server_port,self.server_host,&block)
|
185
174
|
end
|
186
175
|
|
187
176
|
#
|
@@ -205,22 +194,29 @@ module Ronin
|
|
205
194
|
# @api public
|
206
195
|
#
|
207
196
|
def udp_server_session(&block)
|
208
|
-
|
209
|
-
print_info "Listening on #{self.server_host}:#{self.server_port} ..."
|
210
|
-
else
|
211
|
-
print_info "Listening on #{self.server_port} ..."
|
212
|
-
end
|
197
|
+
print_info "Listening on #{self.server_host_port} ..."
|
213
198
|
|
214
|
-
|
215
|
-
|
216
|
-
if self.server_host
|
217
|
-
print_info "Closed #{self.server_host}:#{self.server_port}"
|
218
|
-
else
|
219
|
-
print_info "Closed #{self.server_port}"
|
220
|
-
end
|
199
|
+
super(self.server_port,self.server_host,&block)
|
221
200
|
|
201
|
+
print_info "Closed #{self.server_host_port}"
|
222
202
|
return nil
|
223
203
|
end
|
204
|
+
|
205
|
+
private
|
206
|
+
|
207
|
+
#
|
208
|
+
# The server host/port parameters.
|
209
|
+
#
|
210
|
+
# @return [String]
|
211
|
+
# The server host/port parameters in String form.
|
212
|
+
#
|
213
|
+
# @since 0.4.0
|
214
|
+
#
|
215
|
+
# @api private
|
216
|
+
#
|
217
|
+
def server_host_port
|
218
|
+
"#{self.server_host}:#{self.server_port}"
|
219
|
+
end
|
224
220
|
end
|
225
221
|
end
|
226
222
|
end
|
data/lib/ronin/network/pop3.rb
CHANGED
@@ -17,12 +17,12 @@
|
|
17
17
|
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#
|
19
19
|
|
20
|
-
require '
|
20
|
+
require 'net/pop'
|
21
21
|
|
22
22
|
module Ronin
|
23
23
|
module Network
|
24
24
|
#
|
25
|
-
#
|
25
|
+
# Provides helper methods for communicating with POP3 services.
|
26
26
|
#
|
27
27
|
module POP3
|
28
28
|
# Default POP3 port
|
@@ -49,6 +49,76 @@ module Ronin
|
|
49
49
|
def POP3.default_port=(port)
|
50
50
|
@default_port = port
|
51
51
|
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Creates a connection to the POP3 server.
|
55
|
+
#
|
56
|
+
# @param [String] host
|
57
|
+
# The host to connect to.
|
58
|
+
#
|
59
|
+
# @param [Hash] options
|
60
|
+
# Additional options.
|
61
|
+
#
|
62
|
+
# @option options [Integer] :port (POP3.default_port)
|
63
|
+
# The port the POP3 server is running on.
|
64
|
+
#
|
65
|
+
# @option options [String] :user
|
66
|
+
# The user to authenticate with when connecting to the POP3 server.
|
67
|
+
#
|
68
|
+
# @option options [String] :password
|
69
|
+
# The password to authenticate with when connecting to the POP3 server.
|
70
|
+
#
|
71
|
+
# @yield [session]
|
72
|
+
# If a block is given, it will be passed the newly created POP3 session.
|
73
|
+
#
|
74
|
+
# @yieldparam [Net::POP3] session
|
75
|
+
# The newly created POP3 session.
|
76
|
+
#
|
77
|
+
# @return [Net::POP3]
|
78
|
+
# The newly created POP3 session.
|
79
|
+
#
|
80
|
+
# @api public
|
81
|
+
#
|
82
|
+
def pop3_connect(host,options={})
|
83
|
+
host = host.to_s
|
84
|
+
port = (options[:port] || POP3.default_port)
|
85
|
+
user = options[:user]
|
86
|
+
password = options[:password]
|
87
|
+
|
88
|
+
session = Net::POP3.start(host,port,user,password)
|
89
|
+
|
90
|
+
yield session if block_given?
|
91
|
+
return session
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Starts a session with the POP3 server.
|
96
|
+
#
|
97
|
+
# @param [String] host
|
98
|
+
# The host to connect to.
|
99
|
+
#
|
100
|
+
# @param [Hash] options
|
101
|
+
# Additional options.
|
102
|
+
#
|
103
|
+
# @yield [session]
|
104
|
+
# If a block is given, it will be passed the newly created POP3 session.
|
105
|
+
# After the block has returned, the session will be closed.
|
106
|
+
#
|
107
|
+
# @yieldparam [Net::POP3] session
|
108
|
+
# The newly created POP3 session.
|
109
|
+
#
|
110
|
+
# @return [nil]
|
111
|
+
#
|
112
|
+
# @api public
|
113
|
+
#
|
114
|
+
def pop3_session(host,options={})
|
115
|
+
session = pop3_connect(host,options)
|
116
|
+
|
117
|
+
yield session if block_given?
|
118
|
+
|
119
|
+
session.finish
|
120
|
+
return nil
|
121
|
+
end
|
52
122
|
end
|
53
123
|
end
|
54
124
|
end
|
@@ -19,10 +19,12 @@
|
|
19
19
|
|
20
20
|
require 'ronin/network/smtp/email'
|
21
21
|
|
22
|
+
require 'net/smtp'
|
23
|
+
|
22
24
|
module Ronin
|
23
25
|
module Network
|
24
26
|
#
|
25
|
-
#
|
27
|
+
# Provides helper methods for communicating with SMTP services.
|
26
28
|
#
|
27
29
|
module SMTP
|
28
30
|
# Default SMTP port
|
@@ -57,19 +59,173 @@ module Ronin
|
|
57
59
|
# If a block is given, it will be passed the newly created Email
|
58
60
|
# object.
|
59
61
|
#
|
60
|
-
# @yieldparam [
|
62
|
+
# @yieldparam [Email] email
|
61
63
|
# The new Email object.
|
62
64
|
#
|
63
65
|
# @return [String]
|
64
66
|
# Formatted SMTP email.
|
65
67
|
#
|
66
|
-
# @see
|
68
|
+
# @see SMTP::Email
|
67
69
|
#
|
68
70
|
# @api public
|
69
71
|
#
|
70
72
|
def SMTP.message(options={},&block)
|
71
73
|
Email.new(options,&block).to_s
|
72
74
|
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Creates a new email message.
|
78
|
+
#
|
79
|
+
# @param [Hash] options
|
80
|
+
# Additional options for the email.
|
81
|
+
#
|
82
|
+
# @yield [email]
|
83
|
+
# The given block will be passed the new email.
|
84
|
+
#
|
85
|
+
# @yieldparam [Email] email
|
86
|
+
# The new email.
|
87
|
+
#
|
88
|
+
# @see Email.new
|
89
|
+
#
|
90
|
+
# @api public
|
91
|
+
#
|
92
|
+
def smtp_message(options={},&block)
|
93
|
+
Email.new(options,&block)
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# Creates a connection to the SMTP server.
|
98
|
+
#
|
99
|
+
# @param [String] host
|
100
|
+
# The host to connect to.
|
101
|
+
#
|
102
|
+
# @param [Hash] options
|
103
|
+
# Additional options.
|
104
|
+
#
|
105
|
+
# @option options [Integer] :port (SMTP.default_port)
|
106
|
+
# The port to connect to.
|
107
|
+
#
|
108
|
+
# @option options [String] :helo
|
109
|
+
# The HELO domain.
|
110
|
+
#
|
111
|
+
# @option options [Symbol] :auth
|
112
|
+
# The type of authentication to use. Can be either `:login`, `:plain`,
|
113
|
+
# or `:cram_md5`.
|
114
|
+
#
|
115
|
+
# @option options [String] :user
|
116
|
+
# The user-name to authenticate with.
|
117
|
+
#
|
118
|
+
# @option options [String] :password
|
119
|
+
# The password to authenticate with.
|
120
|
+
#
|
121
|
+
# @yield [session]
|
122
|
+
# If a block is given, it will be passed an SMTP session object.
|
123
|
+
#
|
124
|
+
# @yieldparam [Net::SMTP] session
|
125
|
+
# The SMTP session.
|
126
|
+
#
|
127
|
+
# @return [Net::SMTP]
|
128
|
+
# The SMTP session.
|
129
|
+
#
|
130
|
+
# @example
|
131
|
+
# smtp_connect('www.example.com', :user => 'joe')
|
132
|
+
#
|
133
|
+
# @api public
|
134
|
+
#
|
135
|
+
def smtp_connect(host,options={})
|
136
|
+
host = host.to_s
|
137
|
+
port = (options[:port] || SMTP.default_port)
|
138
|
+
|
139
|
+
helo = options[:helo]
|
140
|
+
|
141
|
+
auth = options[:auth]
|
142
|
+
user = options[:user]
|
143
|
+
password = options[:password]
|
144
|
+
|
145
|
+
session = Net::SMTP.start(host,port,helo,user,password,auth)
|
146
|
+
|
147
|
+
yield session if block_given?
|
148
|
+
return session
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Starts a session with the SMTP server.
|
153
|
+
#
|
154
|
+
# @param [String] host
|
155
|
+
# The host to connect to.
|
156
|
+
#
|
157
|
+
# @param [Hash] options
|
158
|
+
# Additional options.
|
159
|
+
#
|
160
|
+
# @yield [session]
|
161
|
+
# If a block is given, it will be passed an SMTP session object.
|
162
|
+
# After the block has returned, the session will be closed.
|
163
|
+
#
|
164
|
+
# @yieldparam [Net::SMTP] session
|
165
|
+
# The SMTP session.
|
166
|
+
#
|
167
|
+
# @example
|
168
|
+
# smtp_session('www.example.com', :user => 'joe') do |smtp|
|
169
|
+
# # ...
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# @see smtp_connect
|
173
|
+
#
|
174
|
+
# @api public
|
175
|
+
#
|
176
|
+
def smtp_session(host,options={})
|
177
|
+
session = smtp_connect(host,options)
|
178
|
+
|
179
|
+
yield session if block_given?
|
180
|
+
|
181
|
+
session.finish
|
182
|
+
return nil
|
183
|
+
end
|
184
|
+
|
185
|
+
#
|
186
|
+
# @since 0.2.0
|
187
|
+
#
|
188
|
+
# @param [String] host
|
189
|
+
# The host to connect to.
|
190
|
+
#
|
191
|
+
# @param [Hash] options
|
192
|
+
# Additional SMTP and Email options.
|
193
|
+
#
|
194
|
+
# @yield [email]
|
195
|
+
# The given block will be passed the new email to be sent.
|
196
|
+
#
|
197
|
+
# @yieldparam [SMTP::Email] email
|
198
|
+
# The new email to be sent.
|
199
|
+
#
|
200
|
+
# @see smtp_session
|
201
|
+
#
|
202
|
+
# @example
|
203
|
+
# smtp_send_message 'www.example.com', :to => 'joe@example.com',
|
204
|
+
# :from => 'eve@example.com',
|
205
|
+
# :subject => 'Hello',
|
206
|
+
# :message_id => 'XXXX',
|
207
|
+
# :body => 'Hello'
|
208
|
+
#
|
209
|
+
# @example Using the block.
|
210
|
+
# smtp_send_message('www.example.com') do |email|
|
211
|
+
# email.to = 'joe@example.com'
|
212
|
+
# email.from 'eve@example.com'
|
213
|
+
# email.subject = 'Hello'
|
214
|
+
# email.message_id = 'XXXXXXXXXX'
|
215
|
+
# email.body << 'Hello!'
|
216
|
+
# end
|
217
|
+
#
|
218
|
+
# @since 0.2.0
|
219
|
+
#
|
220
|
+
# @api public
|
221
|
+
#
|
222
|
+
def smtp_send_message(host,options={},&block)
|
223
|
+
email = smtp_message(options,&block)
|
224
|
+
|
225
|
+
smtp_session(host,options) do |smtp|
|
226
|
+
smtp.send_message(email.to_s, email.from, email.to)
|
227
|
+
end
|
228
|
+
end
|
73
229
|
end
|
74
230
|
end
|
75
231
|
end
|