actionmailer 5.0.7.2 → 5.1.0.beta1

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.

@@ -1,6 +1,6 @@
1
- require 'abstract_controller/collector'
2
- require 'active_support/core_ext/hash/reverse_merge'
3
- require 'active_support/core_ext/array/extract_options'
1
+ require "abstract_controller/collector"
2
+ require "active_support/core_ext/hash/reverse_merge"
3
+ require "active_support/core_ext/array/extract_options"
4
4
 
5
5
  module ActionMailer
6
6
  class Collector
@@ -1,4 +1,4 @@
1
- require 'active_job'
1
+ require "active_job"
2
2
 
3
3
  module ActionMailer
4
4
  # The <tt>ActionMailer::DeliveryJob</tt> class is used when you
@@ -1,4 +1,4 @@
1
- require 'tmpdir'
1
+ require "tmpdir"
2
2
 
3
3
  module ActionMailer
4
4
  # This module handles everything related to mail delivery, from registering
@@ -25,7 +25,7 @@ module ActionMailer
25
25
  add_delivery_method :smtp, Mail::SMTP,
26
26
  address: "localhost",
27
27
  port: 25,
28
- domain: 'localhost.localdomain',
28
+ domain: "localhost.localdomain",
29
29
  user_name: nil,
30
30
  password: nil,
31
31
  authentication: nil,
@@ -35,8 +35,8 @@ module ActionMailer
35
35
  location: defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
36
36
 
37
37
  add_delivery_method :sendmail, Mail::Sendmail,
38
- location: '/usr/sbin/sendmail',
39
- arguments: '-i'
38
+ location: "/usr/sbin/sendmail",
39
+ arguments: "-i"
40
40
 
41
41
  add_delivery_method :test, Mail::TestMailer
42
42
  end
@@ -52,14 +52,14 @@ module ActionMailer
52
52
  # add_delivery_method :sendmail, Mail::Sendmail,
53
53
  # location: '/usr/sbin/sendmail',
54
54
  # arguments: '-i'
55
- def add_delivery_method(symbol, klass, default_options={})
55
+ def add_delivery_method(symbol, klass, default_options = {})
56
56
  class_attribute(:"#{symbol}_settings") unless respond_to?(:"#{symbol}_settings")
57
57
  send(:"#{symbol}_settings=", default_options)
58
58
  self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze
59
59
  end
60
60
 
61
- def wrap_delivery_behavior(mail, method=nil, options=nil) # :nodoc:
62
- method ||= self.delivery_method
61
+ def wrap_delivery_behavior(mail, method = nil, options = nil) # :nodoc:
62
+ method ||= delivery_method
63
63
  mail.delivery_handler = self
64
64
 
65
65
  case method
@@ -6,9 +6,9 @@ module ActionMailer
6
6
 
7
7
  module VERSION
8
8
  MAJOR = 5
9
- MINOR = 0
10
- TINY = 7
11
- PRE = "2"
9
+ MINOR = 1
10
+ TINY = 0
11
+ PRE = "beta1"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -1,4 +1,4 @@
1
- require 'base64'
1
+ require "base64"
2
2
 
3
3
  module ActionMailer
4
4
  # Implements a mailer preview interceptor that converts image tag src attributes
@@ -11,7 +11,7 @@ module ActionMailer
11
11
  # ActionMailer::Base.preview_interceptors.delete(ActionMailer::InlinePreviewInterceptor)
12
12
  #
13
13
  class InlinePreviewInterceptor
14
- PATTERN = /src=(?:"cid:[^"]+"|'cid:[^']+')/i
14
+ PATTERN = /src=(?:"cid:[^"]+"|'cid:[^']+')/i
15
15
 
16
16
  include Base64
17
17
 
@@ -26,7 +26,7 @@ module ActionMailer
26
26
  def transform! #:nodoc:
27
27
  return message if html_part.blank?
28
28
 
29
- html_source.gsub!(PATTERN) do |match|
29
+ html_part.body = html_part.decoded.gsub(PATTERN) do |match|
30
30
  if part = find_part(match[9..-2])
31
31
  %[src="#{data_url(part)}"]
32
32
  else
@@ -46,16 +46,12 @@ module ActionMailer
46
46
  @html_part ||= message.html_part
47
47
  end
48
48
 
49
- def html_source
50
- html_part.body.raw_source
51
- end
52
-
53
49
  def data_url(part)
54
50
  "data:#{part.mime_type};base64,#{strict_encode64(part.body.raw_source)}"
55
51
  end
56
52
 
57
53
  def find_part(cid)
58
- message.all_parts.find{ |p| p.attachment? && p.cid == cid }
54
+ message.all_parts.find { |p| p.attachment? && p.cid == cid }
59
55
  end
60
56
  end
61
57
  end
@@ -1,4 +1,4 @@
1
- require 'active_support/log_subscriber'
1
+ require "active_support/log_subscriber"
2
2
 
3
3
  module ActionMailer
4
4
  # Implements the ActiveSupport::LogSubscriber for logging notifications when
@@ -7,7 +7,7 @@ module ActionMailer
7
7
  # An email was delivered.
8
8
  def deliver(event)
9
9
  info do
10
- recipients = Array(event.payload[:to]).join(', ')
10
+ recipients = Array(event.payload[:to]).join(", ")
11
11
  "Sent mail to #{recipients} (#{event.duration.round(1)}ms)"
12
12
  end
13
13
 
@@ -54,7 +54,7 @@ module ActionMailer
54
54
  sentences = [[]]
55
55
 
56
56
  text.split.each do |word|
57
- if sentences.first.present? && (sentences.last + [word]).join(' ').length > len
57
+ if sentences.first.present? && (sentences.last + [word]).join(" ").length > len
58
58
  sentences << [word]
59
59
  else
60
60
  sentences.last << word
@@ -1,4 +1,4 @@
1
- require 'delegate'
1
+ require "delegate"
2
2
 
3
3
  module ActionMailer
4
4
  # The <tt>ActionMailer::MessageDelivery</tt> class is used by
@@ -56,7 +56,7 @@ module ActionMailer
56
56
  # * <tt>:wait</tt> - Enqueue the email to be delivered with a delay
57
57
  # * <tt>:wait_until</tt> - Enqueue the email to be delivered at (after) a specific date / time
58
58
  # * <tt>:queue</tt> - Enqueue the email on the specified queue
59
- def deliver_later!(options={})
59
+ def deliver_later!(options = {})
60
60
  enqueue_delivery :deliver_now!, options
61
61
  end
62
62
 
@@ -72,7 +72,7 @@ module ActionMailer
72
72
  # * <tt>:wait</tt> - Enqueue the email to be delivered with a delay.
73
73
  # * <tt>:wait_until</tt> - Enqueue the email to be delivered at (after) a specific date / time.
74
74
  # * <tt>:queue</tt> - Enqueue the email on the specified queue.
75
- def deliver_later(options={})
75
+ def deliver_later(options = {})
76
76
  enqueue_delivery :deliver_now, options
77
77
  end
78
78
 
@@ -106,7 +106,7 @@ module ActionMailer
106
106
  end
107
107
  end
108
108
 
109
- def enqueue_delivery(delivery_method, options={})
109
+ def enqueue_delivery(delivery_method, options = {})
110
110
  if processed?
111
111
  ::Kernel.raise "You've accessed the message before asking to " \
112
112
  "deliver it later, so you may have made local changes that would " \
@@ -0,0 +1,152 @@
1
+ module ActionMailer
2
+ # Provides the option to parameterize mailers in order to share instance variable
3
+ # setup, processing, and common headers.
4
+ #
5
+ # Consider this example that does not use parameterization:
6
+ #
7
+ # class InvitationsMailer < ApplicationMailer
8
+ # def account_invitation(inviter, invitee)
9
+ # @account = inviter.account
10
+ # @inviter = inviter
11
+ # @invitee = invitee
12
+ #
13
+ # subject = "#{@inviter.name} invited you to their Basecamp (#{@account.name})"
14
+ #
15
+ # mail \
16
+ # subject: subject,
17
+ # to: invitee.email_address,
18
+ # from: common_address(inviter),
19
+ # reply_to: inviter.email_address_with_name
20
+ # end
21
+ #
22
+ # def project_invitation(project, inviter, invitee)
23
+ # @account = inviter.account
24
+ # @project = project
25
+ # @inviter = inviter
26
+ # @invitee = invitee
27
+ # @summarizer = ProjectInvitationSummarizer.new(@project.bucket)
28
+ #
29
+ # subject = "#{@inviter.name.familiar} added you to a project in Basecamp (#{@account.name})"
30
+ #
31
+ # mail \
32
+ # subject: subject,
33
+ # to: invitee.email_address,
34
+ # from: common_address(inviter),
35
+ # reply_to: inviter.email_address_with_name
36
+ # end
37
+ #
38
+ # def bulk_project_invitation(projects, inviter, invitee)
39
+ # @account = inviter.account
40
+ # @projects = projects.sort_by(&:name)
41
+ # @inviter = inviter
42
+ # @invitee = invitee
43
+ #
44
+ # subject = "#{@inviter.name.familiar} added you to some new stuff in Basecamp (#{@account.name})"
45
+ #
46
+ # mail \
47
+ # subject: subject,
48
+ # to: invitee.email_address,
49
+ # from: common_address(inviter),
50
+ # reply_to: inviter.email_address_with_name
51
+ # end
52
+ # end
53
+ #
54
+ # InvitationsMailer.account_invitation(person_a, person_b).deliver_later
55
+ #
56
+ # Using parameterized mailers, this can be rewritten as:
57
+ #
58
+ # class InvitationsMailer < ApplicationMailer
59
+ # before_action { @inviter, @invitee = params[:inviter], params[:invitee] }
60
+ # before_action { @account = params[:inviter].account }
61
+ #
62
+ # default to: -> { @invitee.email_address },
63
+ # from: -> { common_address(@inviter) },
64
+ # reply_to: -> { @inviter.email_address_with_name }
65
+ #
66
+ # def account_invitation
67
+ # mail subject: "#{@inviter.name} invited you to their Basecamp (#{@account.name})"
68
+ # end
69
+ #
70
+ # def project_invitation
71
+ # @project = params[:project]
72
+ # @summarizer = ProjectInvitationSummarizer.new(@project.bucket)
73
+ #
74
+ # mail subject: "#{@inviter.name.familiar} added you to a project in Basecamp (#{@account.name})"
75
+ # end
76
+ #
77
+ # def bulk_project_invitation
78
+ # @projects = params[:projects].sort_by(&:name)
79
+ #
80
+ # mail subject: "#{@inviter.name.familiar} added you to some new stuff in Basecamp (#{@account.name})"
81
+ # end
82
+ # end
83
+ #
84
+ # InvitationsMailer.with(inviter: person_a, invitee: person_b).account_invitation.deliver_later
85
+ module Parameterized
86
+ extend ActiveSupport::Concern
87
+
88
+ included do
89
+ attr_accessor :params
90
+ end
91
+
92
+ module ClassMethods
93
+ # Provide the parameters to the mailer in order to use them in the instance methods and callbacks.
94
+ #
95
+ # InvitationsMailer.with(inviter: person_a, invitee: person_b).account_invitation.deliver_later
96
+ #
97
+ # See Parameterized documentation for full example.
98
+ def with(params)
99
+ ActionMailer::Parameterized::Mailer.new(self, params)
100
+ end
101
+ end
102
+
103
+ class Mailer # :nodoc:
104
+ def initialize(mailer, params)
105
+ @mailer, @params = mailer, params
106
+ end
107
+
108
+ private
109
+ def method_missing(method_name, *args)
110
+ if @mailer.action_methods.include?(method_name.to_s)
111
+ ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, *args)
112
+ else
113
+ super
114
+ end
115
+ end
116
+
117
+ def respond_to_missing?(method, include_all = false)
118
+ @mailer.respond_to?(method, include_all)
119
+ end
120
+ end
121
+
122
+ class MessageDelivery < ActionMailer::MessageDelivery # :nodoc:
123
+ def initialize(mailer_class, action, params, *args)
124
+ super(mailer_class, action, *args)
125
+ @params = params
126
+ end
127
+
128
+ private
129
+ def processed_mailer
130
+ @processed_mailer ||= @mailer_class.new.tap do |mailer|
131
+ mailer.params = @params
132
+ mailer.process @action, *@args
133
+ end
134
+ end
135
+
136
+ def enqueue_delivery(delivery_method, options = {})
137
+ if processed?
138
+ super
139
+ else
140
+ args = @mailer_class.name, @action.to_s, delivery_method.to_s, @params, *@args
141
+ ActionMailer::Parameterized::DeliveryJob.set(options).perform_later(*args)
142
+ end
143
+ end
144
+ end
145
+
146
+ class DeliveryJob < ActionMailer::DeliveryJob # :nodoc:
147
+ def perform(mailer, mail_method, delivery_method, params, *args)
148
+ mailer.constantize.with(params).public_send(mail_method, *args).send(delivery_method)
149
+ end
150
+ end
151
+ end
152
+ end
@@ -1,4 +1,4 @@
1
- require 'active_support/descendants_tracker'
1
+ require "active_support/descendants_tracker"
2
2
 
3
3
  module ActionMailer
4
4
  module Previews #:nodoc:
@@ -34,7 +34,8 @@ module ActionMailer
34
34
  # Either a class or a string can be passed in as the Interceptor. If a
35
35
  # string is passed in it will be <tt>constantize</tt>d.
36
36
  def register_preview_interceptor(interceptor)
37
- preview_interceptor = case interceptor
37
+ preview_interceptor = \
38
+ case interceptor
38
39
  when String, Symbol
39
40
  interceptor.to_s.camelize.constantize
40
41
  else
@@ -62,7 +63,7 @@ module ActionMailer
62
63
  # interceptors will be informed so that they can transform the message
63
64
  # as they would if the mail was actually being delivered.
64
65
  def call(email)
65
- preview = self.new
66
+ preview = new
66
67
  message = preview.public_send(email)
67
68
  inform_preview_interceptors(message)
68
69
  message
@@ -80,35 +81,35 @@ module ActionMailer
80
81
 
81
82
  # Returns true if the preview exists.
82
83
  def exists?(preview)
83
- all.any?{ |p| p.preview_name == preview }
84
+ all.any? { |p| p.preview_name == preview }
84
85
  end
85
86
 
86
87
  # Find a mailer preview by its underscored class name.
87
88
  def find(preview)
88
- all.find{ |p| p.preview_name == preview }
89
+ all.find { |p| p.preview_name == preview }
89
90
  end
90
91
 
91
92
  # Returns the underscored name of the mailer preview without the suffix.
92
93
  def preview_name
93
- name.sub(/Preview$/, '').underscore
94
+ name.sub(/Preview$/, "").underscore
94
95
  end
95
96
 
96
- protected
97
- def load_previews #:nodoc:
97
+ private
98
+ def load_previews
98
99
  if preview_path
99
- Dir["#{preview_path}/**/*_preview.rb"].each{ |file| require_dependency file }
100
+ Dir["#{preview_path}/**/*_preview.rb"].each { |file| require_dependency file }
100
101
  end
101
102
  end
102
103
 
103
- def preview_path #:nodoc:
104
+ def preview_path
104
105
  Base.preview_path
105
106
  end
106
107
 
107
- def show_previews #:nodoc:
108
+ def show_previews
108
109
  Base.show_previews
109
110
  end
110
111
 
111
- def inform_preview_interceptors(message) #:nodoc:
112
+ def inform_preview_interceptors(message)
112
113
  Base.preview_interceptors.each do |interceptor|
113
114
  interceptor.previewing_email(message)
114
115
  end
@@ -1,4 +1,4 @@
1
- require 'active_job/railtie'
1
+ require "active_job/railtie"
2
2
  require "action_mailer"
3
3
  require "rails"
4
4
  require "abstract_controller/railties/routes_helpers"
@@ -18,7 +18,7 @@ module ActionMailer
18
18
 
19
19
  if app.config.force_ssl
20
20
  options.default_url_options ||= {}
21
- options.default_url_options[:protocol] ||= 'https'
21
+ options.default_url_options[:protocol] ||= "https"
22
22
  end
23
23
 
24
24
  options.assets_dir ||= paths["public"].first
@@ -28,7 +28,7 @@ module ActionMailer
28
28
  options.cache_store ||= Rails.cache
29
29
 
30
30
  if options.show_previews
31
- options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil
31
+ options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil
32
32
  end
33
33
 
34
34
  # make sure readers methods get compiled
@@ -44,7 +44,7 @@ module ActionMailer
44
44
  register_preview_interceptors(options.delete(:preview_interceptors))
45
45
  register_observers(options.delete(:observers))
46
46
 
47
- options.each { |k,v| send("#{k}=", v) }
47
+ options.each { |k, v| send("#{k}=", v) }
48
48
  end
49
49
 
50
50
  ActiveSupport.on_load(:action_dispatch_integration_test) { include ActionMailer::TestCase::ClearTestDeliveries }
@@ -61,8 +61,8 @@ module ActionMailer
61
61
 
62
62
  if options.show_previews
63
63
  app.routes.prepend do
64
- get '/rails/mailers' => "rails/mailers#index", internal: true
65
- get '/rails/mailers/*path' => "rails/mailers#preview", internal: true
64
+ get "/rails/mailers" => "rails/mailers#index", internal: true
65
+ get "/rails/mailers/*path" => "rails/mailers#preview", internal: true
66
66
  end
67
67
 
68
68
  if options.preview_path
@@ -1,11 +1,11 @@
1
- require 'active_support/test_case'
2
- require 'rails-dom-testing'
1
+ require "active_support/test_case"
2
+ require "rails-dom-testing"
3
3
 
4
4
  module ActionMailer
5
5
  class NonInferrableMailerError < ::StandardError
6
6
  def initialize(name)
7
- super "Unable to determine the mailer to test from #{name}. " +
8
- "You'll need to specify it using tests YourMailer in your " +
7
+ super "Unable to determine the mailer to test from #{name}. " \
8
+ "You'll need to specify it using tests YourMailer in your " \
9
9
  "test case definition"
10
10
  end
11
11
  end
@@ -21,11 +21,11 @@ module ActionMailer
21
21
 
22
22
  private
23
23
 
24
- def clear_test_deliveries
25
- if ActionMailer::Base.delivery_method == :test
26
- ActionMailer::Base.deliveries.clear
24
+ def clear_test_deliveries
25
+ if ActionMailer::Base.delivery_method == :test
26
+ ActionMailer::Base.deliveries.clear
27
+ end
27
28
  end
28
- end
29
29
  end
30
30
 
31
31
  module Behavior
@@ -57,7 +57,7 @@ module ActionMailer
57
57
  end
58
58
 
59
59
  def mailer_class
60
- if mailer = self._mailer_class
60
+ if mailer = _mailer_class
61
61
  mailer
62
62
  else
63
63
  tests determine_default_mailer(name)
@@ -73,38 +73,36 @@ module ActionMailer
73
73
  end
74
74
  end
75
75
 
76
- protected
76
+ private
77
77
 
78
- def initialize_test_deliveries # :nodoc:
78
+ def initialize_test_deliveries
79
79
  set_delivery_method :test
80
80
  @old_perform_deliveries = ActionMailer::Base.perform_deliveries
81
81
  ActionMailer::Base.perform_deliveries = true
82
82
  ActionMailer::Base.deliveries.clear
83
83
  end
84
84
 
85
- def restore_test_deliveries # :nodoc:
85
+ def restore_test_deliveries
86
86
  restore_delivery_method
87
87
  ActionMailer::Base.perform_deliveries = @old_perform_deliveries
88
88
  end
89
89
 
90
- def set_delivery_method(method) # :nodoc:
90
+ def set_delivery_method(method)
91
91
  @old_delivery_method = ActionMailer::Base.delivery_method
92
92
  ActionMailer::Base.delivery_method = method
93
93
  end
94
94
 
95
- def restore_delivery_method # :nodoc:
95
+ def restore_delivery_method
96
96
  ActionMailer::Base.deliveries.clear
97
97
  ActionMailer::Base.delivery_method = @old_delivery_method
98
98
  end
99
99
 
100
- def set_expected_mail # :nodoc:
100
+ def set_expected_mail
101
101
  @expected = Mail.new
102
102
  @expected.content_type ["text", "plain", { "charset" => charset }]
103
- @expected.mime_version = '1.0'
103
+ @expected.mime_version = "1.0"
104
104
  end
105
105
 
106
- private
107
-
108
106
  def charset
109
107
  "UTF-8"
110
108
  end
@@ -114,7 +112,7 @@ module ActionMailer
114
112
  end
115
113
 
116
114
  def read_fixture(action)
117
- IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
115
+ IO.readlines(File.join(Rails.root, "test", "fixtures", self.class.mailer_class.name.underscore, action))
118
116
  end
119
117
  end
120
118