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.

Potentially problematic release.


This version of actionmailer might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d1be44f98a1d15f4147084fe748a4d2bb341f84
4
- data.tar.gz: 4f45039a7220de20dd7c39d81637958d81f1a798
3
+ metadata.gz: a14d6592f23edce89a35a8e248fe9c9aab6ec9db
4
+ data.tar.gz: 9b164dc18c93ab42fe0202d5ba9be3832ce417cd
5
5
  SHA512:
6
- metadata.gz: 2aed9b26621ecc7880aa8643667e28f90dcf09495bdffa7bc3d0dfb491abc053fdb44546a47c0f5037c80d462ba5a96c0dd946ccf13ec2fff590ad9b5405eb98
7
- data.tar.gz: 5df15c31c6bb1ae07e92ab3cb8c81eaa302736a06cec85b81085232a6ea2d4397e165223a577b78a8026c8d336d82b48c8154eeb3cd9a566a9e2cee5a22f0e77
6
+ metadata.gz: 8ae74e8854276fced21a93d2994ae4841afe49777b96ca49f7b341ed1241ccaae293546c09a00c877ef9afe8f2f07a68f60832729d5ab6eba073b420897c589a
7
+ data.tar.gz: ca8bf17a413211b4696fdbf3dc91e9f1310da3dc35fe5c322d6265468fd281a2c01b67920651e7a4f40ae678065d258adc876afac204e2b29ab5c691b03e6024
@@ -1,10 +1,34 @@
1
- * Add mailer previews feature based on 37 Signals mail_view gem
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2013 David Heinemeier Hansson
1
+ Copyright (c) 2004-2014 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -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 e-mail messages has, 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.
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
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2004-2013 David Heinemeier Hansson
2
+ # Copyright (c) 2004-2014 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -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 Email header including optional fields).
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', 'peer', 'client_once', 'fail_if_no_peer_cert') or directly the
358
- # constant (OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER, ...).
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. See the Mail gem documentation on the interface you need to
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 a string can be passed in as the Observer. If a string is passed in
429
- # it will be +constantize+d.
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 = (observer.is_a?(String) ? observer.constantize : 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 a string can be passed in as the Interceptor. If a string is passed in
437
- # it will be <tt>constantize</tt>d.
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 = (interceptor.is_a?(String) ? interceptor.constantize : 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 +:deliver+ on the Mail::Message,
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 +:deliver+ on to send.
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
- class_attribute :preview_path, instance_writer: false
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
- Dir["#{preview_path}/**/*_preview.rb"].each{ |file| require_dependency file }
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
- initializer "action_mailer.configure_mailer_previews", before: :set_autoload_paths do |app|
45
- if Rails.env.development?
46
- options = app.config.action_mailer
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
@@ -1,7 +1,7 @@
1
1
  module ActionMailer
2
2
  # Returns the version of the currently loaded ActionMailer as a Gem::Version
3
3
  def self.version
4
- Gem::Version.new "4.1.0.beta2"
4
+ Gem::Version.new "4.1.0.rc1"
5
5
  end
6
6
 
7
7
  module VERSION #:nodoc:
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.beta2
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.beta2
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.beta2
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.beta2
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.beta2
40
+ version: 4.1.0.rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mail
43
43
  requirement: !ruby/object:Gem::Requirement