postageapp 1.0.24 → 1.2.0

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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +13 -12
  3. data/Gemfile +6 -1
  4. data/LICENSE +1 -1
  5. data/README.md +122 -70
  6. data/Rakefile +19 -4
  7. data/generators/postageapp/postageapp_generator.rb +5 -7
  8. data/lib/generators/postageapp/postageapp_generator.rb +15 -9
  9. data/lib/postageapp.rb +42 -36
  10. data/lib/postageapp/configuration.rb +34 -21
  11. data/lib/postageapp/failed_request.rb +60 -36
  12. data/lib/postageapp/logger.rb +6 -7
  13. data/lib/postageapp/mail.rb +3 -0
  14. data/lib/postageapp/mail/arguments.rb +75 -0
  15. data/lib/postageapp/mail/delivery_method.rb +32 -0
  16. data/lib/postageapp/mail/extensions.rb +21 -0
  17. data/lib/postageapp/mailer.rb +72 -20
  18. data/lib/postageapp/mailer/mailer_2.rb +65 -22
  19. data/lib/postageapp/mailer/mailer_3.rb +45 -28
  20. data/lib/postageapp/mailer/mailer_4.rb +72 -40
  21. data/lib/postageapp/rails/rails.rb +17 -7
  22. data/lib/postageapp/rails/railtie.rb +22 -7
  23. data/lib/postageapp/request.rb +67 -43
  24. data/lib/postageapp/response.rb +11 -8
  25. data/lib/postageapp/utils.rb +11 -3
  26. data/lib/postageapp/version.rb +2 -2
  27. data/postageapp.gemspec +13 -11
  28. data/rails/init.rb +1 -1
  29. data/test/configuration_test.rb +35 -38
  30. data/test/failed_request_test.rb +33 -18
  31. data/test/gemfiles/Gemfile.rails-2.3.x +4 -1
  32. data/test/gemfiles/Gemfile.rails-3.0.x +4 -1
  33. data/test/gemfiles/Gemfile.rails-3.1.x +4 -1
  34. data/test/gemfiles/Gemfile.rails-3.2.x +4 -1
  35. data/test/gemfiles/Gemfile.rails-4.0.x +4 -1
  36. data/test/gemfiles/Gemfile.rails-4.1.x +12 -0
  37. data/test/gemfiles/Gemfile.rails-4.2.x +12 -0
  38. data/test/gemfiles/Gemfile.ruby +11 -0
  39. data/test/helper.rb +52 -33
  40. data/test/live_test.rb +11 -8
  41. data/test/mail_delivery_method_test.rb +161 -0
  42. data/test/mailer/action_mailer_2/notifier.rb +37 -28
  43. data/test/mailer/action_mailer_3/notifier.rb +28 -22
  44. data/test/mailer_2_test.rb +20 -16
  45. data/test/mailer_3_test.rb +16 -22
  46. data/test/mailer_4_test.rb +28 -28
  47. data/test/mailer_helper_methods_test.rb +17 -14
  48. data/test/postageapp_test.rb +8 -9
  49. data/test/rails_initialization_test.rb +14 -14
  50. data/test/request_test.rb +35 -35
  51. data/test/response_test.rb +20 -19
  52. data/test/travis_test.rb +168 -0
  53. data/test/with_environment.rb +27 -0
  54. metadata +23 -17
@@ -0,0 +1,21 @@
1
+ module PostageApp::Mail::Extensions
2
+ def self.install!
3
+ # Register PostageApp as a valid Mail delivery method, allows the shorthand
4
+ # Mail.delivery_method :postageapp
5
+ ::Mail::Configuration.class_eval do
6
+ alias_method :__base_lookup_delivery_method, :lookup_delivery_method
7
+
8
+ # This requires wrapping around the lookup_delivery_method method to
9
+ # add a new case. Unlike ActionMailer there is no way to register new
10
+ # delivery methods.
11
+ def lookup_delivery_method(method)
12
+ case (method.is_a?(String) ? method.to_sym : method)
13
+ when :postageapp
14
+ PostageApp::Mail::DeliveryMethod
15
+ else
16
+ __base_lookup_delivery_method(method)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,52 +1,104 @@
1
- require 'action_mailer'
2
- require 'action_mailer/version'
3
-
4
- # Loading PostageApp::Mailer class depending on what action_mailer is
5
- # currently installed on the system. Assuming we're dealing only with
6
- # ones that come with Rails 2 and 3
7
- if ActionMailer::VERSION::MAJOR == 4
8
- require File.expand_path('../mailer/mailer_4', __FILE__)
9
- elsif ActionMailer::VERSION::MAJOR == 3
10
- require File.expand_path('../mailer/mailer_3', __FILE__)
11
- else
12
- require File.expand_path('../mailer/mailer_2', __FILE__)
1
+ begin
2
+ require 'action_mailer'
3
+ require 'action_mailer/version'
4
+
5
+ rescue LoadError
6
+ # ActionMailer not available
7
+ end
8
+
9
+ if (defined?(ActionMailer))
10
+ # Loading PostageApp::Mailer class depending on what action_mailer is
11
+ # currently installed on the system. Assuming we're dealing only with
12
+ # ones that come with Rails 2 and 3
13
+ case (ActionMailer::VERSION::MAJOR)
14
+ when 4
15
+ require File.expand_path('mailer/mailer_4', File.dirname(__FILE__))
16
+ when 3
17
+ require File.expand_path('mailer/mailer_3', File.dirname(__FILE__))
18
+ else
19
+ require File.expand_path('mailer/mailer_2', File.dirname(__FILE__))
20
+ end
13
21
  end
14
22
 
15
23
  # General helper methods for Request object to act more like TMail::Mail
16
24
  # of Mail for testing
17
25
  class PostageApp::Request
18
-
19
26
  # Getter and setter for headers. You can specify headers in the following
20
27
  # formats:
21
28
  # headers['Custom-Header'] = 'Custom Value'
22
29
  # headers 'Custom-Header-1' => 'Custom Value 1',
23
30
  # 'Custom-Header-2' => 'Custom Value 2'
24
31
  def headers(value = nil)
25
- self.arguments['headers'] ||= { }
26
- if value && value.is_a?(Hash)
32
+ _headers = self.arguments['headers'] ||= { }
33
+
34
+ case (value)
35
+ when Hash
27
36
  value.each do |k, v|
28
- self.arguments['headers'][k.to_s] = v.to_s
37
+ _headers[k.to_s] = v.to_s
29
38
  end
30
39
  end
31
- self.arguments['headers']
40
+
41
+ _headers
42
+ end
43
+
44
+ def [](key)
45
+ case (key)
46
+ when :to, 'to'
47
+ self.to
48
+ when :from, 'from'
49
+ self.from
50
+ when :bcc, 'bcc'
51
+ # Not supported via API at this time
52
+ [ ]
53
+ end
32
54
  end
33
55
 
34
56
  def to
35
57
  out = self.arguments_to_send.dig('arguments', 'recipients')
36
- out.is_a?(Hash) ? out : [out].flatten
58
+
59
+ case (out)
60
+ when Hash
61
+ out
62
+ else
63
+ [ out ].flatten
64
+ end
65
+ end
66
+
67
+ def to=(list)
68
+ self.arguments['recipients'] = list
37
69
  end
38
70
 
39
71
  def from
40
- [self.arguments_to_send.dig('arguments', 'headers', 'from')].flatten
72
+ [ self.arguments_to_send.dig('arguments', 'headers', 'from') ].flatten
73
+ end
74
+
75
+ def from=(address)
76
+ _headers = self.arguments['headers'] ||= { }
77
+
78
+ _headers['from'] = address.to_s
79
+ end
80
+
81
+ def bcc
82
+ # Not supported natively via API at this time
83
+ [ ]
84
+ end
85
+
86
+ def bcc=(list)
87
+ # Not supported natively via API at this time
41
88
  end
42
89
 
43
90
  def subject
44
91
  self.arguments_to_send.dig('arguments', 'headers', 'subject')
45
92
  end
46
93
 
94
+ def subject=(subject)
95
+ _headers = self.arguments['headers'] ||= { }
96
+
97
+ _headers['subject'] = subject.to_s
98
+ end
99
+
47
100
  def body
48
101
  out = self.arguments_to_send.dig('arguments', 'content')
49
102
  out.is_a?(Hash) ? out.values.join("\n\n") : out.to_s
50
103
  end
51
-
52
104
  end
@@ -25,9 +25,10 @@
25
25
  # request = Notifier.create_signup_notification(user) # creates PostageApp::Request object
26
26
  #
27
27
  class PostageApp::Mailer < ActionMailer::Base
28
-
29
28
  # Using :test as a delivery method if set somewhere else
30
- self.delivery_method = :postage unless (self.delivery_method == :test)
29
+ unless (self.delivery_method == :test)
30
+ self.delivery_method = :postage
31
+ end
31
32
 
32
33
  adv_attr_accessor :postageapp_uid
33
34
  adv_attr_accessor :postageapp_api_key
@@ -39,50 +40,92 @@ class PostageApp::Mailer < ActionMailer::Base
39
40
  end
40
41
 
41
42
  def deliver!(mail = @mail)
42
- raise 'PostageApp::Request object not present, cannot deliver' unless mail
43
- __send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries
43
+ unless (mail)
44
+ raise 'PostageApp::Request object not present, cannot deliver'
45
+ end
46
+
47
+ if (perform_deliveries)
48
+ __send__("perform_delivery_#{delivery_method}", mail)
49
+ end
44
50
  end
45
51
 
46
52
  # Creating a Postage::Request object unlike TMail one in ActionMailer::Base
47
53
  def create_mail
48
54
  params = { }
49
- params['recipients'] = self.recipients unless self.recipients.blank?
55
+
56
+ unless (self.recipients.blank?)
57
+ params['recipients'] = self.recipients
58
+ end
50
59
 
51
60
  params['headers'] = { }
52
- params['headers']['subject'] = self.subject unless self.subject.blank?
53
- params['headers']['from'] = self.from unless self.from.blank?
54
- params['headers'].merge!(self.headers) unless self.headers.blank?
61
+
62
+ unless (self.subject.blank?)
63
+ params['headers']['subject'] = self.subject
64
+ end
65
+
66
+ unless (self.subject.blank?)
67
+ params['headers']['from'] = self.from
68
+ end
69
+
70
+ unless (self.headers.blank?)
71
+ params['headers'].merge!(self.headers)
72
+ end
55
73
 
56
74
  params['content'] = { }
57
75
  params['attachments'] = { }
58
76
 
59
- if @parts.empty?
60
- params['content'][self.content_type] = self.body unless self.body.blank?
77
+ if (@parts.empty?)
78
+ unless (self.body.blank?)
79
+ params['content'][self.content_type] = self.body
80
+ end
61
81
  else
62
82
  self.parts.each do |part|
63
- case part.content_disposition
83
+ case (part.content_disposition)
64
84
  when 'inline'
65
- part.content_type = 'text/plain' if part.content_type.blank? && String === part.body
85
+ if (part.content_type.blank? && String === part.body)
86
+ part.content_type = 'text/plain'
87
+ end
88
+
66
89
  params['content'][part.content_type] = part.body
67
90
  when 'attachment'
68
91
  params['attachments'][part.filename] = {
69
92
  'content_type' => part.content_type,
70
- 'content' => Base64.encode64(part.body)
93
+ 'content' => Base64.encode64(part.body)
71
94
  }
72
95
  end
73
96
  end
74
97
  end
75
98
 
76
- params['template'] = self.postageapp_template unless self.postageapp_template.blank?
77
- params['variables'] = self.postageapp_variables unless self.postageapp_variables.blank?
99
+ unless (self.postageapp_template.blank?)
100
+ params['template'] = self.postageapp_template
101
+ end
102
+
103
+ unless (self.postageapp_variables.blank?)
104
+ params['variables'] = self.postageapp_variables
105
+ end
78
106
 
79
- params.delete('headers') if params['headers'].blank?
80
- params.delete('content') if params['content'].blank?
81
- params.delete('attachments') if params['attachments'].blank?
107
+ if (params['headers'].blank?)
108
+ params.delete('headers')
109
+ end
110
+
111
+ if (params['content'].blank?)
112
+ params.delete('content')
113
+ end
114
+
115
+ if (params['attachments'].blank?)
116
+ params.delete('attachments')
117
+ end
82
118
 
83
119
  @mail = PostageApp::Request.new('send_message', params)
84
- @mail.uid = self.postageapp_uid unless self.postageapp_uid.blank?
85
- @mail.api_key = self.postageapp_api_key unless self.postageapp_api_key.blank?
120
+
121
+ unless (self.postageapp_uid.blank?)
122
+ @mail.uid = self.postageapp_uid
123
+ end
124
+
125
+ unless (self.postageapp_api_key.blank?)
126
+ @mail.api_key = self.postageapp_api_key
127
+ end
128
+
86
129
  @mail
87
130
  end
88
131
 
@@ -90,8 +133,8 @@ class PostageApp::Mailer < ActionMailer::Base
90
133
  # provided that the template is defined.
91
134
  def render(opts)
92
135
  super(opts)
136
+
93
137
  rescue ActionView::MissingTemplate
94
138
  # do nothing
95
139
  end
96
-
97
- end
140
+ end
@@ -25,34 +25,37 @@
25
25
  #
26
26
  # request = Notifier.signup_notification(user) # creates PostageApp::Request object
27
27
  # response = request.deliver # attempts to deliver the message and creates a PostageApp::Response
28
- #
29
- class PostageApp::Mailer < ActionMailer::Base
30
28
 
29
+ class PostageApp::Mailer < ActionMailer::Base
31
30
  # Wrapper for creating attachments
32
31
  # Attachments sent to PostageApp are in the following format:
33
32
  # 'filename.ext' => {
34
33
  # 'content_type' => 'content/type',
35
34
  # 'content' => 'base64_encoded_content'
36
35
  # }
37
- class Attachments < Hash
38
36
 
37
+ class Attachments < Hash
39
38
  def initialize(message)
40
39
  @_message = message
40
+
41
41
  message.arguments['attachments'] ||= { }
42
42
  end
43
43
 
44
44
  def []=(filename, attachment)
45
45
  default_content_type = MIME::Types.type_for(filename).first.content_type rescue ''
46
- if attachment.is_a?(Hash)
47
- content_type = attachment[:content_type] || default_content_type
48
- content = Base64.encode64(attachment[:body])
46
+
47
+ case (attachment)
48
+ when Hash
49
+ content_type = attachment[:content_type] || default_content_type
50
+ content = Base64.encode64(attachment[:body])
49
51
  else
50
- content_type = default_content_type
51
- content = Base64.encode64(attachment)
52
+ content_type = default_content_type
53
+ content = Base64.encode64(attachment)
52
54
  end
55
+
53
56
  @_message.arguments['attachments'][filename] = {
54
- 'content_type' => content_type,
55
- 'content' => content
57
+ 'content_type' => content_type,
58
+ 'content' => content
56
59
  }
57
60
  end
58
61
  end
@@ -60,8 +63,12 @@ class PostageApp::Mailer < ActionMailer::Base
60
63
  # Instead of initializing Mail object, we prepare PostageApp::Request
61
64
  def initialize(method_name = nil, *args)
62
65
  super()
66
+
63
67
  @_message = PostageApp::Request.new(:send_message)
64
- process(method_name, *args) if method_name
68
+
69
+ if method_name
70
+ process(method_name, *args)
71
+ end
65
72
  end
66
73
 
67
74
  # Possible to define custom uid. Should be sufficiently unique
@@ -76,12 +83,20 @@ class PostageApp::Mailer < ActionMailer::Base
76
83
  # In API call we can specify PostageApp template that will be used
77
84
  # to generate content of the message
78
85
  def postageapp_template(value = nil)
79
- value ? @_message.arguments['template'] = value : @_message.arguments['template']
86
+ if (value)
87
+ @_message.arguments['template'] = value
88
+ else
89
+ @_message.arguments['template']
90
+ end
80
91
  end
81
92
 
82
93
  # Hash of variables that will be used to inject into the content
83
94
  def postageapp_variables(value = nil)
84
- value ? @_message.arguments['variables'] = value : @_message.arguments['variables']
95
+ if (value)
96
+ @_message.arguments['variables'] = value
97
+ else
98
+ @_message.arguments['variables']
99
+ end
85
100
  end
86
101
 
87
102
  def attachments
@@ -89,13 +104,13 @@ class PostageApp::Mailer < ActionMailer::Base
89
104
  end
90
105
 
91
106
  # Override for headers assignment
92
- def headers(args=nil)
107
+ def headers(args = nil)
93
108
  @_message.headers(args)
94
109
  end
95
110
 
96
111
  # Overriding method that prepares Mail object. This time we'll be
97
112
  # contructing PostageApp::Request payload.
98
- def mail(headers = {}, &block)
113
+ def mail(headers = { }, &block)
99
114
  # Guard flag to prevent both the old and the new API from firing
100
115
  # Should be removed when old API is removed
101
116
  @mail_was_called = true
@@ -103,11 +118,15 @@ class PostageApp::Mailer < ActionMailer::Base
103
118
 
104
119
  # At the beginning, do not consider class default for parts order neither content_type
105
120
  content_type = headers[:content_type]
106
- parts_order = headers[:parts_order]
121
+ parts_order = headers[:parts_order]
107
122
 
108
123
  # Call all the procs (if any)
109
124
  default_values = self.class.default.merge(self.class.default) do |k,v|
110
- v.respond_to?(:call) ? v.bind(self).call : v
125
+ if (v.respond_to?(:call))
126
+ v.bind(self).call
127
+ else
128
+ v
129
+ end
111
130
  end
112
131
 
113
132
  # Handle defaults
@@ -131,22 +150,20 @@ class PostageApp::Mailer < ActionMailer::Base
131
150
  end
132
151
 
133
152
  protected
134
-
135
153
  def create_parts_from_responses(m, responses) #:nodoc:
136
- content = m.arguments['content'] ||= {}
154
+ content = m.arguments['content'] ||= { }
155
+
137
156
  responses.each do |part|
138
157
  content[part[:content_type]] = part[:body]
139
158
  end
140
159
  end
141
-
142
160
  end
143
161
 
144
162
  # A set of methods that are useful when request needs to behave as Mail
145
163
  class PostageApp::Request
146
-
147
- attr_accessor :delivery_handler,
148
- :perform_deliveries,
149
- :raise_delivery_errors
164
+ attr_accessor :delivery_handler
165
+ attr_accessor :perform_deliveries
166
+ attr_accessor :raise_delivery_errors
150
167
 
151
168
  def inform_interceptors
152
169
  Mail.inform_interceptors(self)
@@ -156,8 +173,9 @@ class PostageApp::Request
156
173
  # Probably not the best way as we're skipping way too many intermediate methods
157
174
  def deliver
158
175
  inform_interceptors
159
- if perform_deliveries
160
- if @delivery_method == Mail::TestMailer
176
+
177
+ if (perform_deliveries)
178
+ if (@delivery_method == Mail::TestMailer)
161
179
  @delivery_method.deliveries << self
162
180
  else
163
181
  self.send
@@ -166,8 +184,7 @@ class PostageApp::Request
166
184
  end
167
185
 
168
186
  # Not 100% on this, but I need to assign this so I can properly handle deliver method
169
- def delivery_method(method = nil, settings = {})
187
+ def delivery_method(method = nil, settings = { })
170
188
  @delivery_method = method
171
189
  end
172
-
173
190
  end
@@ -9,9 +9,9 @@
9
9
  # class Notifier < PostageApp::Mailer
10
10
  # def signup_notification(recipient)
11
11
  # mail(
12
- # :to => recipient.email,
13
- # :from => 'sender@test.test',
14
- # :subject => 'Test Message'
12
+ # to: recipient.email,
13
+ # from: 'sender@test.test',
14
+ # subject: 'Test Message'
15
15
  # )
16
16
  # end
17
17
  # end
@@ -25,17 +25,21 @@
25
25
  #
26
26
  # request = Notifier.signup_notification(user) # creates PostageApp::Request object
27
27
  # response = request.deliver # attempts to deliver the message and creates a PostageApp::Response
28
- #
28
+
29
29
  class PostageApp::Mailer < ActionMailer::Base
30
+ CONTENT_TYPE_MAP = {
31
+ 'html' => 'text/html',
32
+ 'text' => 'text/plain'
33
+ }
30
34
 
31
35
  # Wrapper for creating attachments
32
36
  # Attachments sent to PostageApp are in the following format:
33
37
  # 'filename.ext' => {
34
- # 'content_type' => 'content/type',
35
- # 'content' => 'base64_encoded_content'
38
+ # content_type: 'content/type',
39
+ # content: 'base64_encoded_content'
36
40
  # }
37
- class Attachments < Hash
38
41
 
42
+ class Attachments < Hash
39
43
  def initialize(message)
40
44
  @_message = message
41
45
  message.arguments['attachments'] ||= { }
@@ -43,16 +47,19 @@ class PostageApp::Mailer < ActionMailer::Base
43
47
 
44
48
  def []=(filename, attachment)
45
49
  default_content_type = MIME::Types.type_for(filename).first.content_type rescue ''
46
- if attachment.is_a?(Hash)
47
- content_type = attachment[:content_type] || default_content_type
48
- content = Base64.encode64(attachment[:body])
50
+
51
+ case (attachment)
52
+ when Hash
53
+ content_type = attachment[:content_type] || default_content_type
54
+ content = Base64.encode64(attachment[:body])
49
55
  else
50
- content_type = default_content_type
51
- content = Base64.encode64(attachment)
56
+ content_type = default_content_type
57
+ content = Base64.encode64(attachment)
52
58
  end
59
+
53
60
  @_message.arguments['attachments'][filename] = {
54
- 'content_type' => content_type,
55
- 'content' => content
61
+ 'content_type' => content_type,
62
+ 'content' => content
56
63
  }
57
64
  end
58
65
  end
@@ -60,28 +67,48 @@ class PostageApp::Mailer < ActionMailer::Base
60
67
  # Instead of initializing Mail object, we prepare PostageApp::Request
61
68
  def initialize(method_name = nil, *args)
62
69
  super()
70
+
63
71
  @_message = PostageApp::Request.new(:send_message)
64
- process(method_name, *args) if method_name
72
+
73
+ if (method_name)
74
+ process(method_name, *args)
75
+ end
65
76
  end
66
77
 
67
78
  # Possible to define custom uid. Should be sufficiently unique
68
79
  def postageapp_uid(value = nil)
69
- value ? @_message.uid = value : @_message.uid
80
+ if (value)
81
+ @_message.uid = value
82
+ else
83
+ @_message.uid
84
+ end
70
85
  end
71
86
 
72
87
  def postageapp_api_key(value = nil)
73
- value ? @_message.api_key = value : @_message.api_key
88
+ if (value)
89
+ @_message.api_key = value
90
+ else
91
+ @_message.api_key
92
+ end
74
93
  end
75
94
 
76
95
  # In API call we can specify PostageApp template that will be used
77
96
  # to generate content of the message
78
97
  def postageapp_template(value = nil)
79
- value ? @_message.arguments['template'] = value : @_message.arguments['template']
98
+ if (value)
99
+ @_message.arguments['template'] = value
100
+ else
101
+ @_message.arguments['template']
102
+ end
80
103
  end
81
104
 
82
105
  # Hash of variables that will be used to inject into the content
83
106
  def postageapp_variables(value = nil)
84
- value ? @_message.arguments['variables'] = value : @_message.arguments['variables']
107
+ if (value)
108
+ @_message.arguments['variables'] = value
109
+ else
110
+ @_message.arguments['variables']
111
+ end
85
112
  end
86
113
 
87
114
  def attachments
@@ -89,13 +116,13 @@ class PostageApp::Mailer < ActionMailer::Base
89
116
  end
90
117
 
91
118
  # Override for headers assignment
92
- def headers(args=nil)
119
+ def headers(args = nil)
93
120
  @_message.headers(args)
94
121
  end
95
122
 
96
123
  # Overriding method that prepares Mail object. This time we'll be
97
124
  # contructing PostageApp::Request payload.
98
- def mail(headers = {}, &block)
125
+ def mail(headers = { }, &block)
99
126
  # Guard flag to prevent both the old and the new API from firing
100
127
  # Should be removed when old API is removed
101
128
  @_mail_was_called = true
@@ -117,13 +144,23 @@ class PostageApp::Mailer < ActionMailer::Base
117
144
  charset = headers[:charset]
118
145
 
119
146
  # Set configure delivery behavior
120
- wrap_delivery_behavior!(headers.delete(:delivery_method),headers.delete(:delivery_method_options))
147
+ wrap_delivery_behavior!(
148
+ headers.delete(:delivery_method),
149
+ headers.delete(:delivery_method_options)
150
+ )
121
151
 
122
152
  # Assigning recipients
123
153
  m.arguments['recipients'] = headers.delete(:to)
124
154
 
125
155
  # Assign all headers except parts_order, content_type and body
126
- assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
156
+ assignable = headers.except(
157
+ :parts_order,
158
+ :content_type,
159
+ :body,
160
+ :template_name,
161
+ :template_path
162
+ )
163
+
127
164
  m.headers.merge!(assignable)
128
165
 
129
166
  # Render the templates and blocks
@@ -134,34 +171,29 @@ class PostageApp::Mailer < ActionMailer::Base
134
171
  end
135
172
 
136
173
  protected
137
-
138
174
  def each_template(paths, name, &block) #:nodoc:
139
175
  templates = lookup_context.find_all(name, paths)
140
- if templates.present?
176
+
177
+ if (templates.present?)
141
178
  templates.uniq { |t| t.formats }.each(&block)
142
179
  end
143
180
  end
144
181
 
145
182
  def create_parts_from_responses(m, responses) #:nodoc:
146
- map = {
147
- 'html' => 'text/html',
148
- 'text' => 'text/plain'
149
- }
150
- content = m.arguments['content'] ||= {}
183
+ content = m.arguments['content'] ||= { }
184
+
151
185
  responses.each do |part|
152
- content_type = map[part[:content_type]] || part[:content_type]
186
+ content_type = CONTENT_TYPE_MAP[part[:content_type]] || part[:content_type]
153
187
  content[content_type] = part[:body]
154
188
  end
155
189
  end
156
-
157
190
  end
158
191
 
159
192
  # A set of methods that are useful when request needs to behave as Mail
160
193
  class PostageApp::Request
161
-
162
- attr_accessor :delivery_handler,
163
- :perform_deliveries,
164
- :raise_delivery_errors
194
+ attr_accessor :delivery_handler
195
+ attr_accessor :perform_deliveries
196
+ attr_accessor :raise_delivery_errors
165
197
 
166
198
  def inform_interceptors
167
199
  Mail.inform_interceptors(self)
@@ -171,8 +203,9 @@ class PostageApp::Request
171
203
  # Probably not the best way as we're skipping way too many intermediate methods
172
204
  def deliver
173
205
  inform_interceptors
174
- if perform_deliveries
175
- if @delivery_method == Mail::TestMailer
206
+
207
+ if (perform_deliveries)
208
+ if (@delivery_method == Mail::TestMailer)
176
209
  @delivery_method.deliveries << self
177
210
  else
178
211
  self.send
@@ -181,8 +214,7 @@ class PostageApp::Request
181
214
  end
182
215
 
183
216
  # Not 100% on this, but I need to assign this so I can properly handle deliver method
184
- def delivery_method(method = nil, settings = {})
217
+ def delivery_method(method = nil, settings = nil)
185
218
  @delivery_method = method
186
219
  end
187
-
188
220
  end