scambra-ar_mailer 2.1.6 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,21 @@
1
+ = 2.1.7
2
+
3
+ * Miscellaneous Updates
4
+ * Added adzap-ar_mailer file to end the need for the config.gem :lib option
5
+
6
+ * Bugs fixed
7
+ * Fix from address being set as address header object.
8
+
9
+ = 2.1.6
10
+
11
+ * Miscellaneous Updates
12
+ * Use return-path as from address if set, as per default ActionMailer::Base SMTP delivery (Dustin Tinney)
13
+ * Always wait full delay between deliveries (cyu)
14
+
15
+ * Bugs fixed
16
+ * Non-zero return code returned in init.d script (hennk)
17
+ * Use updated Timeout error class (hennk)
18
+
1
19
  = 2.1.5
2
20
 
3
21
  * Bugs fixed
@@ -21,7 +39,7 @@
21
39
  * Require ar_mailer in ar_sendmail since the change to remove TableName and use email_class
22
40
 
23
41
  = 2.1.1
24
-
42
+
25
43
  * Force gem rebuild
26
44
 
27
45
  = 2.1.0
@@ -55,7 +73,7 @@
55
73
  = 1.4.3
56
74
 
57
75
  * Bugs fixed
58
- * Replaced mistaken call to log when removing pid file artifact for
76
+ * Replaced mistaken call to log when removing pid file artifact for
59
77
  non-running daemon
60
78
 
61
79
  = 1.4.2
@@ -65,11 +83,11 @@
65
83
  config file. See files share/linux/ar_sendmail and ar_sendmail.conf
66
84
  * Bugs fixed
67
85
  * Proper handling for relative and absolute paths for the pid file
68
- * Removed hoe dependency since we need the explicit gemspec file for github and
86
+ * Removed hoe dependency since we need the explicit gemspec file for github and
69
87
  not deploying to RubyForge its not as useful.
70
- * Moved old BSD rc.d script to share/bsd folder
88
+ * Moved old BSD rc.d script to share/bsd folder
71
89
  * Updated README with github gem install, docs and init script info
72
-
90
+
73
91
  = 1.4.1
74
92
 
75
93
  * Bugs fixed
@@ -30,19 +30,17 @@ Before installing you will need to make sure the original gem is uninstalled as
30
30
 
31
31
  $ sudo gem uninstall ar_mailer
32
32
 
33
- Install the gem from GitHub gems server:
34
-
35
- First, if you haven't already:
36
-
37
- $ sudo gem sources -a http://gems.github.com
38
-
39
33
  Then
40
34
 
41
35
  $ sudo gem install adzap-ar_mailer
42
36
 
43
37
  For Rails >= 2.1, in your environment.rb:
44
-
45
- config.gem "adzap-ar_mailer", :lib => 'action_mailer/ar_mailer', :source => 'http://gems.github.com'
38
+
39
+ config.gem "adzap-ar_mailer", :lib => 'action_mailer/ar_mailer'
40
+
41
+ # or since version 2.1.7 of this gem you can now just do
42
+
43
+ config.gem "adzap-ar_mailer"
46
44
 
47
45
  For Rails 2.0, in an initializer file:
48
46
 
@@ -88,9 +86,9 @@ Or if you need to, you can set each mailer class delivery method individually:
88
86
  end
89
87
 
90
88
  This can be useful when using plugins like ExceptionNotification. Where it
91
- might be foolish to tie the sending of the email alert to the database when the
89
+ might be foolish to tie the sending of the email alert to the database when the
92
90
  database might be causing the exception being raised. In this instance you could
93
- override ExceptionNofitier delivery method to be smtp or set the other
91
+ override ExceptionNofitier delivery method to be smtp or set the other
94
92
  mailer classes to use ARMailer explicitly.
95
93
 
96
94
  Then to run it:
@@ -116,7 +114,7 @@ SMTP server supports it. If you do not want it to automatically enabled then
116
114
  set the :tls option to false in your smtp_settings.
117
115
 
118
116
  If you are on Ruby <= 1.8.6, then the TLS patch included in this plugin will
119
- be loaded, so you don't need another TLS plugin to add the capability. This
117
+ be loaded, so you don't need another TLS plugin to add the capability. This
120
118
  patch allows you to explicit set if the server supports TLS by setting the
121
119
  :tls option to true in your smtp_settings.
122
120
 
@@ -129,10 +127,10 @@ around. ar_mailer supplies it own.
129
127
 
130
128
  == Run as a service (init.d/rc.d scripts)
131
129
 
132
- For Linux both script and demo config files are in share/linux.
133
- See ar_sendmail.conf for setting up your config. Copy the ar_sendmail file
130
+ For Linux both script and demo config files are in share/linux.
131
+ See ar_sendmail.conf for setting up your config. Copy the ar_sendmail file
134
132
  to /etc/init.d/ and make it executable. Then for Debian based distros run
135
- 'sudo update-rc.d ar_sendmail defaults' and it should work. Make sure you have
133
+ 'sudo update-rc.d ar_sendmail defaults' and it should work. Make sure you have
136
134
  the config file /etc/ar_sendmail.conf in place before starting.
137
135
 
138
136
  For FreeBSD or NetBSD script is share/bsd/ar_sendmail. This is old and does not
data/Rakefile CHANGED
@@ -6,38 +6,59 @@ require 'rake/rdoctask'
6
6
  $:.unshift(File.expand_path(File.dirname(__FILE__) + '/lib'))
7
7
 
8
8
  require './lib/action_mailer/ar_sendmail'
9
-
9
+
10
10
  ar_mailer_gemspec = Gem::Specification.new do |s|
11
- s.name = %q{ar_mailer}
11
+ s.name = %q{scambra-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", "Sergio Cambra"]
15
15
  s.default_executable = %q{ar_sendmail}
16
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.}
17
- s.email = %q{adam.meehan@gmail.com}
17
+ s.email = %q{sergio@entrecables.com}
18
18
  s.executables = ["ar_sendmail"]
19
19
  s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "README.rdoc"]
20
- s.files = ["History.txt", "LICENSE.txt", "README.rdoc", "Rakefile", "bin/ar_sendmail", "generators/ar_mailer/ar_mailer_generator.rb", "generators/ar_mailer/templates/migration.rb", "generators/ar_mailer/templates/model.rb", "lib/action_mailer/ar_mailer.rb", "lib/action_mailer/ar_sendmail.rb", "lib/smtp_tls.rb", "share/bsd/ar_sendmail", "share/linux/ar_sendmail", "share/linux/ar_sendmail.conf", "test/resources/action_mailer.rb", "test/test_armailer.rb", "test/test_arsendmail.rb", "test/test_helper.rb"]
20
+ s.files = [
21
+ "History.txt",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "bin/ar_sendmail",
26
+ "generators/ar_mailer/ar_mailer_generator.rb",
27
+ "generators/ar_mailer/templates/migration.rb",
28
+ "generators/ar_mailer/templates/model.rb",
29
+ "lib/adzap-ar_mailer.rb",
30
+ "lib/action_mailer/ar_mailer.rb",
31
+ "lib/action_mailer/ar_sendmail.rb",
32
+ "lib/smtp_tls.rb",
33
+ "share/bsd/ar_sendmail",
34
+ "share/linux/ar_sendmail",
35
+ "share/linux/ar_sendmail.conf",
36
+ "test/resources/action_mailer.rb",
37
+ "test/test_armailer.rb",
38
+ "test/test_arsendmail.rb",
39
+ "test/test_helper.rb"
40
+ ]
21
41
  s.has_rdoc = true
22
- s.homepage = %q{http://github.com/adzap/ar_mailer}
42
+ s.homepage = %q{http://github.com/scambra/ar_mailer}
23
43
  s.rdoc_options = ["--main", "README.rdoc"]
24
44
  s.require_paths = ["lib"]
25
- s.rubyforge_project = %q{seattlerb}
26
45
  s.summary = %q{A two-phase delivery agent for ActionMailer}
27
46
  s.test_files = ["test/test_armailer.rb", "test/test_arsendmail.rb"]
28
- end
47
+ s.add_development_dependency "minitest", ">= 1.5.0"
48
+ s.add_development_dependency "mocha", ">= 0.9.8"
49
+ end
29
50
 
30
51
  Rake::GemPackageTask.new(ar_mailer_gemspec) do |pkg|
31
52
  pkg.gem_spec = ar_mailer_gemspec
32
53
  end
33
-
54
+
34
55
  desc "Update ar_mailer.gemspec"
35
56
  task :make_spec do
36
- File.open("ar_mailer.gemspec", "w") do |f|
57
+ File.open("adzap-ar_mailer.gemspec", "w") do |f|
37
58
  f.puts(ar_mailer_gemspec.to_ruby)
38
59
  end
39
60
  end
40
-
61
+
41
62
  desc "Build packages and install"
42
63
  task :install => :package do
43
64
  sh %{sudo gem install --local --test pkg/ar_mailer-#{ActionMailer::ARSendmail::VERSION}}
@@ -23,8 +23,9 @@ class ActionMailer::Base
23
23
  # used.
24
24
 
25
25
  def perform_delivery_activerecord(mail)
26
+ sender = (mail['return-path'] && mail['return-path'].spec) || mail.from.first
26
27
  mail.destinations.each do |destination|
27
- self.class.email_class.create :mail => mail.encoded, :to => destination, :from => mail.from.first
28
+ self.class.email_class.create :mail => mail.encoded, :to => destination, :from => sender
28
29
  end
29
30
  end
30
31
 
@@ -42,7 +42,7 @@ class ActionMailer::ARSendmail
42
42
  ##
43
43
  # The version of ActionMailer::ARSendmail you are running.
44
44
 
45
- VERSION = '2.1.5'
45
+ VERSION = '2.1.7'
46
46
 
47
47
  ##
48
48
  # Maximum number of times authentication will be consecutively retried
@@ -68,7 +68,7 @@ class ActionMailer::ARSendmail
68
68
  # Be verbose
69
69
 
70
70
  attr_accessor :verbose
71
-
71
+
72
72
 
73
73
  ##
74
74
  # True if only one delivery attempt will be made per call to run
@@ -282,7 +282,7 @@ class ActionMailer::ARSendmail
282
282
  File.open(@@pid_file, 'r') {|f| pid = f.read.chomp }
283
283
  if system("ps -p #{pid} | grep #{pid}") # returns true if process is running, o.w. false
284
284
  $stderr.puts "Warning: The pid file #{@@pid_file} exists and ar_sendmail is running. Shutting down."
285
- exit
285
+ exit -1
286
286
  else
287
287
  # not running, so remove existing pid file and continue
288
288
  self.remove_pid_file
@@ -303,7 +303,7 @@ class ActionMailer::ARSendmail
303
303
  rescue Exception => e
304
304
  $stderr.puts "Unhandled exception #{e.message}(#{e.class}):"
305
305
  $stderr.puts "\t#{e.backtrace.join "\n\t"}"
306
- exit 1
306
+ exit -2
307
307
  end
308
308
 
309
309
  ##
@@ -364,7 +364,7 @@ class ActionMailer::ARSendmail
364
364
  smtp_settings[:password],
365
365
  smtp_settings[:authentication]
366
366
  ]
367
-
367
+
368
368
  smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
369
369
  if smtp.respond_to?(:enable_starttls_auto)
370
370
  smtp.enable_starttls_auto unless smtp_settings[:tls] == false
@@ -386,14 +386,13 @@ class ActionMailer::ARSendmail
386
386
  [email.id, e.message, e.class, e.backtrace.join("\n\t")]
387
387
  email.destroy
388
388
  session.reset
389
- rescue Net::SMTPServerBusy, Net::SMTPUnknownError, Net::SMTPSyntaxError, TimeoutError => e
389
+ rescue Net::SMTPServerBusy, Net::SMTPUnknownError, Net::SMTPSyntaxError, TimeoutError, Timeout::Error => e
390
390
  email.last_send_attempt = Time.now.to_i
391
391
  email.save rescue nil
392
392
  log "error sending email %d: %p(%s):\n\t%s" %
393
393
  [email.id, e.message, e.class, e.backtrace.join("\n\t")]
394
394
  if e.is_a? Net::SMTPServerBusy
395
- log "server too busy, sleeping #{@delay} seconds"
396
- sleep delay
395
+ log "server too busy, stopping delivery cycle"
397
396
  return
398
397
  else
399
398
  session.reset
@@ -420,7 +419,7 @@ class ActionMailer::ARSendmail
420
419
  def do_exit
421
420
  log "caught signal, shutting down"
422
421
  self.class.remove_pid_file
423
- exit
422
+ exit 130
424
423
  end
425
424
 
426
425
  ##
@@ -460,7 +459,6 @@ class ActionMailer::ARSendmail
460
459
  install_signal_handlers
461
460
 
462
461
  loop do
463
- now = Time.now
464
462
  begin
465
463
  cleanup
466
464
  emails = find_emails
@@ -469,7 +467,7 @@ class ActionMailer::ARSendmail
469
467
  rescue ActiveRecord::Transactions::TransactionError
470
468
  end
471
469
  break if @once
472
- sleep @delay if now + @delay > Time.now
470
+ sleep @delay
473
471
  end
474
472
  end
475
473
 
@@ -0,0 +1 @@
1
+ require 'action_mailer/ar_mailer'
@@ -14,11 +14,11 @@ begin
14
14
  config = YAML::load(IO.read(config_file)) || {}
15
15
  if config.empty? || (config.has_key?('defaults') && config.size == 1)
16
16
  puts "No mailers defined. Exiting."
17
- exit
17
+ exit -2
18
18
  end
19
19
  rescue Errno::ENOENT
20
20
  puts "Config file not found at '#{config_file}'!"
21
- exit
21
+ exit -3
22
22
  end
23
23
 
24
24
  default_options = {'pidfile' => './log/ar_sendmail.pid'}.merge(config.delete('defaults') || {})
@@ -57,7 +57,7 @@ end
57
57
 
58
58
  def command_error(msg)
59
59
  puts msg
60
- exit
60
+ exit -1
61
61
  end
62
62
 
63
63
  if ['start', 'stop', 'restart'].include?(command)
@@ -7,6 +7,7 @@ class Mailer < ActionMailer::Base
7
7
  @mail = Object.new
8
8
  def @mail.encoded() 'email' end
9
9
  def @mail.from() ['nobody@example.com'] end
10
+ def @mail.[](key) {'return-path' => $return_path, 'from' => 'nobody@example.com'}[key] end
10
11
  def @mail.destinations() %w[user1@example.com user2@example.com] end
11
12
  end
12
13
 
@@ -15,6 +16,7 @@ end
15
16
  class TestARMailer < Test::Unit::TestCase
16
17
 
17
18
  def setup
19
+ $return_path = nil
18
20
  Mailer.email_class = Email
19
21
 
20
22
  Email.records.clear
@@ -28,6 +30,15 @@ class TestARMailer < Test::Unit::TestCase
28
30
 
29
31
  assert_equal 2, Newsletter.records.length
30
32
  end
33
+
34
+ def test_perform_delivery_activerecord_when_return_path_is_present
35
+ $return_path = stub(:spec => 'return-path@example.com')
36
+ Mailer.deliver_mail
37
+
38
+ assert_equal 2, Email.records.length
39
+ record = Email.records.first
40
+ assert_equal 'return-path@example.com', record.from
41
+ end
31
42
 
32
43
  def test_perform_delivery_activerecord
33
44
  Mailer.deliver_mail
@@ -98,19 +98,19 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
98
98
 
99
99
  def test_class_parse_args_chdir
100
100
  argv = %w[-c /tmp]
101
-
101
+
102
102
  options = ActionMailer::ARSendmail.process_args argv
103
103
 
104
104
  assert_equal '/tmp', options[:Chdir]
105
105
 
106
106
  argv = %w[--chdir /tmp]
107
-
107
+
108
108
  options = ActionMailer::ARSendmail.process_args argv
109
109
 
110
110
  assert_equal '/tmp', options[:Chdir]
111
111
 
112
112
  argv = %w[-c /nonexistent]
113
-
113
+
114
114
  out, err = capture_io do
115
115
  assert_raises SystemExit do
116
116
  ActionMailer::ARSendmail.process_args argv
@@ -120,35 +120,35 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
120
120
 
121
121
  def test_class_parse_args_daemon
122
122
  argv = %w[-d]
123
-
123
+
124
124
  options = ActionMailer::ARSendmail.process_args argv
125
125
 
126
126
  assert_equal true, options[:Daemon]
127
127
 
128
128
  argv = %w[--daemon]
129
-
129
+
130
130
  options = ActionMailer::ARSendmail.process_args argv
131
131
 
132
132
  assert_equal true, options[:Daemon]
133
133
  end
134
-
134
+
135
135
  def test_class_parse_args_pidfile
136
136
  argv = %w[-p ./log/ar_sendmail.pid]
137
-
137
+
138
138
  options = ActionMailer::ARSendmail.process_args argv
139
139
 
140
140
  assert_equal './log/ar_sendmail.pid', options[:Pidfile]
141
141
 
142
142
  argv = %w[--pidfile ./log/ar_sendmail.pid]
143
-
143
+
144
144
  options = ActionMailer::ARSendmail.process_args argv
145
145
 
146
146
  assert_equal './log/ar_sendmail.pid', options[:Pidfile]
147
147
  end
148
-
148
+
149
149
  def test_class_parse_args_delay
150
150
  argv = %w[--delay 75]
151
-
151
+
152
152
  options = ActionMailer::ARSendmail.process_args argv
153
153
 
154
154
  assert_equal 75, options[:Delay]
@@ -158,7 +158,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
158
158
  assert_equal nil, ENV['RAILS_ENV']
159
159
 
160
160
  argv = %w[-e production]
161
-
161
+
162
162
  options = ActionMailer::ARSendmail.process_args argv
163
163
 
164
164
  assert_equal 'production', options[:RailsEnv]
@@ -166,7 +166,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
166
166
  assert_equal 'production', ENV['RAILS_ENV']
167
167
 
168
168
  argv = %w[--environment production]
169
-
169
+
170
170
  options = ActionMailer::ARSendmail.process_args argv
171
171
 
172
172
  assert_equal 'production', options[:RailsEnv]
@@ -177,7 +177,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
177
177
  refute_includes options, :MailQ
178
178
 
179
179
  argv = %w[--mailq]
180
-
180
+
181
181
  options = ActionMailer::ARSendmail.process_args argv
182
182
 
183
183
  assert_equal true, options[:MailQ]
@@ -209,13 +209,13 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
209
209
 
210
210
  def test_class_parse_args_once
211
211
  argv = %w[-o]
212
-
212
+
213
213
  options = ActionMailer::ARSendmail.process_args argv
214
214
 
215
215
  assert_equal true, options[:Once]
216
216
 
217
217
  argv = %w[--once]
218
-
218
+
219
219
  options = ActionMailer::ARSendmail.process_args argv
220
220
 
221
221
  assert_equal true, options[:Once]
@@ -420,31 +420,6 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
420
420
  assert_equal '', err
421
421
  end
422
422
 
423
- def test_deliver_server_busy
424
- Net::SMTP.on_send_message do
425
- e = Net::SMTPServerBusy.new 'try again'
426
- e.set_backtrace %w[one two three]
427
- raise e
428
- end
429
-
430
- now = Time.now.to_i
431
-
432
- email = Email.create :mail => 'body', :to => 'to', :from => 'from'
433
-
434
- out, err = capture_io do
435
- @sm.deliver [email]
436
- end
437
-
438
- assert_equal 0, Net::SMTP.deliveries.length
439
- assert_equal 1, Email.records.length
440
- assert_operator now, :>=, Email.records.first.last_send_attempt
441
- assert_equal 0, Net::SMTP.reset_called, 'Reset connection on SyntaxError'
442
- assert_equal [60], @sm.slept
443
-
444
- assert_equal '', out
445
- assert_equal "server too busy, sleeping 60 seconds\n", err
446
- end
447
-
448
423
  def test_deliver_syntax_error
449
424
  Net::SMTP.on_send_message do
450
425
  Net::SMTP.on_send_message # clear
metadata CHANGED
@@ -1,20 +1,39 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scambra-ar_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
- - Sergio Cambra
8
7
  - Eric Hodel
9
8
  - Adam Meehan
9
+ - Sergio Cambra
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-10-19 00:00:00 +02:00
14
+ date: 2010-01-19 00:00:00 +01:00
15
15
  default_executable: ar_sendmail
16
- dependencies: []
17
-
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: minitest
19
+ type: :development
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.5.0
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
29
+ type: :development
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.9.8
36
+ version:
18
37
  description: 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.
19
38
  email: sergio@entrecables.com
20
39
  executables:
@@ -34,6 +53,7 @@ files:
34
53
  - generators/ar_mailer/ar_mailer_generator.rb
35
54
  - generators/ar_mailer/templates/migration.rb
36
55
  - generators/ar_mailer/templates/model.rb
56
+ - lib/adzap-ar_mailer.rb
37
57
  - lib/action_mailer/ar_mailer.rb
38
58
  - lib/action_mailer/ar_sendmail.rb
39
59
  - lib/smtp_tls.rb