ar_mailer 1.4.0 → 1.5.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.
- data.tar.gz.sig +0 -0
- data/.autotest +6 -0
- data/History.txt +5 -0
- data/Manifest.txt +1 -0
- data/lib/action_mailer/ar_sendmail.rb +63 -10
- data/test/test_arsendmail.rb +87 -1
- metadata +5 -4
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
|
Binary file
|
data/.autotest
ADDED
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
|
@@ -54,7 +54,7 @@ class ActionMailer::ARSendmail
|
|
|
54
54
|
##
|
|
55
55
|
# The version of ActionMailer::ARSendmail you are running.
|
|
56
56
|
|
|
57
|
-
VERSION = '1.
|
|
57
|
+
VERSION = '1.5.0'
|
|
58
58
|
|
|
59
59
|
##
|
|
60
60
|
# Maximum number of times authentication will be consecutively retried
|
|
@@ -96,6 +96,26 @@ class ActionMailer::ARSendmail
|
|
|
96
96
|
|
|
97
97
|
attr_accessor :failed_auth_count
|
|
98
98
|
|
|
99
|
+
##
|
|
100
|
+
# Checks and writes +pid_file+, aborting if it already exists or this
|
|
101
|
+
# process loses the pid-writing race.
|
|
102
|
+
|
|
103
|
+
def self.check_pid(pid_file)
|
|
104
|
+
if File.exist? pid_file then
|
|
105
|
+
abort "pid file exists at #{pid_file}, exiting"
|
|
106
|
+
else
|
|
107
|
+
open pid_file, 'w', 0644 do |io|
|
|
108
|
+
io.write $$
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
written_pid = File.read pid_file
|
|
112
|
+
|
|
113
|
+
if written_pid.to_i != $$ then
|
|
114
|
+
abort "pid #{written_pid} from #{pid_file} doesn't match $$ #{$$}, exiting"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
99
119
|
##
|
|
100
120
|
# Creates a new migration using +table_name+ and prints it on stdout.
|
|
101
121
|
|
|
@@ -193,13 +213,21 @@ end
|
|
|
193
213
|
options[:TableName] = 'Email'
|
|
194
214
|
|
|
195
215
|
op = OptionParser.new do |opts|
|
|
196
|
-
opts.
|
|
197
|
-
opts.
|
|
216
|
+
opts.program_name = name
|
|
217
|
+
opts.version = VERSION
|
|
198
218
|
|
|
199
|
-
opts.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
219
|
+
opts.banner = <<-BANNER
|
|
220
|
+
Usage: #{name} [options]
|
|
221
|
+
|
|
222
|
+
#{name} scans the email table for new messages and sends them to the
|
|
223
|
+
website's configured SMTP host.
|
|
224
|
+
|
|
225
|
+
#{name} must be run from a Rails application's root or have it specified
|
|
226
|
+
with --chdir.
|
|
227
|
+
|
|
228
|
+
If #{name} is started with --pid-file, it will fail to start if the PID
|
|
229
|
+
file already exists or the contents don't match it's PID.
|
|
230
|
+
BANNER
|
|
203
231
|
|
|
204
232
|
opts.separator ''
|
|
205
233
|
opts.separator 'Sendmail options:'
|
|
@@ -231,6 +259,20 @@ end
|
|
|
231
259
|
options[:Once] = once
|
|
232
260
|
end
|
|
233
261
|
|
|
262
|
+
opts.on("-p", "--pid-file [PATH]",
|
|
263
|
+
"File to store the pid in.",
|
|
264
|
+
"Defaults to /var/run/ar_sendmail.pid",
|
|
265
|
+
"when no path is given") do |pid_file|
|
|
266
|
+
pid_file ||= '/var/run/ar_sendmail/ar_sendmail.pid'
|
|
267
|
+
|
|
268
|
+
pid_dir = File.dirname pid_file
|
|
269
|
+
raise OptionParser::InvalidArgument,
|
|
270
|
+
"directory #{pid_dir} does not exist" unless
|
|
271
|
+
File.directory? pid_dir
|
|
272
|
+
|
|
273
|
+
options[:PidFile] = pid_file
|
|
274
|
+
end
|
|
275
|
+
|
|
234
276
|
opts.on("-d", "--daemonize",
|
|
235
277
|
"Run as a daemon process",
|
|
236
278
|
"Default: #{options[:Daemon]}") do |daemon|
|
|
@@ -308,6 +350,7 @@ end
|
|
|
308
350
|
rescue LoadError
|
|
309
351
|
usage op, <<-EOF
|
|
310
352
|
#{name} must be run from a Rails application's root to deliver email.
|
|
353
|
+
|
|
311
354
|
#{Dir.pwd} does not appear to be a Rails application root.
|
|
312
355
|
EOF
|
|
313
356
|
end
|
|
@@ -338,7 +381,16 @@ end
|
|
|
338
381
|
WEBrick::Daemon.start
|
|
339
382
|
end
|
|
340
383
|
|
|
341
|
-
new
|
|
384
|
+
sendmail = new options
|
|
385
|
+
|
|
386
|
+
check_pid options[:PidFile] if options.key? :PidFile
|
|
387
|
+
|
|
388
|
+
begin
|
|
389
|
+
sendmail.run
|
|
390
|
+
ensure
|
|
391
|
+
File.unlink options[:PidFile] if
|
|
392
|
+
options.key? :PidFile and $PID == File.read(options[:PidFile]).to_i
|
|
393
|
+
end
|
|
342
394
|
|
|
343
395
|
rescue SystemExit
|
|
344
396
|
raise
|
|
@@ -354,12 +406,13 @@ end
|
|
|
354
406
|
# Prints a usage message to $stderr using +opts+ and exits
|
|
355
407
|
|
|
356
408
|
def self.usage(opts, message = nil)
|
|
409
|
+
$stderr.puts opts
|
|
410
|
+
|
|
357
411
|
if message then
|
|
358
|
-
$stderr.puts message
|
|
359
412
|
$stderr.puts
|
|
413
|
+
$stderr.puts message
|
|
360
414
|
end
|
|
361
415
|
|
|
362
|
-
$stderr.puts opts
|
|
363
416
|
exit 1
|
|
364
417
|
end
|
|
365
418
|
|
data/test/test_arsendmail.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'tmpdir'
|
|
1
2
|
require 'action_mailer'
|
|
2
3
|
require 'action_mailer/ar_sendmail'
|
|
3
4
|
require 'rubygems'
|
|
@@ -23,10 +24,64 @@ class TestARSendmail < MiniTest::Unit::TestCase
|
|
|
23
24
|
|
|
24
25
|
@include_c_e = ! $".grep(/config\/environment.rb/).empty?
|
|
25
26
|
$" << 'config/environment.rb' unless @include_c_e
|
|
27
|
+
|
|
28
|
+
@pid_file = File.join Dir.tmpdir, "test_#{$$}_ar_sendmail.pid"
|
|
26
29
|
end
|
|
27
30
|
|
|
28
31
|
def teardown
|
|
29
32
|
$".delete 'config/environment.rb' unless @include_c_e
|
|
33
|
+
|
|
34
|
+
File.unlink @pid_file if File.exist? @pid_file
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_class_check_pid
|
|
38
|
+
ActionMailer::ARSendmail.check_pid @pid_file
|
|
39
|
+
|
|
40
|
+
assert File.exist?(@pid_file)
|
|
41
|
+
|
|
42
|
+
assert_equal $$, File.read(@pid_file).to_i
|
|
43
|
+
rescue SystemExit
|
|
44
|
+
flunk 'pid file teardown failed'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_class_check_pid_exists
|
|
48
|
+
ActionMailer::ARSendmail.check_pid @pid_file
|
|
49
|
+
|
|
50
|
+
out, err = capture_io do
|
|
51
|
+
assert_raises SystemExit do
|
|
52
|
+
ActionMailer::ARSendmail.check_pid @pid_file
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
assert_equal '', out
|
|
57
|
+
assert_equal "pid file exists at #{@pid_file}, exiting\n", err
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_class_check_pid_no_match
|
|
61
|
+
def (ActionMailer::ARSendmail).open(path, mode, perm)
|
|
62
|
+
fake_io = Object.new
|
|
63
|
+
def fake_io.write(data) end
|
|
64
|
+
|
|
65
|
+
File.open path, mode, perm do |io|
|
|
66
|
+
yield fake_io
|
|
67
|
+
|
|
68
|
+
io.write 0
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
out, err = capture_io do
|
|
73
|
+
assert_raises SystemExit do
|
|
74
|
+
ActionMailer::ARSendmail.check_pid @pid_file
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
assert_equal '', out
|
|
79
|
+
assert_equal "pid 0 from #{@pid_file} doesn't match $$ #{$$}, exiting\n",
|
|
80
|
+
err
|
|
81
|
+
ensure
|
|
82
|
+
class << ActionMailer::ARSendmail
|
|
83
|
+
send :remove_method, :open
|
|
84
|
+
end
|
|
30
85
|
end
|
|
31
86
|
|
|
32
87
|
def test_class_create_migration
|
|
@@ -300,6 +355,37 @@ Last send attempt: Thu Aug 10 11:40:05 2006
|
|
|
300
355
|
assert_equal true, options[:Once]
|
|
301
356
|
end
|
|
302
357
|
|
|
358
|
+
def test_class_parse_args_pid_file
|
|
359
|
+
argv = %w[]
|
|
360
|
+
|
|
361
|
+
options = ActionMailer::ARSendmail.process_args argv
|
|
362
|
+
|
|
363
|
+
refute options.key?(:PidFile), 'no --pid-file option'
|
|
364
|
+
|
|
365
|
+
argv = %w[--pid-file]
|
|
366
|
+
|
|
367
|
+
options = ActionMailer::ARSendmail.process_args argv
|
|
368
|
+
|
|
369
|
+
assert_equal '/var/run/ar_sendmail/ar_sendmail.pid', options[:PidFile]
|
|
370
|
+
|
|
371
|
+
argv = %w[--pid-file=/tmp/ar_sendmail.pid]
|
|
372
|
+
|
|
373
|
+
options = ActionMailer::ARSendmail.process_args argv
|
|
374
|
+
|
|
375
|
+
assert_equal '/tmp/ar_sendmail.pid', options[:PidFile]
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
def test_class_parse_args_pid_file_nonexistent
|
|
379
|
+
argv = %w[--pid-file /nonexistent/ar_sendmail.pid]
|
|
380
|
+
|
|
381
|
+
e = assert_raises OptionParser::InvalidArgument do
|
|
382
|
+
ActionMailer::ARSendmail.process_args argv
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
assert_equal 'invalid argument: --pid-file directory /nonexistent does not exist',
|
|
386
|
+
e.message
|
|
387
|
+
end
|
|
388
|
+
|
|
303
389
|
def test_class_parse_args_table_name
|
|
304
390
|
argv = %w[-t Email]
|
|
305
391
|
|
|
@@ -331,7 +417,7 @@ Last send attempt: Thu Aug 10 11:40:05 2006
|
|
|
331
417
|
end
|
|
332
418
|
|
|
333
419
|
assert_equal '', out
|
|
334
|
-
assert_equal "
|
|
420
|
+
assert_equal "opts\n\nhi\n", err
|
|
335
421
|
end
|
|
336
422
|
|
|
337
423
|
def test_cleanup
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ar_mailer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Hodel
|
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
|
30
30
|
x52qPcexcYZR7w==
|
|
31
31
|
-----END CERTIFICATE-----
|
|
32
32
|
|
|
33
|
-
date: 2009-
|
|
33
|
+
date: 2009-10-15 00:00:00 -07:00
|
|
34
34
|
default_executable:
|
|
35
35
|
dependencies:
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
@@ -51,7 +51,7 @@ dependencies:
|
|
|
51
51
|
requirements:
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 2.3.
|
|
54
|
+
version: 2.3.3
|
|
55
55
|
version:
|
|
56
56
|
description: |-
|
|
57
57
|
ar_mailer is a two-phase delivery agent for ActionMailer. Even delivering
|
|
@@ -70,6 +70,7 @@ extra_rdoc_files:
|
|
|
70
70
|
- Manifest.txt
|
|
71
71
|
- README.txt
|
|
72
72
|
files:
|
|
73
|
+
- .autotest
|
|
73
74
|
- History.txt
|
|
74
75
|
- LICENSE.txt
|
|
75
76
|
- Manifest.txt
|
|
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
108
109
|
requirements: []
|
|
109
110
|
|
|
110
111
|
rubyforge_project: seattlerb
|
|
111
|
-
rubygems_version: 1.3.
|
|
112
|
+
rubygems_version: 1.3.5
|
|
112
113
|
signing_key:
|
|
113
114
|
specification_version: 3
|
|
114
115
|
summary: ar_mailer is a two-phase delivery agent for ActionMailer
|
metadata.gz.sig
CHANGED
|
Binary file
|