dvdplm-ar_mailer 2.1.1 → 2.1.2

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.
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = reason for fork
2
- The purpose of this fork is to keep an archive of sent/unsent emails.
2
+ The purpose of this fork is to keep an archive of sent/unsent emails. The archive is kept for 30 days by default, but can be configured to use any timeperiod by using the --max-archive-age switch.
3
3
 
4
- The Email class (or whatever you prefer to call it) in this for has different attributes.
4
+ The Email class (or whatever you prefer to call it) in this fork has different attributes than the original.
5
5
 
6
6
  = ar_mailer
7
7
 
data/Rakefile CHANGED
@@ -11,9 +11,9 @@ ar_mailer_gemspec = Gem::Specification.new do |s|
11
11
  s.name = %q{ar_mailer}
12
12
  s.version = ActionMailer::ARSendmail::VERSION
13
13
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
14
- s.authors = ["Eric Hodel", "Adam Meehan"]
14
+ s.authors = ["Eric Hodel", "Adam Meehan", 'David Palm']
15
15
  s.default_executable = %q{ar_sendmail}
16
- s.description = %q{Even delivering email to the local machine may take too long when you have to send hundreds of messages. ar_mailer allows you to store messages into the database for later delivery by a separate process, ar_sendmail.}
16
+ s.description = %q{Even delivering email to the local machine may take too long when you have to send hundreds of messages. ar_mailer allows you to store messages into the database for later delivery by a separate process, ar_sendmail. This fork stores the email in the database for easy inspection and tracking.}
17
17
  s.email = %q{adam.meehan@gmail.com}
18
18
  s.executables = ["ar_sendmail"]
19
19
  s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.rdoc"]
@@ -23,7 +23,7 @@ ar_mailer_gemspec = Gem::Specification.new do |s|
23
23
  s.rdoc_options = ["--main", "README.rdoc"]
24
24
  s.require_paths = ["lib"]
25
25
  s.rubyforge_project = %q{seattlerb}
26
- s.summary = %q{A two-phase delivery agent for ActionMailer}
26
+ s.summary = %q{A two-phase delivery agent and outbox archive for ActionMailer}
27
27
  s.test_files = ["test/test_armailer.rb", "test/test_arsendmail.rb"]
28
28
  end
29
29
 
@@ -46,7 +46,7 @@ class ActionMailer::ARSendmail
46
46
  ##
47
47
  # The version of ActionMailer::ARSendmail you are running.
48
48
 
49
- VERSION = '2.1'
49
+ VERSION = '2.1.2'
50
50
 
51
51
  ##
52
52
  # Maximum number of times authentication will be consecutively retried
@@ -64,9 +64,14 @@ class ActionMailer::ARSendmail
64
64
  attr_accessor :delay
65
65
 
66
66
  ##
67
- # Maximum age of emails in seconds before they are removed from the queue.
67
+ # Maximum age of unsent emails in seconds before they are removed from the queue.
68
68
 
69
- attr_accessor :max_age
69
+ attr_accessor :max_retry_age
70
+
71
+ ##
72
+ # Maximum age of sent emails in days before they are removed from the archive altogether.
73
+
74
+ attr_accessor :max_archive_age
70
75
 
71
76
  ##
72
77
  # Be verbose
@@ -213,7 +218,8 @@ EOF
213
218
  options[:Chdir] = '.'
214
219
  options[:Daemon] = false
215
220
  options[:Delay] = 60
216
- options[:MaxAge] = 86400 * 7
221
+ options[:MaxRetryAge] = 86400 * 7
222
+ options[:MaxArchiveAge] = 30
217
223
  options[:Once] = false
218
224
  options[:RailsEnv] = ENV['RAILS_ENV']
219
225
  options[:TableName] = 'Email'
@@ -244,12 +250,20 @@ EOF
244
250
  options[:Delay] = delay
245
251
  end
246
252
 
247
- opts.on( "--max-age MAX_AGE",
248
- "Maxmimum age for an email. After this",
253
+ opts.on( "--max-retry-age MAX_RETRY_AGE",
254
+ "Maxmimum age for an unsent email. After this",
255
+ "we will not try to send it anymore and ",
249
256
  "it will be removed from the queue.",
250
257
  "Set to 0 to disable queue cleanup.",
251
- "Default: #{options[:MaxAge]} seconds", Integer) do |max_age|
252
- options[:MaxAge] = max_age
258
+ "Default: #{options[:MaxRetryAge]} seconds", Integer) do |max_retry_age|
259
+ options[:MaxRetryAge] = max_retry_age
260
+ end
261
+
262
+ opts.on( "--max-archive-age MAX_ARCHIVE_AGE",
263
+ "Keep sent emails for this number of ",
264
+ "days, after which they are deleted.",
265
+ "Default: #{options[:MaxArchiveAge]} days", Integer) do |max_archive_age|
266
+ options[:MaxArchiveAge] = max_archive_age
253
267
  end
254
268
 
255
269
  opts.on("-o", "--once",
@@ -426,31 +440,45 @@ EOF
426
440
  # <tt>:Verbose</tt>:: Be verbose.
427
441
 
428
442
  def initialize(options = {})
429
- options[:Delay] ||= 60
430
- options[:TableName] ||= 'Email'
431
- options[:MaxAge] ||= 86400 * 7
432
-
433
- @batch_size = options[:BatchSize]
434
- @delay = options[:Delay]
435
- @email_class = options[:TableName].constantize
436
- @once = options[:Once]
437
- @verbose = options[:Verbose]
438
- @max_age = options[:MaxAge]
443
+ options[:Delay] ||= 60
444
+ options[:TableName] ||= 'Email'
445
+ options[:MaxRetryAge] ||= 86400 * 7
446
+ options[:MaxArchiveAge] ||= 30
447
+
448
+ @batch_size = options[:BatchSize]
449
+ @delay = options[:Delay]
450
+ @email_class = options[:TableName].constantize
451
+ @once = options[:Once]
452
+ @verbose = options[:Verbose]
453
+ @max_retry_age = options[:MaxRetryAge]
454
+ @max_archive_age = options[:MaxArchiveAge]
439
455
 
440
456
  @failed_auth_count = 0
441
457
  end
442
458
 
459
+ def cleanup
460
+ cleanup_unsent
461
+ cleanup_old_emails
462
+ end
463
+
443
464
  ##
444
465
  # Removes unsent emails that have lived in the queue for too long.
445
- # If max_age is set to 0, no emails will be removed; max_age defaults
466
+ # If max_retry_age is set to 0, no emails will be removed; max_retry_age defaults
446
467
  # to 7 days (86400 * 7)
447
- def cleanup
448
- return if @max_age == 0
449
- timeout = Time.now - @max_age
468
+ def cleanup_unsent
469
+ return if @max_retry_age == 0
470
+ timeout = Time.now - @max_retry_age
450
471
  conditions = ['last_send_attempt > 0 AND created_at < ? AND sent_at IS NULL', timeout]
451
472
  mail = @email_class.update_all({:failed => true}, conditions)
452
473
 
453
- log "#{self.class}#cleanup expired #{mail} emails from the queue"
474
+ log "#{self.class}#cleanup_unsent expired #{mail} emails from the queue"
475
+ end
476
+
477
+ # Store 30 days worth of old emails
478
+ def cleanup_old_emails
479
+ conditions = ['sent_at < ?', @max_archive_age.days.ago.to_date]
480
+ log "#{self.class}#cleanup_old_emails Deleting #{@email_class.count(:conditions => conditions)} emails from the archive."
481
+ @email_class.delete_all(conditions)
454
482
  end
455
483
 
456
484
  ##
@@ -244,13 +244,13 @@ EOF
244
244
 
245
245
  def test_class_parse_args_max_age
246
246
  options = ActionMailer::ARSendmail.process_args []
247
- assert_equal 86400 * 7, options[:MaxAge]
247
+ assert_equal 86400 * 7, options[:MaxRetryAge]
248
248
 
249
- argv = %w[--max-age 86400]
249
+ argv = %w[--max-retry-age 86400]
250
250
 
251
251
  options = ActionMailer::ARSendmail.process_args argv
252
252
 
253
- assert_equal 86400, options[:MaxAge]
253
+ assert_equal 86400, options[:MaxRetryAge]
254
254
  end
255
255
 
256
256
  def test_class_parse_args_migration
@@ -365,7 +365,7 @@ EOF
365
365
  assert_equal "hi\n\nopts\n", err
366
366
  end
367
367
 
368
- def test_cleanup
368
+ def test_cleanup_unsent
369
369
  e1 = Email.create :mail => 'body', :to => 'to', :from => 'from'
370
370
  e1.created_at = Time.now
371
371
  e2 = Email.create :mail => 'body', :to => 'to', :from => 'from'
@@ -373,11 +373,11 @@ EOF
373
373
  e3.update_attributes(:last_send_attempt => 1.day.ago, :created_at => 3.weeks.ago, :sent_at => nil)
374
374
 
375
375
  out, err = capture_io do
376
- @sm.cleanup
376
+ @sm.cleanup_unsent
377
377
  end
378
378
 
379
379
  assert_equal "", out
380
- assert_equal "ActionMailer::ARSendmail#cleanup expired 1 emails from the queue\n", err
380
+ assert_equal "ActionMailer::ARSendmail#cleanup_unsent expired 1 emails from the queue\n", err
381
381
  assert_equal 2, Email.count(:conditions => {:failed => false})
382
382
 
383
383
  assert_equal [e1, e2], Email.all(:conditions => {:failed => false})
@@ -388,15 +388,27 @@ EOF
388
388
  e1.created_at = Time.now
389
389
  e2 = Email.create :mail => 'body', :to => 'to', :from => 'from'
390
390
 
391
- @sm.max_age = 0
391
+ @sm.max_retry_age = 0
392
392
 
393
393
  out, err = capture_io do
394
- @sm.cleanup
394
+ @sm.cleanup_unsent
395
395
  end
396
396
 
397
397
  assert_equal '', out
398
398
  assert_equal 2, Email.count
399
399
  end
400
+
401
+ def test_cleanup_old_emails
402
+ e1 = Email.create! :mail => 'body', :to => 'to', :from => 'from', :sent_at => 31.days.ago
403
+ e2 = Email.create! :mail => 'body', :to => 'to', :from => 'from', :sent_at => 29.days.ago
404
+
405
+ out, err = capture_io do
406
+ @sm.cleanup_old_emails
407
+ end
408
+
409
+ assert_equal '', out
410
+ assert_equal 1, Email.count
411
+ end
400
412
 
401
413
  def test_deliver
402
414
  pre_count = Email.count
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dvdplm-ar_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-04-17 00:00:00 -07:00
14
+ date: 2009-08-04 00:00:00 -07:00
15
15
  default_executable: ar_sendmail
16
16
  dependencies: []
17
17
 
@@ -44,6 +44,7 @@ files:
44
44
  - test/test_arsendmail.rb
45
45
  has_rdoc: true
46
46
  homepage: http://github.com/adzap/ar_mailer
47
+ licenses:
47
48
  post_install_message:
48
49
  rdoc_options:
49
50
  - --main
@@ -65,9 +66,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  requirements: []
66
67
 
67
68
  rubyforge_project: seattlerb
68
- rubygems_version: 1.2.0
69
+ rubygems_version: 1.3.5
69
70
  signing_key:
70
- specification_version: 3
71
+ specification_version: 2
71
72
  summary: A two-phase delivery agent and outbox archive for ActionMailer
72
73
  test_files:
73
74
  - test/test_armailer.rb