whitelist_mail_proxy 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +12 -1
  2. data/Rakefile +1 -1
  3. data/lib/whitelist_mail_proxy.rb +27 -6
  4. metadata +4 -4
data/README CHANGED
@@ -20,6 +20,17 @@ config/staging.rb
20
20
 
21
21
  config.action_mailer.delivery_method = :whitelist_proxy
22
22
  # this will use the sendmail_settings defined elsewhere, or ActionMailer's default settings
23
- config.action_mailer.whitelist_proxy_settings = {:delivery_method =>:sendmail, :regexp => /@gmail\.com$/}
23
+ config.action_mailer.whitelist_proxy_settings = {:delivery_method =>:sendmail, :regexp => /test@/}
24
+
25
+ or if you want a specific domain
26
+
27
+ config.action_mailer.whitelist_proxy_settings = {:delivery_method =>:sendmail, :domain => "gmail.com"
28
+
29
+ or if you want multiple domains
30
+
31
+ config.action_mailer.whitelist_proxy_settings = {:delivery_method =>:sendmail, :domain => ["gmail.com", "hotmail.com"]
32
+
33
+
34
+
24
35
 
25
36
  Copyright (c) 2010 [Matthew Rudy Jacobs], released under the MIT license
data/Rakefile CHANGED
@@ -45,7 +45,7 @@ spec = Gem::Specification.new do |s|
45
45
 
46
46
  # Change these as appropriate
47
47
  s.name = "whitelist_mail_proxy"
48
- s.version = "0.3.3"
48
+ s.version = "0.4.0"
49
49
  s.summary = "A thin proxy for Mail and ActionMailer to enable whitelisting"
50
50
  s.author = "Matthew Rudy Jacobs"
51
51
  s.email = "MatthewRudyJacobs@gmail.com"
@@ -1,19 +1,21 @@
1
1
  class WhitelistMailProxy
2
2
 
3
3
  class BlockedDelivery < StandardError; end
4
+ class SettingsError < ArgumentError ; end
4
5
 
5
6
  def initialize(options)
6
7
  @delivery_method = options[:delivery_method]
7
8
  @regexp = options[:regexp]
9
+ @domains = options[:domain] && Array(options[:domain])
8
10
 
9
- raise "must have :delivery_method" unless @delivery_method
10
- raise "must have :regexp" unless @regexp
11
+ raise SettingsError, "you must specify config.action_mailer.whitelist_proxy_settings to contain a :delivery_method" unless @delivery_method
12
+ raise SettingsError, "you must specify config.action_mailer.whitelist_proxy_settings to contain a :regexp or :domain" unless @regexp || @domains
11
13
  end
12
- attr_reader :delivery_method, :regexp
14
+ attr_reader :delivery_method, :regexp, :domains
13
15
 
14
16
  def deliver!(mail)
15
17
  blocked = mail.destinations.select do |destination|
16
- block?(destination)
18
+ block_recipient?(destination)
17
19
  end
18
20
 
19
21
  if blocked.any?
@@ -23,10 +25,29 @@ class WhitelistMailProxy
23
25
  end
24
26
  end
25
27
 
28
+ # eg.
29
+ # "Matthew Rudy Jacobs"<matthewrudyjacobs@gmail.com>
30
+ # matthewrudyjacobs@gmail.com
31
+ def self.extract_email_address(recipient)
32
+ recipient.split("<").last.gsub(/>$/, "").strip
33
+ end
34
+
35
+ def self.extract_email_domain(recipient)
36
+ extract_email_address(recipient).split("@").last
37
+ end
38
+
39
+ def block_recipient?(string)
40
+ block_by_regexp?(string) || block_by_domain?(string)
41
+ end
42
+
26
43
  protected
27
44
 
28
- def block?(string)
29
- string !~ regexp
45
+ def block_by_regexp?(string)
46
+ string !~ regexp if self.regexp
47
+ end
48
+
49
+ def block_by_domain?(string)
50
+ !self.domains.include?(self.class.extract_email_domain(string)) if self.domains
30
51
  end
31
52
 
32
53
  def real_delivery_method
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whitelist_mail_proxy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 3
10
- version: 0.3.3
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew Rudy Jacobs