actionmailer 4.1.0.beta2 → 4.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -1
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/action_mailer.rb +1 -1
- data/lib/action_mailer/base.rb +56 -25
- data/lib/action_mailer/preview.rb +41 -4
- data/lib/action_mailer/railtie.rb +7 -5
- data/lib/action_mailer/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a14d6592f23edce89a35a8e248fe9c9aab6ec9db
|
4
|
+
data.tar.gz: 9b164dc18c93ab42fe0202d5ba9be3832ce417cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ae74e8854276fced21a93d2994ae4841afe49777b96ca49f7b341ed1241ccaae293546c09a00c877ef9afe8f2f07a68f60832729d5ab6eba073b420897c589a
|
7
|
+
data.tar.gz: ca8bf17a413211b4696fdbf3dc91e9f1310da3dc35fe5c322d6265468fd281a2c01b67920651e7a4f40ae678065d258adc876afac204e2b29ab5c691b03e6024
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,34 @@
|
|
1
|
-
*
|
1
|
+
* Support the use of underscored symbols when registering interceptors and
|
2
|
+
observers like we do elsewhere within Rails.
|
3
|
+
|
4
|
+
*Andrew White*
|
5
|
+
|
6
|
+
* Add the ability to intercept emails before previewing in a similar fashion
|
7
|
+
to how emails can be intercepted before delivery.
|
8
|
+
|
9
|
+
Fixes #13622.
|
10
|
+
|
11
|
+
Example:
|
12
|
+
|
13
|
+
class CSSInlineStyler
|
14
|
+
def self.previewing_email(message)
|
15
|
+
# inline CSS styles
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ActionMailer::Base.register_preview_interceptor CSSInlineStyler
|
20
|
+
|
21
|
+
*Andrew White*
|
22
|
+
|
23
|
+
* Add mailer previews feature based on 37 Signals mail_view gem.
|
2
24
|
|
3
25
|
*Andrew White*
|
4
26
|
|
5
27
|
* Calling `mail()` without arguments serves as getter for the current mail
|
6
28
|
message and keeps previously set headers.
|
7
29
|
|
30
|
+
Fixes #13090.
|
31
|
+
|
8
32
|
Example:
|
9
33
|
|
10
34
|
class MailerWithCallback < ActionMailer::Base
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -74,7 +74,7 @@ Or you can just chain the methods together like:
|
|
74
74
|
|
75
75
|
== Setting defaults
|
76
76
|
|
77
|
-
It is possible to set default values that will be used in every method in your Action Mailer class. To implement this functionality, you just call the public class method <tt>default</tt> which you get for free from <tt>ActionMailer::Base</tt>. This method accepts a Hash as the parameter. You can use any of the headers
|
77
|
+
It is possible to set default values that will be used in every method in your Action Mailer class. To implement this functionality, you just call the public class method <tt>default</tt> which you get for free from <tt>ActionMailer::Base</tt>. This method accepts a Hash as the parameter. You can use any of the headers email messages have, like <tt>:from</tt> as the key. You can also pass in a string as the key, like "Content-Type", but Action Mailer does this out of the box for you, so you won't need to worry about that. Finally, it is also possible to pass in a Proc that will get evaluated when it is needed.
|
78
78
|
|
79
79
|
Note that every value you set with this method will get overwritten if you use the same key in your mailer method.
|
80
80
|
|
data/lib/action_mailer.rb
CHANGED
data/lib/action_mailer/base.rb
CHANGED
@@ -50,8 +50,8 @@ module ActionMailer
|
|
50
50
|
#
|
51
51
|
# * <tt>mail</tt> - Allows you to specify email to be sent.
|
52
52
|
#
|
53
|
-
# The hash passed to the mail method allows you to specify any header that a Mail::Message
|
54
|
-
# will accept (any valid
|
53
|
+
# The hash passed to the mail method allows you to specify any header that a <tt>Mail::Message</tt>
|
54
|
+
# will accept (any valid email header including optional fields).
|
55
55
|
#
|
56
56
|
# The mail method, if not passed a block, will inspect your views and send all the views with
|
57
57
|
# the same name as the method, so the above action would send the +welcome.text.erb+ view
|
@@ -229,7 +229,7 @@ module ActionMailer
|
|
229
229
|
# An interceptor class must implement the <tt>:delivering_email(message)</tt> method which will be
|
230
230
|
# called before the email is sent, allowing you to make modifications to the email before it hits
|
231
231
|
# the delivery agents. Your class should make any needed modifications directly to the passed
|
232
|
-
# in Mail::Message instance.
|
232
|
+
# in <tt>Mail::Message</tt> instance.
|
233
233
|
#
|
234
234
|
# = Default Hash
|
235
235
|
#
|
@@ -320,13 +320,31 @@ module ActionMailer
|
|
320
320
|
# end
|
321
321
|
# end
|
322
322
|
#
|
323
|
-
# Methods must return a Mail::Message object which can be generated by calling the mailer
|
323
|
+
# Methods must return a <tt>Mail::Message</tt> object which can be generated by calling the mailer
|
324
324
|
# method without the additional <tt>deliver</tt>. The location of the mailer previews
|
325
325
|
# directory can be configured using the <tt>preview_path</tt> option which has a default
|
326
326
|
# of <tt>test/mailers/previews</tt>:
|
327
327
|
#
|
328
328
|
# config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
|
329
329
|
#
|
330
|
+
# An overview of all previews is accessible at <tt>http://localhost:3000/rails/mailers</tt>
|
331
|
+
# on a running development server instance.
|
332
|
+
#
|
333
|
+
# Previews can also be intercepted in a similar manner as deliveries can be by registering
|
334
|
+
# a preview interceptor that has a <tt>previewing_email</tt> method:
|
335
|
+
#
|
336
|
+
# class CssInlineStyler
|
337
|
+
# def self.previewing_email(message)
|
338
|
+
# # inline CSS styles
|
339
|
+
# end
|
340
|
+
# end
|
341
|
+
#
|
342
|
+
# config.action_mailer.register_preview_interceptor :css_inline_styler
|
343
|
+
#
|
344
|
+
# Note that interceptors need to be registered both with <tt>register_interceptor</tt>
|
345
|
+
# and <tt>register_preview_interceptor</tt> if they should operate on both sending and
|
346
|
+
# previewing emails.
|
347
|
+
#
|
330
348
|
# = Configuration options
|
331
349
|
#
|
332
350
|
# These options are specified on the class level, like
|
@@ -336,7 +354,7 @@ module ActionMailer
|
|
336
354
|
# per the above section.
|
337
355
|
#
|
338
356
|
# * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
|
339
|
-
# Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
|
357
|
+
# Can be set to +nil+ for no logging. Compatible with both Ruby's own +Logger+ and Log4r loggers.
|
340
358
|
#
|
341
359
|
# * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
|
342
360
|
# * <tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default
|
@@ -354,8 +372,9 @@ module ActionMailer
|
|
354
372
|
# and starts to use it.
|
355
373
|
# * <tt>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is
|
356
374
|
# really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name
|
357
|
-
# of an OpenSSL verify constant ('none'
|
358
|
-
# constant
|
375
|
+
# of an OpenSSL verify constant (<tt>'none'</tt>, <tt>'peer'</tt>, <tt>'client_once'</tt>,
|
376
|
+
# <tt>'fail_if_no_peer_cert'</tt>) or directly the constant (<tt>OpenSSL::SSL::VERIFY_NONE</tt>,
|
377
|
+
# <tt>OpenSSL::SSL::VERIFY_PEER</tt>, ...).
|
359
378
|
#
|
360
379
|
# * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
|
361
380
|
# * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
|
@@ -370,7 +389,7 @@ module ActionMailer
|
|
370
389
|
#
|
371
390
|
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default),
|
372
391
|
# <tt>:sendmail</tt>, <tt>:test</tt>, and <tt>:file</tt>. Or you may provide a custom delivery method
|
373
|
-
# object e.g. MyOwnDeliveryMethodClass
|
392
|
+
# object e.g. +MyOwnDeliveryMethodClass+. See the Mail gem documentation on the interface you need to
|
374
393
|
# implement for a custom delivery agent.
|
375
394
|
#
|
376
395
|
# * <tt>perform_deliveries</tt> - Determines whether emails are actually sent from Action Mailer when you
|
@@ -425,18 +444,30 @@ module ActionMailer
|
|
425
444
|
end
|
426
445
|
|
427
446
|
# Register an Observer which will be notified when mail is delivered.
|
428
|
-
# Either a class or
|
429
|
-
# it will be
|
447
|
+
# Either a class, string or symbol can be passed in as the Observer.
|
448
|
+
# If a string or symbol is passed in it will be camelized and constantized.
|
430
449
|
def register_observer(observer)
|
431
|
-
delivery_observer =
|
450
|
+
delivery_observer = case observer
|
451
|
+
when String, Symbol
|
452
|
+
observer.to_s.camelize.constantize
|
453
|
+
else
|
454
|
+
observer
|
455
|
+
end
|
456
|
+
|
432
457
|
Mail.register_observer(delivery_observer)
|
433
458
|
end
|
434
459
|
|
435
460
|
# Register an Interceptor which will be called before mail is sent.
|
436
|
-
# Either a class or
|
437
|
-
# it will be
|
461
|
+
# Either a class, string or symbol can be passed in as the Interceptor.
|
462
|
+
# If a string or symbol is passed in it will be camelized and constantized.
|
438
463
|
def register_interceptor(interceptor)
|
439
|
-
delivery_interceptor =
|
464
|
+
delivery_interceptor = case interceptor
|
465
|
+
when String, Symbol
|
466
|
+
interceptor.to_s.camelize.constantize
|
467
|
+
else
|
468
|
+
interceptor
|
469
|
+
end
|
470
|
+
|
440
471
|
Mail.register_interceptor(delivery_interceptor)
|
441
472
|
end
|
442
473
|
|
@@ -484,11 +515,11 @@ module ActionMailer
|
|
484
515
|
end
|
485
516
|
end
|
486
517
|
|
487
|
-
# Wraps an email delivery inside of ActiveSupport::Notifications instrumentation.
|
518
|
+
# Wraps an email delivery inside of <tt>ActiveSupport::Notifications</tt> instrumentation.
|
488
519
|
#
|
489
|
-
# This method is actually called by the Mail::Message object itself
|
490
|
-
# through a callback when you call
|
491
|
-
# calling +deliver_mail+ directly and passing a Mail::Message will do
|
520
|
+
# This method is actually called by the <tt>Mail::Message</tt> object itself
|
521
|
+
# through a callback when you call <tt>:deliver</tt> on the <tt>Mail::Message</tt>,
|
522
|
+
# calling +deliver_mail+ directly and passing a <tt>Mail::Message</tt> will do
|
492
523
|
# nothing except tell the logger you sent the email.
|
493
524
|
def deliver_mail(mail) #:nodoc:
|
494
525
|
ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
|
@@ -564,18 +595,18 @@ module ActionMailer
|
|
564
595
|
self.class.mailer_name
|
565
596
|
end
|
566
597
|
|
567
|
-
# Allows you to pass random and unusual headers to the new Mail::Message
|
598
|
+
# Allows you to pass random and unusual headers to the new <tt>Mail::Message</tt>
|
568
599
|
# object which will add them to itself.
|
569
600
|
#
|
570
601
|
# headers['X-Special-Domain-Specific-Header'] = "SecretValue"
|
571
602
|
#
|
572
603
|
# You can also pass a hash into headers of header field names and values,
|
573
|
-
# which will then be set on the Mail::Message object:
|
604
|
+
# which will then be set on the <tt>Mail::Message</tt> object:
|
574
605
|
#
|
575
606
|
# headers 'X-Special-Domain-Specific-Header' => "SecretValue",
|
576
607
|
# 'In-Reply-To' => incoming.message_id
|
577
608
|
#
|
578
|
-
# The resulting Mail::Message will have the following in its header:
|
609
|
+
# The resulting <tt>Mail::Message</tt> will have the following in its header:
|
579
610
|
#
|
580
611
|
# X-Special-Domain-Specific-Header: SecretValue
|
581
612
|
def headers(args = nil)
|
@@ -664,13 +695,13 @@ module ActionMailer
|
|
664
695
|
# templates in the view paths using by default the mailer name and the
|
665
696
|
# method name that it is being called from, it will then create parts for
|
666
697
|
# each of these templates intelligently, making educated guesses on correct
|
667
|
-
# content type and sequence, and return a fully prepared Mail::Message
|
668
|
-
# ready to call
|
698
|
+
# content type and sequence, and return a fully prepared <tt>Mail::Message</tt>
|
699
|
+
# ready to call <tt>:deliver</tt> on to send.
|
669
700
|
#
|
670
701
|
# For example:
|
671
702
|
#
|
672
703
|
# class Notifier < ActionMailer::Base
|
673
|
-
# default from: 'no-reply@test.lindsaar.net'
|
704
|
+
# default from: 'no-reply@test.lindsaar.net'
|
674
705
|
#
|
675
706
|
# def welcome
|
676
707
|
# mail(to: 'mikel@test.lindsaar.net')
|
@@ -733,7 +764,7 @@ module ActionMailer
|
|
733
764
|
m.charset = charset = headers[:charset]
|
734
765
|
|
735
766
|
# Set configure delivery behavior
|
736
|
-
wrap_delivery_behavior!(headers.delete(:delivery_method),headers.delete(:delivery_method_options))
|
767
|
+
wrap_delivery_behavior!(headers.delete(:delivery_method), headers.delete(:delivery_method_options))
|
737
768
|
|
738
769
|
# Assign all headers except parts_order, content_type and body
|
739
770
|
assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
|
@@ -9,7 +9,32 @@ module ActionMailer
|
|
9
9
|
#
|
10
10
|
# config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
|
11
11
|
#
|
12
|
-
|
12
|
+
mattr_accessor :preview_path, instance_writer: false
|
13
|
+
|
14
|
+
# :nodoc:
|
15
|
+
mattr_accessor :preview_interceptors, instance_writer: false
|
16
|
+
self.preview_interceptors = []
|
17
|
+
|
18
|
+
# Register one or more Interceptors which will be called before mail is previewed.
|
19
|
+
def register_preview_interceptors(*interceptors)
|
20
|
+
interceptors.flatten.compact.each { |interceptor| register_preview_interceptor(interceptor) }
|
21
|
+
end
|
22
|
+
|
23
|
+
# Register an Interceptor which will be called before mail is previewed.
|
24
|
+
# Either a class or a string can be passed in as the Interceptor. If a
|
25
|
+
# string is passed in it will be <tt>constantize</tt>d.
|
26
|
+
def register_preview_interceptor(interceptor)
|
27
|
+
preview_interceptor = case interceptor
|
28
|
+
when String, Symbol
|
29
|
+
interceptor.to_s.camelize.constantize
|
30
|
+
else
|
31
|
+
interceptor
|
32
|
+
end
|
33
|
+
|
34
|
+
unless preview_interceptors.include?(preview_interceptor)
|
35
|
+
preview_interceptors << preview_interceptor
|
36
|
+
end
|
37
|
+
end
|
13
38
|
end
|
14
39
|
end
|
15
40
|
|
@@ -23,10 +48,14 @@ module ActionMailer
|
|
23
48
|
descendants
|
24
49
|
end
|
25
50
|
|
26
|
-
# Returns the mail object for the given email name
|
51
|
+
# Returns the mail object for the given email name. The registered preview
|
52
|
+
# interceptors will be informed so that they can transform the message
|
53
|
+
# as they would if the mail was actually being delivered.
|
27
54
|
def call(email)
|
28
55
|
preview = self.new
|
29
|
-
preview.public_send(email)
|
56
|
+
message = preview.public_send(email)
|
57
|
+
inform_preview_interceptors(message)
|
58
|
+
message
|
30
59
|
end
|
31
60
|
|
32
61
|
# Returns all of the available email previews
|
@@ -56,12 +85,20 @@ module ActionMailer
|
|
56
85
|
|
57
86
|
protected
|
58
87
|
def load_previews #:nodoc:
|
59
|
-
|
88
|
+
if preview_path
|
89
|
+
Dir["#{preview_path}/**/*_preview.rb"].each{ |file| require_dependency file }
|
90
|
+
end
|
60
91
|
end
|
61
92
|
|
62
93
|
def preview_path #:nodoc:
|
63
94
|
Base.preview_path
|
64
95
|
end
|
96
|
+
|
97
|
+
def inform_preview_interceptors(message) #:nodoc:
|
98
|
+
Base.preview_interceptors.each do |interceptor|
|
99
|
+
interceptor.previewing_email(message)
|
100
|
+
end
|
101
|
+
end
|
65
102
|
end
|
66
103
|
end
|
67
104
|
end
|
@@ -19,6 +19,10 @@ module ActionMailer
|
|
19
19
|
options.javascripts_dir ||= paths["public/javascripts"].first
|
20
20
|
options.stylesheets_dir ||= paths["public/stylesheets"].first
|
21
21
|
|
22
|
+
if Rails.env.development?
|
23
|
+
options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil
|
24
|
+
end
|
25
|
+
|
22
26
|
# make sure readers methods get compiled
|
23
27
|
options.asset_host ||= app.config.asset_host
|
24
28
|
options.relative_url_root ||= app.config.relative_url_root
|
@@ -41,11 +45,9 @@ module ActionMailer
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
|
45
|
-
if
|
46
|
-
|
47
|
-
options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil
|
48
|
-
app.config.autoload_paths << options.preview_path
|
48
|
+
config.after_initialize do
|
49
|
+
if ActionMailer::Base.preview_path
|
50
|
+
ActiveSupport::Dependencies.autoload_paths << ActionMailer::Base.preview_path
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionmailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.0.
|
4
|
+
version: 4.1.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.1.0.
|
19
|
+
version: 4.1.0.rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.1.0.
|
26
|
+
version: 4.1.0.rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionview
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.1.0.
|
33
|
+
version: 4.1.0.rc1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.1.0.
|
40
|
+
version: 4.1.0.rc1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mail
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|