safety_mailer 0.0.2 → 0.0.3

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
@@ -19,7 +19,18 @@ Don't forget to <tt>bundle install</tt> to install
19
19
  In your environment file <tt>config/environments/development.rb</tt> configure it, and some regular expressions.
20
20
 
21
21
  config.action_mailer.delivery_method = :safety_mailer
22
- SafetyMailer::Config.allowed_matchers = [ /mydomain.com/, /mytestacct@gmail.com/, /super_secret_test/ ]
22
+ config.action_mailer.safety_mailer_settings = {
23
+ allowed_matchers: [ /mydomain.com/, /mytestacct@gmail.com/, /super_secret_test/ ],
24
+ delivery_method: :smtp,
25
+ delivery_method_settings: {
26
+ :address => "smtp.mydomain.com",
27
+ :port => 25,
28
+ :domain => "mydomain.com",
29
+ :authentication => :plain,
30
+ :user_name => "mydomain_mailer@mydomain.com",
31
+ :password => "password"
32
+ }
33
+ }
23
34
 
24
35
  ... and now, email to anyone@mydomain.com, mytestacct@gmail.com, bob+super_secret_test@yahoo.com all get sent
25
36
  and email to other recipients (like the real users in the production database you copied to a test server) is suppressed.
@@ -30,9 +41,10 @@ Any user of the Mail gem can configure safety_mailer:
30
41
 
31
42
  require "safety_mailer"
32
43
  Mail.defaults do
33
- delivery_method SafetyMailer::Carrier
44
+ delivery_method SafetyMailer::Carrier, {
45
+ ... same settings as above
46
+ }
34
47
  end
35
- SafetyMailer::Config.allowed_matchers = [ /mydomain.com/, /mytestacct@gmail.com/, /super_secret_test/ ]
36
48
 
37
49
  == License
38
50
 
@@ -1,6 +1,6 @@
1
1
  module SafetyMailer
2
2
  class Railtie < Rails::Railtie
3
- initializer "safety_mailer.add_delivery_method" do
3
+ config.before_configuration do
4
4
  ActionMailer::Base.add_delivery_method :safety_mailer, SafetyMailer::Carrier
5
5
  end
6
6
  end
@@ -1,21 +1,18 @@
1
1
  module SafetyMailer
2
- class Config
3
- @@allowed_matchers = []
4
- cattr_accessor :allowed_matchers
5
- @@delivery_method = :smtp
6
- cattr_accessor :delivery_method
7
- end
8
2
  class Carrier
9
3
  attr_accessor :params
10
4
  def initialize(params = {})
11
5
  self.params = params
6
+ delivery_method = params[:delivery_method] || :smtp
7
+ settings = params[:delivery_method_settings] || {}
8
+ @delivery_method = Mail::Configuration.instance.lookup_delivery_method(delivery_method).new(settings)
12
9
  end
13
10
  def log(msg)
14
11
  Rails.logger.warn(msg) if defined?(Rails)
15
12
  end
16
13
  def deliver!(mail)
17
14
  mail.to = mail.to.reject do |recipient|
18
- if SafetyMailer::Config.allowed_matchers.any?{ |m| recipient =~ m }
15
+ if params[:allowed_matchers].any?{ |m| recipient =~ m }
19
16
  false
20
17
  else
21
18
  log "*** safety_mailer suppressing mail to #{recipient}"
@@ -26,7 +23,7 @@ module SafetyMailer
26
23
  log "*** safety_mailer - no recipients left ... suppressing delivery altogether"
27
24
  else
28
25
  log "*** safety_mailer allowing delivery to #{mail.to}"
29
- Mail::Configuration.instance.lookup_delivery_method(SafetyMailer::Config.delivery_method).deliver!(mail)
26
+ @delivery_method.deliver!(mail)
30
27
  end
31
28
  end
32
29
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safety_mailer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bill Kirtley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-08 00:00:00 Z
18
+ date: 2012-02-12 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Specify a domain (or set of domains, or magic word in email address) email is allowed to go to, and email to all other domains is silently dropped. Useful for testing and staging environments.