mail 2.0.5 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mail might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +12 -0
- data/Rakefile +1 -1
- data/lib/mail/configuration.rb +6 -3
- data/lib/mail/fields/common/common_address.rb +1 -1
- data/lib/mail/fields/common/common_field.rb +5 -1
- data/lib/mail/mail.rb +0 -19
- data/lib/mail/message.rb +101 -12
- data/lib/mail/network/delivery_methods/test_mailer.rb +21 -0
- data/lib/mail/version.rb +2 -2
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== Mon Jan 25 10:36:33 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
2
|
+
|
3
|
+
* Now passes a block to the delivery handler, which can just call yield if it want's Mail to just do it's normal delivery method
|
4
|
+
* Moved Mail.deliveries into Mail::TestMailer.deliveries. Now only gets mail appended to it if you are sending with the :test delivery_method (only for testing)
|
5
|
+
* Version bump to 2.1.0
|
6
|
+
|
7
|
+
== Mon Jan 25 01:44:13 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
8
|
+
|
9
|
+
* Change :deliver! to deliver a mail object, bypassing the :perform_deliveries and :raise_delivery_errors flags, also does not append the mail object to Mail.deliveries, thus the ! (dangerous). The intended use for :deliver! is for people wanting to have their own delivery_handler (like ActionMailer uses) to track and handle delivery failures.
|
10
|
+
* Added :delivery_handler to Message. Allows you to pass an object that will be sent :deliver_mail(self) by the Mail::Message instance when it is sent :deliver and bypasses the usual delivery method.
|
11
|
+
* Changed :perform_deliveries flag to be more consistent with it's name, mail will not append itself to the Mail.deliveries collection if :perform_deliveries is false
|
12
|
+
|
1
13
|
== Sat Jan 23 23:49:50 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
2
14
|
|
3
15
|
* Version bump to 2.0.5
|
data/Rakefile
CHANGED
data/lib/mail/configuration.rb
CHANGED
@@ -13,9 +13,12 @@ module Mail
|
|
13
13
|
# which can be overwritten on a per mail object basis.
|
14
14
|
class Configuration
|
15
15
|
include Singleton
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@delivery_method = nil
|
19
|
+
@retriever_method = nil
|
20
|
+
super
|
21
|
+
end
|
19
22
|
|
20
23
|
def delivery_method(method = nil, settings = {})
|
21
24
|
return @delivery_method if @delivery_method && method.nil?
|
data/lib/mail/mail.rb
CHANGED
@@ -169,25 +169,6 @@ module Mail
|
|
169
169
|
def Mail.read(filename)
|
170
170
|
Mail.new(File.read(filename))
|
171
171
|
end
|
172
|
-
|
173
|
-
# Provides a store of all the emails sent
|
174
|
-
def Mail.deliveries
|
175
|
-
@@deliveries ||= []
|
176
|
-
end
|
177
|
-
|
178
|
-
# Allows you to over write the default deliveries store from an array to some
|
179
|
-
# other object. If you just want to clear the store, call Mail.deliveries.clear.
|
180
|
-
#
|
181
|
-
# If you place another object here, please make sure it responds to:
|
182
|
-
#
|
183
|
-
# * << (message)
|
184
|
-
# * clear
|
185
|
-
# * length
|
186
|
-
# * size
|
187
|
-
# * and other common Array methods
|
188
|
-
def Mail.deliveries=(val)
|
189
|
-
@@deliveries = val
|
190
|
-
end
|
191
172
|
|
192
173
|
protected
|
193
174
|
|
data/lib/mail/message.rb
CHANGED
@@ -102,9 +102,12 @@ module Mail
|
|
102
102
|
|
103
103
|
@perform_deliveries = true
|
104
104
|
@raise_delivery_errors = true
|
105
|
+
|
106
|
+
@delivery_handler = nil
|
107
|
+
|
105
108
|
@delivery_method = Mail.delivery_method.dup
|
106
109
|
@delivery_notification_observers = []
|
107
|
-
|
110
|
+
|
108
111
|
if args.flatten.first.respond_to?(:each_pair)
|
109
112
|
init_with_hash(args.flatten.first)
|
110
113
|
else
|
@@ -118,7 +121,76 @@ module Mail
|
|
118
121
|
self
|
119
122
|
end
|
120
123
|
|
124
|
+
# If you assign a delivery handler, mail will call :deliver_mail on the
|
125
|
+
# object you assign to delivery_handler, it will pass itself as the
|
126
|
+
# single argument.
|
127
|
+
#
|
128
|
+
# If you define a delivery_handler, then you are responsible for the
|
129
|
+
# following actions in the delivery cycle:
|
130
|
+
#
|
131
|
+
# * Appending the mail object to Mail.deliveries as you see fit.
|
132
|
+
# * Checking the mail.perform_deliveries flag to decide if you should
|
133
|
+
# actually call :deliver! the mail object or not.
|
134
|
+
# * Checking the mail.raise_delivery_errors flag to decide if you
|
135
|
+
# should raise delivery errors if they occur.
|
136
|
+
# * Actually calling :deliver! (with the bang) on the mail object to
|
137
|
+
# get it to deliver itself.
|
138
|
+
#
|
139
|
+
# A simplest implementation of a delivery_handler would be
|
140
|
+
#
|
141
|
+
# class MyObject
|
142
|
+
#
|
143
|
+
# def initialize
|
144
|
+
# @mail = Mail.new('To: mikel@test.lindsaar.net')
|
145
|
+
# @mail.delivery_handler = self
|
146
|
+
# end
|
147
|
+
#
|
148
|
+
# attr_accessor :mail
|
149
|
+
#
|
150
|
+
# def deliver_mail(mail)
|
151
|
+
# yield
|
152
|
+
# end
|
153
|
+
# end
|
154
|
+
#
|
155
|
+
# Then doing:
|
156
|
+
#
|
157
|
+
# obj = MyObject.new
|
158
|
+
# obj.mail.deliver
|
159
|
+
#
|
160
|
+
# Would cause Mail to call obj.deliver_mail passing itself as a parameter,
|
161
|
+
# which then can just yield and let Mail do it's own private do_delivery
|
162
|
+
# method.
|
163
|
+
attr_accessor :delivery_handler
|
164
|
+
|
165
|
+
# If set to false, mail will go through the motions of doing a delivery,
|
166
|
+
# but not actually call the delivery method or append the mail object to
|
167
|
+
# the Mail.deliveries collection. Useful for testing.
|
168
|
+
#
|
169
|
+
# Mail.deliveries.size #=> 0
|
170
|
+
# mail.delivery_method :smtp
|
171
|
+
# mail.perform_deliveries = false
|
172
|
+
# mail.deliver # Mail::SMTP not called here
|
173
|
+
# Mail.deliveries.size #=> 0
|
174
|
+
#
|
175
|
+
# If you want to test and query the Mail.deliveries collection to see what
|
176
|
+
# mail you sent, you should set perform_deliveries to true and use
|
177
|
+
# the :test mail delivery_method:
|
178
|
+
#
|
179
|
+
# Mail.deliveries.size #=> 0
|
180
|
+
# mail.delivery_method :test
|
181
|
+
# mail.perform_deliveries = true
|
182
|
+
# mail.deliver
|
183
|
+
# Mail.deliveries.size #=> 1
|
184
|
+
#
|
185
|
+
# This setting is ignored by mail (though still available as a flag) if you
|
186
|
+
# define a delivery_handler
|
121
187
|
attr_accessor :perform_deliveries
|
188
|
+
|
189
|
+
# If set to false, mail will silently catch and ignore any exceptions
|
190
|
+
# raised through attempting to deliver an email.
|
191
|
+
#
|
192
|
+
# This setting is ignored by mail (though still available as a flag) if you
|
193
|
+
# define a delivery_handler
|
122
194
|
attr_accessor :raise_delivery_errors
|
123
195
|
|
124
196
|
def register_for_delivery_notification(observer)
|
@@ -138,22 +210,29 @@ module Mail
|
|
138
210
|
# Examples:
|
139
211
|
#
|
140
212
|
# mail = Mail.read('file.eml')
|
141
|
-
# mail.deliver
|
213
|
+
# mail.deliver
|
142
214
|
def deliver
|
143
|
-
if
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
raise e if raise_delivery_errors
|
149
|
-
end
|
215
|
+
if delivery_handler
|
216
|
+
delivery_handler.deliver_mail(self) { do_delivery }
|
217
|
+
else
|
218
|
+
do_delivery
|
219
|
+
inform_observers
|
150
220
|
end
|
221
|
+
self
|
222
|
+
end
|
223
|
+
|
224
|
+
# This method bypasses checking perform_deliveries and raise_delivery_errors,
|
225
|
+
# so use with caution.
|
226
|
+
#
|
227
|
+
# It still however fires callbacks to the observers if they are defined.
|
228
|
+
#
|
229
|
+
# Returns self
|
230
|
+
def deliver!
|
231
|
+
delivery_method.deliver!(self)
|
151
232
|
inform_observers
|
152
233
|
self
|
153
234
|
end
|
154
235
|
|
155
|
-
alias :deliver! :deliver
|
156
|
-
|
157
236
|
def delivery_method(method = nil, settings = {})
|
158
237
|
unless method
|
159
238
|
@delivery_method
|
@@ -1571,7 +1650,7 @@ module Mail
|
|
1571
1650
|
find_attachment
|
1572
1651
|
end
|
1573
1652
|
|
1574
|
-
|
1653
|
+
private
|
1575
1654
|
|
1576
1655
|
# 2.1. General Description
|
1577
1656
|
# A message consists of header fields (collectively called "the header
|
@@ -1679,5 +1758,15 @@ module Mail
|
|
1679
1758
|
filename
|
1680
1759
|
end
|
1681
1760
|
|
1761
|
+
def do_delivery
|
1762
|
+
begin
|
1763
|
+
if perform_deliveries
|
1764
|
+
delivery_method.deliver!(self)
|
1765
|
+
end
|
1766
|
+
rescue Exception => e # Net::SMTP errors or sendmail pipe errors
|
1767
|
+
raise e if raise_delivery_errors
|
1768
|
+
end
|
1769
|
+
end
|
1770
|
+
|
1682
1771
|
end
|
1683
1772
|
end
|
@@ -6,6 +6,26 @@ module Mail
|
|
6
6
|
# if you want to make a custom mailer for Mail
|
7
7
|
class TestMailer
|
8
8
|
|
9
|
+
# Provides a store of all the emails sent with the TestMailer so you can check them.
|
10
|
+
def TestMailer.deliveries
|
11
|
+
@@deliveries ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
# Allows you to over write the default deliveries store from an array to some
|
15
|
+
# other object. If you just want to clear the store,
|
16
|
+
# call TestMailer.deliveries.clear.
|
17
|
+
#
|
18
|
+
# If you place another object here, please make sure it responds to:
|
19
|
+
#
|
20
|
+
# * << (message)
|
21
|
+
# * clear
|
22
|
+
# * length
|
23
|
+
# * size
|
24
|
+
# * and other common Array methods
|
25
|
+
def TestMailer.deliveries=(val)
|
26
|
+
@@deliveries = val
|
27
|
+
end
|
28
|
+
|
9
29
|
def initialize(values)
|
10
30
|
@settings = {}
|
11
31
|
end
|
@@ -13,6 +33,7 @@ module Mail
|
|
13
33
|
attr_accessor :settings
|
14
34
|
|
15
35
|
def deliver!(mail)
|
36
|
+
Mail::TestMailer.deliveries << mail
|
16
37
|
end
|
17
38
|
|
18
39
|
end
|
data/lib/mail/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Lindsaar
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-25 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|