fishman-ar_mailer 2.1.9 → 2.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/README.rdoc CHANGED
@@ -1,6 +1,8 @@
1
- = ar_mailer
1
+ = ar_mailer_rails3
2
2
 
3
- A two-phase delivery agent for ActionMailer
3
+ A two-phase delivery agent for ActionMailer which works for Rails 3.
4
+
5
+ Forked from http://github.com/adzap/ar_mailer/
4
6
 
5
7
  Rubyforge Project:
6
8
 
@@ -12,11 +14,11 @@ http://seattlerb.org/ar_mailer
12
14
 
13
15
  and for forked additions
14
16
 
15
- http://github.com/adzap/ar_mailer/wikis
17
+ http://github.com/yzhang/ar_mailer_rails3/wikis
16
18
 
17
19
  Bugs:
18
20
 
19
- http://adzap.lighthouseapp.com/projects/26997-ar_mailer
21
+ http://github.com/yzhang/ar_mailer_rails3/issues
20
22
 
21
23
  == About
22
24
 
@@ -24,27 +26,11 @@ Even delivering email to the local machine may take too long when you have to
24
26
  send hundreds of messages. ar_mailer allows you to store messages into the
25
27
  database for later delivery by a separate process, ar_sendmail.
26
28
 
27
- == Installing ar_mailer (forked)
28
-
29
- Before installing you will need to make sure the original gem is uninstalled as they can't coexist:
30
-
31
- $ sudo gem uninstall ar_mailer
32
-
33
- Then
34
-
35
- $ sudo gem install adzap-ar_mailer
36
-
37
- For Rails >= 2.1, in your environment.rb:
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"
29
+ == Installing ar_mailer_rails3
44
30
 
45
- For Rails 2.0, in an initializer file:
31
+ Don't need remove adzap-ar_mailer or ar_mailer, just install ar_mailer_rails3
46
32
 
47
- require 'action_mailer/ar_mailer'
33
+ $ sudo gem install ar_mailer_rails3
48
34
 
49
35
  == Usage
50
36
 
@@ -52,19 +38,19 @@ Go to your Rails project:
52
38
 
53
39
  $ cd your_rails_project
54
40
 
55
- Create the migration and model:
41
+ Create the migration, model and initializer:
56
42
 
57
43
  This shows the options which are only the model name, which defaults to Email
58
44
 
59
- ./script/generate ar_mailer -h
45
+ ./script/generate ar_mailer_rails3 -h
60
46
 
61
47
  Then run with defaults
62
48
 
63
- ./script/generate ar_mailer
49
+ ./script/generate ar_mailer email
64
50
 
65
51
  Or specify a custom model name
66
52
 
67
- ./script/generate ar_mailer Newsletter
53
+ ./script/generate ar_mailer newsletter
68
54
 
69
55
  See Alternate Mail Storage if you use a custom model name
70
56
 
@@ -75,14 +61,15 @@ Something like:
75
61
  from 'no_reply@example.com'
76
62
  # ...
77
63
 
78
- Edit config/environments/production.rb and set the delivery method:
64
+ Edit config/initializer/ar_mailer_rails3.rb and uncomment below line to use ar_mailer as
65
+ default delivery method:
79
66
 
80
- config.action_mailer.delivery_method = :activerecord
67
+ ActionMailer::Base.delivery_method = :active_record
81
68
 
82
69
  Or if you need to, you can set each mailer class delivery method individually:
83
70
 
84
71
  class MyMailer < ActionMailer::Base
85
- self.delivery_method = :activerecord
72
+ self.delivery_method = :active_record
86
73
  end
87
74
 
88
75
  This can be useful when using plugins like ExceptionNotification. Where it
@@ -93,19 +80,19 @@ mailer classes to use ARMailer explicitly.
93
80
 
94
81
  Then to run it:
95
82
 
96
- $ ar_sendmail
83
+ $ ar_sendmail_rails3
97
84
 
98
85
  You can also run it from cron with -o, or as a daemon with -d.
99
86
 
100
- See <tt>ar_sendmail -h</tt> for full details.
87
+ See <tt>ar_sendmail_rails3 -h</tt> for full details.
101
88
 
102
89
  === Alternate Mail Storage
103
90
 
104
- By default ar_mailer assumes you are using an ActiveRecord model called
91
+ By default ar_mailer_rails3 assumes you are using an ActiveRecord model called
105
92
  Email to store the emails created before sending. If you want to change
106
93
  this you alter it in an intializer like so:
107
94
 
108
- ActionMailer::Base.email_class = Newsletter
95
+ ActionMailer::Base.add_delivery_method :active_record, ArMailer::ActiveRecord, :email_class => Newsletter
109
96
 
110
97
  === A Word on TLS
111
98
 
@@ -120,7 +107,7 @@ patch allows you to explicit set if the server supports TLS by setting the
120
107
 
121
108
  === Help
122
109
 
123
- See ar_sendmail -h for options to ar_sendmail.
110
+ See ar_sendmail_rails3 -h for options to ar_sendmail_rails3.
124
111
 
125
112
  NOTE: You may need to delete an smtp_tls.rb file if you have one lying
126
113
  around. ar_mailer supplies it own.
data/Rakefile CHANGED
@@ -1,76 +1,18 @@
1
- require 'rubygems'
2
- require 'rake/gempackagetask'
1
+ require 'rake'
3
2
  require 'rake/testtask'
4
- require 'rake/rdoctask'
5
3
 
6
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/lib'))
7
-
8
- require './lib/action_mailer/ar_sendmail'
9
-
10
- ar_mailer_gemspec = Gem::Specification.new do |s|
11
- s.name = %q{fishman-ar_mailer}
12
- s.version = ActionMailer::ARSendmail::VERSION
13
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
14
- s.authors = ["Eric Hodel", "Adam Meehan", "Reza Jelveh"]
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.}
17
- s.email = %q{adam.meehan@gmail.com}
18
- s.executables = ["ar_sendmail"]
19
- s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "README.rdoc"]
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
- ]
41
- s.has_rdoc = true
42
- s.homepage = %q{http://github.com/adzap/ar_mailer}
43
- s.rdoc_options = ["--main", "README.rdoc"]
44
- s.require_paths = ["lib"]
45
- s.rubyforge_project = %q{seattlerb}
46
- s.summary = %q{A two-phase delivery agent for ActionMailer}
47
- s.test_files = ["test/test_armailer.rb", "test/test_arsendmail.rb"]
48
- s.add_development_dependency "minitest", ">= 1.5.0"
49
- s.add_development_dependency "mocha", ">= 0.9.8"
50
- end
51
-
52
- Rake::GemPackageTask.new(ar_mailer_gemspec) do |pkg|
53
- pkg.gem_spec = ar_mailer_gemspec
54
- end
55
-
56
- desc "Update ar_mailer.gemspec"
57
- task :make_spec do
58
- File.open("adzap-ar_mailer.gemspec", "w") do |f|
59
- f.puts(ar_mailer_gemspec.to_ruby)
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |s|
7
+ s.name = "ar_mailer"
8
+ s.summary = "ArMailer wrapper for Rails 3"
9
+ s.email = "zhangyuanyi@gmail.com"
10
+ s.homepage = "http://github.com/fishman/ar_mailer"
11
+ s.description = "ArMailer wrapper for Rails 3"
12
+ s.authors = ["Yuanyi Zhang"]
13
+ s.files = FileList["[A-Z]*", "bin/*", "share/*", "test/*", "{lib}/**/*", '.gitignore']
14
+ s.test_files = []
60
15
  end
61
- end
62
-
63
- desc "Build packages and install"
64
- task :install => :package do
65
- sh %{sudo gem install --local --test pkg/ar_mailer-#{ActionMailer::ARSendmail::VERSION}}
66
- end
67
-
68
- desc 'Default: run unit tests.'
69
- task :default => :test
70
-
71
- desc 'Test the ar_mailer gem.'
72
- Rake::TestTask.new(:test) do |t|
73
- t.libs << 'lib' << 'test'
74
- t.test_files = FileList['test/**/test_*.rb'].exclude("test/test_helper.rb")
75
- t.verbose = true
16
+ rescue LoadError
17
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
76
18
  end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.1.11
data/bin/ar_sendmail CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'action_mailer/ar_sendmail'
3
+ require 'ar_mailer/ar_sendmail'
4
4
 
5
- ActionMailer::ARSendmail.run
5
+ ArMailer::ARSendmail.run
6
6
 
@@ -0,0 +1,55 @@
1
+ module ArMailer
2
+ # A delivery method implementation which sends via sendmail.
3
+ #
4
+ # To use this, first find out where the sendmail binary is on your computer,
5
+ # if you are on a mac or unix box, it is usually in /usr/sbin/sendmail, this will
6
+ # be your sendmail location.
7
+ #
8
+ # Mail.defaults do
9
+ # delivery_method :sendmail
10
+ # end
11
+ #
12
+ # Or if your sendmail binary is not at '/usr/sbin/sendmail'
13
+ #
14
+ # Mail.defaults do
15
+ # delivery_method :sendmail, :location => '/absolute/path/to/your/sendmail'
16
+ # end
17
+ #
18
+ # Then just deliver the email as normal:
19
+ #
20
+ # Mail.deliver do
21
+ # to 'mikel@test.lindsaar.net'
22
+ # from 'ada@test.lindsaar.net'
23
+ # subject 'testing sendmail'
24
+ # body 'testing sendmail'
25
+ # end
26
+ #
27
+ # Or by calling deliver on a Mail message
28
+ #
29
+ # mail = Mail.new do
30
+ # to 'mikel@test.lindsaar.net'
31
+ # from 'ada@test.lindsaar.net'
32
+ # subject 'testing sendmail'
33
+ # body 'testing sendmail'
34
+ # end
35
+ #
36
+ # mail.deliver!
37
+ class ActiveRecord
38
+
39
+ def initialize(options)
40
+ self.email_class = options[:email_class] || Email
41
+ self.email_backup_class = options[:email_backup_class] || EmailBackup
42
+ end
43
+
44
+ attr_accessor :email_class_name, :email_class
45
+ attr_accessor :email_backup_class_name, :email_backup_class
46
+
47
+ def deliver!(mail)
48
+ destinations = mail.destinations
49
+ sender = mail.return_path || mail.sender || mail.from_addrs.first
50
+ destinations.each do |destination|
51
+ self.email_class.create :mail => mail.encoded, :to => destination, :from => sender
52
+ end
53
+ end
54
+ end
55
+ end
@@ -35,14 +35,14 @@ end
35
35
  # * --daemon
36
36
  # * --mailq
37
37
 
38
- module ActionMailer; end
38
+ module ArMailer; end
39
39
 
40
- class ActionMailer::ARSendmail
40
+ class ArMailer::ARSendmail
41
41
 
42
42
  ##
43
43
  # The version of ActionMailer::ARSendmail you are running.
44
44
 
45
- VERSION = '2.1.9'
45
+ VERSION = '2.1.8'
46
46
 
47
47
  ##
48
48
  # Maximum number of times authentication will be consecutively retried
@@ -90,6 +90,17 @@ class ActionMailer::ARSendmail
90
90
  end
91
91
  end
92
92
 
93
+ ##
94
+ # Get email class
95
+
96
+ def self.email_class
97
+ ActionMailer::Base.active_record_settings[:email_class]
98
+ end
99
+
100
+ def self.email_backup_class
101
+ ActionMailer::Base.active_record_settings[:email_backup_class]
102
+ end
103
+
93
104
  ##
94
105
  # Prints a list of unsent emails and the last delivery attempt, if any.
95
106
  #
@@ -98,7 +109,7 @@ class ActionMailer::ARSendmail
98
109
  # to learn how to enable ActiveRecord::Timestamp.
99
110
 
100
111
  def self.mailq
101
- emails = ActionMailer::Base.email_class.find :all
112
+ emails = self.email_class.find :all
102
113
 
103
114
  if emails.empty? then
104
115
  puts "Mail queue is empty"
@@ -249,8 +260,8 @@ class ActionMailer::ARSendmail
249
260
 
250
261
  Dir.chdir options[:Chdir] do
251
262
  begin
252
- require 'config/environment'
253
- require 'action_mailer/ar_mailer'
263
+ require Dir.pwd + '/config/environment'
264
+ require 'ar_mailer/active_record'
254
265
  rescue LoadError
255
266
  usage opts, <<-EOF
256
267
  #{name} must be run from a Rails application's root to deliver email.
@@ -348,7 +359,7 @@ class ActionMailer::ARSendmail
348
359
  return if @max_age == 0
349
360
  timeout = Time.now - @max_age
350
361
  conditions = ['last_send_attempt > 0 and created_on < ?', timeout]
351
- mail = ActionMailer::Base.email_class.destroy_all conditions
362
+ mail = self.class.email_class.destroy_all conditions
352
363
 
353
364
  log "expired #{mail.length} emails from the queue"
354
365
  end
@@ -377,8 +388,7 @@ class ActionMailer::ARSendmail
377
388
  email = emails.shift
378
389
  begin
379
390
  res = session.send_message email.mail, email.from, email.to
380
- # create a copy of the sent mail in the emailbackup model
381
- ActionMailer::Base.email_backup_class.create :mail => email.mail, :to => email.to, :from => email.from
391
+ self.class.email_backup_class.create :mail => email.mail, :to => email.to, :from => email.from
382
392
  email.destroy
383
393
  log "sent email %011d from %s to %s: %p" %
384
394
  [email.id, email.from, email.to, res]
@@ -428,7 +438,7 @@ class ActionMailer::ARSendmail
428
438
  def find_emails
429
439
  options = { :conditions => ['last_send_attempt < ?', Time.now.to_i - 300] }
430
440
  options[:limit] = batch_size unless batch_size.nil?
431
- mail = ActionMailer::Base.email_class.find :all, options
441
+ mail = self.class.email_class.find :all, options
432
442
 
433
443
  log "found #{mail.length} emails to send"
434
444
  mail
@@ -462,7 +472,7 @@ class ActionMailer::ARSendmail
462
472
  cleanup
463
473
  emails = find_emails
464
474
  deliver(emails) unless emails.empty?
465
- rescue ActiveRecord::Transactions::TransactionError
475
+ rescue
466
476
  end
467
477
  break if @once
468
478
  sleep @delay
data/lib/ar_mailer.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ar_mailer/active_record'
@@ -0,0 +1,31 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class ArMailerGenerator < Rails::Generators::NamedBase
5
+ include Rails::Generators::Migration
6
+
7
+ def create_ar_mailer_files
8
+ self.class.check_class_collision class_name
9
+ template('ar_mailer.rb', 'config/initializers/ar_mailer.rb')
10
+ template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
11
+ migration_template 'migration.rb', "db/migrate/create_#{file_path.gsub(/\//, '_').pluralize}.rb"
12
+ end
13
+
14
+ def self.source_root
15
+ File.join(File.dirname(__FILE__), 'templates')
16
+ end
17
+
18
+ # Implement the required interface for Rails::Generators::Migration.
19
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
20
+ def self.next_migration_number(dirname)
21
+ if ActiveRecord::Base.timestamped_migrations
22
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
23
+ else
24
+ "%.3d" % (current_migration_number(dirname) + 1)
25
+ end
26
+ end
27
+
28
+ def self.banner
29
+ "Usage: #{$0} ar_mailer EmailModelName (default: Email)"
30
+ end
31
+ end
@@ -0,0 +1,2 @@
1
+ ActionMailer::Base.add_delivery_method :active_record, ArMailer::ActiveRecord, :email_class => <%= class_name %>
2
+ ActionMailer::Base.delivery_method = :active_record
@@ -1,4 +1,4 @@
1
- class <%= migration_name %> < ActiveRecord::Migration
1
+ class <%= migration_class_name.gsub(/::/, '') %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :<%= table_name %> do |t|
4
4
  t.column :from, :string
metadata CHANGED
@@ -1,95 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fishman-ar_mailer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
6
  - 2
8
7
  - 1
9
- - 9
10
- version: 2.1.9
8
+ - 11
9
+ version: 2.1.11
11
10
  platform: ruby
12
11
  authors:
13
- - Eric Hodel
14
- - Adam Meehan
15
- - Reza Jelveh
12
+ - Yuanyi Zhang
16
13
  autorequire:
17
14
  bindir: bin
18
15
  cert_chain: []
19
16
 
20
- date: 2010-10-11 00:00:00 +02:00
17
+ date: 2011-03-21 00:00:00 +01:00
21
18
  default_executable: ar_sendmail
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
24
- name: minitest
25
- prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
27
- none: false
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- hash: 3
32
- segments:
33
- - 1
34
- - 5
35
- - 0
36
- version: 1.5.0
37
- type: :development
38
- version_requirements: *id001
39
- - !ruby/object:Gem::Dependency
40
- name: mocha
41
- prerelease: false
42
- requirement: &id002 !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- hash: 43
48
- segments:
49
- - 0
50
- - 9
51
- - 8
52
- version: 0.9.8
53
- type: :development
54
- version_requirements: *id002
55
- 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.
56
- email: adam.meehan@gmail.com
19
+ dependencies: []
20
+
21
+ description: ArMailer wrapper for Rails 3
22
+ email: zhangyuanyi@gmail.com
57
23
  executables:
58
24
  - ar_sendmail
59
25
  extensions: []
60
26
 
61
27
  extra_rdoc_files:
62
- - History.txt
63
28
  - LICENSE.txt
64
29
  - README.rdoc
65
30
  files:
31
+ - .gitignore
66
32
  - History.txt
67
33
  - LICENSE.txt
68
34
  - README.rdoc
69
35
  - Rakefile
36
+ - VERSION
70
37
  - bin/ar_sendmail
71
- - generators/ar_mailer/ar_mailer_generator.rb
72
- - generators/ar_mailer/templates/migration.rb
73
- - generators/ar_mailer/templates/model.rb
74
- - lib/adzap-ar_mailer.rb
75
- - lib/action_mailer/ar_mailer.rb
76
- - lib/action_mailer/ar_sendmail.rb
38
+ - lib/ar_mailer.rb
39
+ - lib/ar_mailer/active_record.rb
40
+ - lib/ar_mailer/ar_sendmail.rb
41
+ - lib/generators/ar_mailer/ar_mailer_generator.rb
42
+ - lib/generators/ar_mailer/templates/ar_mailer.rb
43
+ - lib/generators/ar_mailer/templates/migration.rb
44
+ - lib/generators/ar_mailer/templates/model.rb
77
45
  - lib/smtp_tls.rb
78
- - share/bsd/ar_sendmail
79
- - share/linux/ar_sendmail
80
- - share/linux/ar_sendmail.conf
81
- - test/resources/action_mailer.rb
82
46
  - test/test_armailer.rb
83
47
  - test/test_arsendmail.rb
84
48
  - test/test_helper.rb
85
49
  has_rdoc: true
86
- homepage: http://github.com/adzap/ar_mailer
50
+ homepage: http://github.com/fishman/ar_mailer
87
51
  licenses: []
88
52
 
89
53
  post_install_message:
90
54
  rdoc_options:
91
- - --main
92
- - README.rdoc
55
+ - --charset=UTF-8
93
56
  require_paths:
94
57
  - lib
95
58
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -97,7 +60,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
60
  requirements:
98
61
  - - ">="
99
62
  - !ruby/object:Gem::Version
100
- hash: 3
101
63
  segments:
102
64
  - 0
103
65
  version: "0"
@@ -106,17 +68,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
68
  requirements:
107
69
  - - ">="
108
70
  - !ruby/object:Gem::Version
109
- hash: 3
110
71
  segments:
111
72
  - 0
112
73
  version: "0"
113
74
  requirements: []
114
75
 
115
- rubyforge_project: seattlerb
76
+ rubyforge_project:
116
77
  rubygems_version: 1.3.7
117
78
  signing_key:
118
79
  specification_version: 3
119
- summary: A two-phase delivery agent for ActionMailer
120
- test_files:
121
- - test/test_armailer.rb
122
- - test/test_arsendmail.rb
80
+ summary: ArMailer wrapper for Rails 3
81
+ test_files: []
82
+
@@ -1,30 +0,0 @@
1
- class ArMailerGenerator < Rails::Generator::NamedBase
2
-
3
- def initialize(runtime_args, runtime_options = {})
4
- runtime_args.unshift('Email') if runtime_args.empty?
5
- super
6
- end
7
-
8
- def manifest
9
- record do |m|
10
- m.class_collisions class_name
11
-
12
- m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
13
- m.template 'model.rb', File.join('app/models', 'EmailBackup', "email_backup.rb")
14
-
15
- m.migration_template 'migration.rb', 'db/migrate', :assigns => {
16
- :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
17
- }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
18
-
19
- m.migration_template 'migration.rb', 'db/migrate', :assigns => {
20
- :migration_name => "Create#{'EmailBackup'.pluralize.gsub(/::/, '')}"
21
- }, :migration_file_name => "create_#{'email_backup'.gsub(/\//, '_').pluralize}"
22
- end
23
- end
24
-
25
- protected
26
- def banner
27
- "Usage: #{$0} #{spec.name} EmailModelName (default: Email)"
28
- end
29
-
30
- end
@@ -1,47 +0,0 @@
1
- ##
2
- # Adds sending email through an ActiveRecord table as a delivery method for
3
- # ActionMailer.
4
- #
5
-
6
- class ActionMailer::Base
7
-
8
- ##
9
- # Set the email class for deliveries. Handle class reloading issues which prevents caching the email class.
10
- #
11
- @@email_class_name = 'Email'
12
-
13
- def self.email_class=(klass)
14
- @@email_class_name = klass.to_s
15
- end
16
-
17
- def self.email_class
18
- @@email_class_name.constantize
19
- end
20
-
21
- ##
22
- # Set the email class for successful deliveries.
23
- #
24
- @@email_backup_class_name = 'EmailBackup'
25
-
26
- def self.email_backup_class=(klass)
27
- @@email_backup_class_name = klass.to_s
28
- end
29
-
30
- def self.email_backup_class
31
- @@email_backup_class_name.constantize
32
- end
33
-
34
- ##
35
- # Adds +mail+ to the Email table. Only the first From address for +mail+ is
36
- # used.
37
-
38
- def perform_delivery_activerecord(mail)
39
- destinations = mail.destinations
40
- mail.ready_to_send
41
- sender = (mail['return-path'] && mail['return-path'].spec) || mail.from.first
42
- destinations.each do |destination|
43
- self.class.email_class.create :mail => mail.encoded, :to => destination, :from => sender
44
- end
45
- end
46
-
47
- end
@@ -1 +0,0 @@
1
- require 'action_mailer/ar_mailer'
@@ -1,30 +0,0 @@
1
- #!/bin/sh
2
- # PROVIDE: ar_sendmail
3
- # REQUIRE: DAEMON
4
- # BEFORE: LOGIN
5
- # KEYWORD: FreeBSD shutdown
6
-
7
- #
8
- # Add the following lines to /etc/rc.conf to enable ar_sendmail:
9
- #
10
- #ar_sendmail_enable="YES"
11
-
12
- . /etc/rc.subr
13
-
14
- name="ar_sendmail"
15
- rcvar=`set_rcvar`
16
-
17
- command="/usr/local/bin/ar_sendmail"
18
- command_interpreter="/usr/local/bin/ruby18"
19
-
20
- # set defaults
21
-
22
- ar_sendmail_rails_env=${ar_sendmail_rails_env:-"production"}
23
- ar_sendmail_chdir=${ar_sendmail_chdir:-"/"}
24
- ar_sendmail_enable=${ar_sendmail_enable:-"NO"}
25
- ar_sendmail_flags=${ar_sendmail_flags:-"-d"}
26
-
27
- load_rc_config $name
28
- export RAILS_ENV=$ar_sendmail_rails_env
29
- run_rc_command "$1"
30
-
@@ -1,78 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # ar_sendmail Startup script for ar_mailer by Adam Meehan
4
- #
5
- # chkconfig: - 85 15
6
- # description: ar_sendmail manages sending emails for Rails apps.
7
- #
8
- require 'yaml'
9
-
10
- # Config file app mailers
11
- config_file = '/etc/ar_sendmail.conf'
12
-
13
- begin
14
- config = YAML::load(IO.read(config_file)) || {}
15
- if config.empty? || (config.has_key?('defaults') && config.size == 1)
16
- puts "No mailers defined. Exiting."
17
- exit -2
18
- end
19
- rescue Errno::ENOENT
20
- puts "Config file not found at '#{config_file}'!"
21
- exit -3
22
- end
23
-
24
- default_options = {'pidfile' => './log/ar_sendmail.pid'}.merge(config.delete('defaults') || {})
25
-
26
- command, app_name = *ARGV
27
-
28
- def start(app, options)
29
- switches = ""
30
- options.each {|k, v| switches << " --#{k} #{v}"}
31
- STDOUT.write "Starting mailer for #{app} in #{options['environment']} mode ... "
32
- status = system("ar_sendmail -d #{switches}") ? "started" : "failed"
33
- puts status
34
- end
35
-
36
- def stop(app, options)
37
- pid_file = File.expand_path(options['pidfile'], options['chdir'])
38
- if File.exist? pid_file
39
- begin
40
- pid = open(pid_file).read.to_i
41
- STDOUT.write "Stopping mailer for #{app}... "
42
- Process.kill('TERM', pid)
43
- puts "stopped"
44
- rescue Errno::ESRCH
45
- puts "Mailer process does not exist. Is not running."
46
- end
47
- else
48
- puts "Skipping mailer for #{app}, no pid file."
49
- end
50
- end
51
-
52
- def restart(app, options)
53
- puts "Restarting mailer for #{app} ..."
54
- stop app, options
55
- start app, options
56
- end
57
-
58
- def command_error(msg)
59
- puts msg
60
- exit -1
61
- end
62
-
63
- if ['start', 'stop', 'restart'].include?(command)
64
- apps = config
65
- if app_name
66
- command_error "No such app defined in ar_sendmail config" unless config.include?(app_name)
67
- app_options = config[app_name]
68
- command_error "Must specify chdir for app in ar_sendmail config" if app_options['chdir'].nil?
69
- apps = {app_name => app_options}
70
- end
71
-
72
- apps.each do |app, options|
73
- options = default_options.merge(options)
74
- send(command, app, options)
75
- end
76
- else
77
- command_error "Usage: ar_sendmail {start|stop|restart} [optional app_name]"
78
- end
@@ -1,30 +0,0 @@
1
- # This is a configuration file for ar_sendmail daemon init.d script
2
- #
3
- # Define the settings for each app which has a mailer that you want start
4
- # automatically on startup.
5
- #
6
- # You can define an optional defaults section which will apply to all
7
- # applications unless the setting is specified under the applications specific
8
- # config.
9
- #
10
- # Settings not specified in either the defaults or app config section will
11
- # be implied by the gem binary defaults. The option names are the same as the
12
- # long format binary option switches. Run 'ar_sendmail -h' to see option switches
13
- # and default values.
14
- #
15
- # Copy this file to /etc/ar_sendmail.conf and it will be read by the init.d
16
- # script.
17
- #
18
-
19
- ## Demo app config
20
- #
21
- #defaults:
22
- # batch-size: 10
23
- # max-age: 0
24
- # delay: 60
25
- #
26
- #app_name:
27
- # chdir: /var/www/apps/app_name
28
- # environment: production
29
- # pidfile: ./log/ar_sendmail.pid
30
-
@@ -1,197 +0,0 @@
1
- require 'net/smtp'
2
- require 'smtp_tls' unless Net::SMTP.instance_methods.include?("enable_starttls_auto")
3
- require 'time'
4
-
5
- class Net::SMTP
6
-
7
- @reset_called = 0
8
-
9
- @deliveries = []
10
-
11
- @send_message_block = nil
12
-
13
- @start_block = nil
14
-
15
- class << self
16
-
17
- attr_reader :deliveries
18
- attr_reader :send_message_block
19
- attr_accessor :reset_called
20
-
21
- # send :remove_method, :start
22
- end
23
-
24
- def self.on_send_message(&block)
25
- @send_message_block = block
26
- end
27
-
28
- def self.on_start(&block)
29
- if block_given?
30
- @start_block = block
31
- else
32
- @start_block
33
- end
34
- end
35
-
36
- def self.clear_on_start
37
- @start_block = nil
38
- end
39
-
40
- def self.reset
41
- deliveries.clear
42
- on_start
43
- on_send_message
44
- @reset_called = 0
45
- end
46
-
47
- def start(*args)
48
- self.class.on_start.call if self.class.on_start
49
- yield self
50
- end
51
-
52
- alias test_old_reset reset if instance_methods.include? 'reset'
53
-
54
- def reset
55
- self.class.reset_called += 1
56
- end
57
-
58
- alias test_old_send_message send_message
59
-
60
- def send_message(mail, to, from)
61
- return self.class.send_message_block.call(mail, to, from) unless
62
- self.class.send_message_block.nil?
63
- self.class.deliveries << [mail, to, from]
64
- return "queued"
65
- end
66
-
67
- end
68
-
69
- ##
70
- # Stub for ActionMailer::Base
71
-
72
- module ActionMailer; end
73
-
74
- class ActionMailer::Base
75
-
76
- @server_settings = {}
77
-
78
- class << self
79
- cattr_accessor :email_class
80
- attr_accessor :delivery_method
81
- end
82
-
83
- def self.logger
84
- o = Object.new
85
- def o.info(arg) end
86
- return o
87
- end
88
-
89
- def self.method_missing(meth, *args)
90
- meth.to_s =~ /deliver_(.*)/
91
- super unless $1
92
- new($1, *args).deliver!
93
- end
94
-
95
- def self.reset
96
- server_settings.clear
97
- self.email_class = Email
98
- end
99
-
100
- def self.server_settings
101
- @server_settings
102
- end
103
-
104
- def initialize(meth = nil)
105
- send meth if meth
106
- end
107
-
108
- def deliver!
109
- perform_delivery_activerecord @mail
110
- end
111
-
112
- end
113
-
114
- ##
115
- # Stub for an ActiveRecord model
116
-
117
- class Email
118
-
119
- START = Time.parse 'Thu Aug 10 2006 11:19:48'
120
-
121
- attr_accessor :from, :to, :mail, :last_send_attempt, :created_on, :id
122
-
123
- @records = []
124
- @id = 0
125
-
126
- class << self; attr_accessor :records, :id; end
127
-
128
- def self.create(record)
129
- record = new record[:from], record[:to], record[:mail],
130
- record[:last_send_attempt]
131
- records << record
132
- return record
133
- end
134
-
135
- def self.destroy_all(conditions)
136
- timeout = conditions.last
137
- found = []
138
-
139
- records.each do |record|
140
- next if record.last_send_attempt == 0
141
- next if record.created_on == 0
142
- next unless record.created_on < timeout
143
- record.destroy
144
- found << record
145
- end
146
-
147
- found
148
- end
149
-
150
- def self.find(_, conditions = nil)
151
- return records if conditions.nil?
152
- now = Time.now.to_i - 300
153
- return records.select do |r|
154
- r.last_send_attempt < now
155
- end
156
- end
157
-
158
- def self.reset
159
- @id = 0
160
- records.clear
161
- end
162
-
163
- def initialize(from, to, mail, last_send_attempt = nil)
164
- @from = from
165
- @to = to
166
- @mail = mail
167
- @id = self.class.id += 1
168
- @created_on = START + @id
169
- @last_send_attempt = last_send_attempt || 0
170
- end
171
-
172
- def destroy
173
- self.class.records.delete self
174
- self.freeze
175
- end
176
-
177
- def ==(other)
178
- other.id == id
179
- end
180
-
181
- def save
182
- end
183
-
184
- end
185
-
186
- Newsletter = Email
187
-
188
- class String
189
- def classify
190
- self
191
- end
192
-
193
- def tableize
194
- self.downcase
195
- end
196
-
197
- end