ar_mailer_revised 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e31b96ff2c52c7ea6de5612eaf78aaac96f0c848
4
- data.tar.gz: 8bee7faa04dd6dc0b6e873fd8c54d9bd6f2832b9
3
+ metadata.gz: 03b52bdd415b8935da01f8f64f5635861733ebd3
4
+ data.tar.gz: c95fdf08080ad676f99d1c62e9ee4eee27668011
5
5
  SHA512:
6
- metadata.gz: e2c952822e0eef6031bcb68d4441dc8dbc50c8940f04390c9dcffa59fd3a7c1bc4f456e8b0252cb6e646a136489b8cf0a8fd2f4cac699fa7e496d1108d9ebe5d
7
- data.tar.gz: 09de5500a627fb78d1259476b458d17c5a62629e6e472700be4c736491a071b706beef0a849d9fdee269b385bbe25e8d686b3ba3b96bf32bd5d7c2be779cbd95
6
+ metadata.gz: 09a63f87e618d4279a869cba103058b9560476d3bad0b9d7d8fa6cfbc6ddd5fef533a2f151ee58fe55060f29bfb42356e9762cdc26335bf81a4c9f9b7bc0c67d
7
+ data.tar.gz: 806906086e593191fab222b53c708d30ed0a87913d3de18283695ad18e2d989f870e8d1cbae1bcf0d1fbbf793e1465d6234414651bd3b393c15c3c0156571a07
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
+ **Important**: The Rails 4 Gem Versions are **1.x**
2
+
1
3
  # ArMailerRevised
2
4
 
3
- [![Gem Version](https://badge.fury.io/rb/ar_mailer_revised.svg)](http://badge.fury.io/rb/ar_mailer_revised)
4
5
  [![Code Climate](https://codeclimate.com/github/Stex/ar_mailer_revised.png)](https://codeclimate.com/github/Stex/ar_mailer_revised)
5
6
  [![Build Status](https://travis-ci.org/Stex/ar_mailer_revised.svg?branch=rails_4)](https://travis-ci.org/Stex/ar_mailer_revised)
6
7
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.version = ArMailerRevised::VERSION
10
10
  spec.authors = ['Stefan Exner']
11
11
  spec.email = ['stex@sterex.de']
12
- spec.description = %q{Extension of the great ArMailer gem by Eric Hodel.}
12
+ spec.description = %q{Allows Batch-Sending emails in Ruby on Rails applications including delayed emails and custom SMTP settings per email}
13
13
  spec.summary = 'Batch email sending for rails applications'
14
14
  spec.homepage = 'http://www.github.com/stex/ar_mailer_revised'
15
15
  spec.license = 'MIT'
@@ -23,14 +23,14 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rake', '~> 10.3'
24
24
  spec.add_development_dependency 'yard', '~> 0.8'
25
25
  spec.add_development_dependency 'redcarpet', '~> 2.3'
26
- spec.add_development_dependency 'sqlite3'
27
- spec.add_development_dependency 'minitest'
28
- spec.add_development_dependency 'shoulda'
29
- spec.add_development_dependency 'mailcatcher'
26
+ spec.add_development_dependency 'sqlite3', '~> 1'
27
+ spec.add_development_dependency 'minitest', '~> 5.3'
28
+ spec.add_development_dependency 'shoulda', '~> 3.5'
29
+ spec.add_development_dependency 'mailcatcher', '~> 0.2'
30
30
 
31
31
  spec.add_dependency 'rails', '~> 4'
32
- spec.add_dependency 'log4r'
33
- spec.add_dependency 'hirb'
32
+ spec.add_dependency 'log4r', '~> 1'
33
+ spec.add_dependency 'hirb', '~> 0'
34
34
 
35
35
  spec.required_ruby_version = '~> 2'
36
36
  end
@@ -67,7 +67,7 @@ module ArMailerRevised
67
67
  options = {}
68
68
  options[:chdir] = '.'
69
69
  options[:max_age] = 86400 * 7
70
- options[:rails_env] = ENV['RAILS_ENV']
70
+ options[:rails_env] = ENV['RAILS_ENV'] || 'production'
71
71
  options[:log_level] = 'info'
72
72
  options[:verbose] = false
73
73
 
@@ -24,9 +24,7 @@ module ArMailerRevised
24
24
  end
25
25
 
26
26
  def run
27
- logger.debug 'ArMailerRevised initialized with the following options:'
28
- logger.debug Hirb::Helpers::AutoTable.render @options
29
-
27
+ logger.debug "ArMailerRevised initialized with the following options:\n" + Hirb::Helpers::AutoTable.render(@options)
30
28
  deliver_emails
31
29
  end
32
30
 
@@ -58,7 +56,6 @@ module ArMailerRevised
58
56
  group_emails_by_settings(emails).each do |settings_hash, grouped_emails|
59
57
  setting = OpenStruct.new(settings_hash)
60
58
  logger.info "Using setting #{setting.address}:#{setting.port}/#{setting.user_name}"
61
- logger.info setting.inspect
62
59
 
63
60
  smtp = Net::SMTP.new(setting.address, setting.port)
64
61
  smtp.open_timeout = 10
@@ -85,10 +82,10 @@ module ArMailerRevised
85
82
  #TODO: Should we remove the custom SMTP settings here as well?
86
83
  logger.warn 'Other SMTP error, trying again next batch.'
87
84
  logger.warn 'Complete Error: ' + e.to_s
85
+ rescue OpenSSL::SSL::SSLError => e
86
+ handle_ssl_error(setting, e, grouped_emails)
88
87
  rescue Exception => e
89
- logger.warn 'Other Error, trying again next batch.'
90
- logger.warn 'Complete Error: ' + e.to_s
91
- puts e.backtrace
88
+ handle_other_exception(setting, e, grouped_emails)
92
89
  end
93
90
  end
94
91
  end
@@ -138,14 +135,37 @@ module ArMailerRevised
138
135
  def setup_tls(smtp, setting)
139
136
  if setting.enable_starttls_auto
140
137
  logger.debug 'Using STARTTLS, if the server accepts it'
141
- smtp.enable_starttls_auto
138
+ smtp.enable_starttls_auto(build_ssl_context(setting))
142
139
  elsif setting.enable_starttls
143
140
  logger.debug 'Forcing STARTTLS'
144
- smtp.enable_starttls
141
+ smtp.enable_starttls(build_ssl_context(setting))
145
142
  elsif setting.tls
146
143
  logger.debug 'Forcing TLS'
147
- smtp.enable_tls
144
+ smtp.enable_tls(build_ssl_context(setting))
145
+ else
146
+ logger.debug 'Disabling TLS'
147
+ smtp.disable_tls
148
+ end
149
+ end
150
+
151
+ #
152
+ # @return [Boolean] +true+ if TLS is used in any kind (STARTLS auto, STARTLS or TLS)
153
+ #
154
+ def use_tls?(setting)
155
+ setting.enable_starttls_auto || setting.enable_starttls || setting.enable_tls
156
+ end
157
+
158
+ #
159
+ # Builds an SSL context to be used if TLS is enabled for the given setting
160
+ # At the moment it only sets the chosen verify_mode, but it might be extended later.
161
+ #
162
+ def build_ssl_context(setting)
163
+ c = OpenSSL::SSL::SSLContext.new
164
+ if use_tls?(setting)
165
+ logger.debug "Using SSL verify mode: #{setting.openssl_verify_mode}"
166
+ c.verify_mode = setting.openssl_verify_mode
148
167
  end
168
+ c
149
169
  end
150
170
 
151
171
  #
@@ -221,6 +241,18 @@ module ArMailerRevised
221
241
  end
222
242
  end
223
243
 
244
+ #
245
+ # Handles SSL errors (mostly invalid certificates)
246
+ # @see #handle_smtp_timeout
247
+ #
248
+ # Custom SMTP settings will be deleted and the default server will be used.
249
+ #
250
+ def handle_ssl_error(setting, exception, emails)
251
+ logger.warn "SSL error while connecting to '#{setting.address}:#{setting.port}'"
252
+ logger.warn 'Complete Error: ' + exception.to_s
253
+ handle_custom_setting_removal(setting, emails)
254
+ end
255
+
224
256
  #
225
257
  # Handles authentication errors occuring while connecting to an SMTP server.
226
258
  # @see #handle_smtp_timeout
@@ -229,35 +261,50 @@ module ArMailerRevised
229
261
  # as it isn't very likely that time will solve the error.
230
262
  #
231
263
  def handle_smtp_authentication_error(setting, exception, emails)
232
- logger.warn "SMTP authentication error while connecting to '#{setting.host}:#{setting.port}'"
264
+ logger.warn "SMTP authentication error while connecting to '#{setting.address}:#{setting.port}'"
233
265
  logger.warn 'Complete Error: ' + exception.to_s
234
-
235
- if setting.custom_setting
236
- logger.warn 'Setting default SMTP settings for all affected emails, they will be sent next batch.'
237
- emails.each { |email| remove_custom_smtp_settings!(email) }
238
- else
239
- logger.error "Your application's base setting ('#{setting.host}:#{setting.port}') produced an authentication error!"
240
- emails.each { |email| adjust_last_send_attempt!(email) }
241
- end
266
+ handle_custom_setting_removal(setting, emails)
242
267
  end
243
268
 
269
+ #
270
+ # Handles SMTP syntax errors.
271
+ # @see #handle_smtp_timeout
272
+ #
244
273
  def handle_smtp_syntax_error(setting, exception, emails)
245
274
  logger.warn "SMTP syntax error while connecting to '#{setting.host}:#{setting.port}'"
246
275
  logger.warn 'Complete Error: ' + exception.to_s
276
+ handle_custom_setting_removal(setting, emails)
277
+ end
278
+
279
+ #
280
+ # Handles other errors occuring while sending the email
281
+ # Custom settings are removed here as well as the gem itself
282
+ # most likely has to be altered to send these emails out using
283
+ # the custom settings - which might take a while.
284
+ #
285
+ def handle_other_exception(setting, exception, emails)
286
+ logger.warn "Other error while connecting to '#{setting.host}:#{setting.port}'"
287
+ logger.warn "Complete Error (#{exception.class.to_s}): " + exception.to_s
288
+ handle_custom_setting_removal(setting, emails)
289
+ end
290
+
291
+ #----------------------------------------------------------------
292
+ # Email Record Alteration
293
+ #----------------------------------------------------------------
247
294
 
295
+ #
296
+ # Removes custom settings for all given emails
297
+ #
298
+ def handle_custom_setting_removal(setting, emails)
248
299
  if setting.custom_setting
249
300
  logger.warn 'Setting default SMTP settings for all affected emails, they will be sent next batch.'
250
301
  emails.each { |email| remove_custom_smtp_settings!(email) }
251
302
  else
252
303
  emails.each { |email| adjust_last_send_attempt!(email) }
253
- logger.error "Your application's base setting ('#{setting.host}:#{setting.port}') produced a syntax error!"
304
+ logger.error "Your application's base setting ('#{setting.host}:#{setting.port}') produced an error!"
254
305
  end
255
306
  end
256
307
 
257
- #----------------------------------------------------------------
258
- # Email Record Alteration
259
- #----------------------------------------------------------------
260
-
261
308
  #
262
309
  # Adjusts the last send attempt timestamp in the given
263
310
  # email to the current time.
@@ -1,3 +1,3 @@
1
1
  module ArMailerRevised
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_mailer_revised
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Exner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-14 00:00:00.000000000 Z
11
+ date: 2014-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,58 +70,58 @@ dependencies:
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: minitest
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '5.3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '5.3'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: shoulda
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '3.5'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '3.5'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: mailcatcher
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '0.2'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '0.2'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rails
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -140,31 +140,32 @@ dependencies:
140
140
  name: log4r
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '1'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: '1'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: hirb
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description: Extension of the great ArMailer gem by Eric Hodel.
167
+ description: Allows Batch-Sending emails in Ruby on Rails applications including delayed
168
+ emails and custom SMTP settings per email
168
169
  email:
169
170
  - stex@sterex.de
170
171
  executables: