mail_whitelist 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31b8a163785a9a8b8042184147cebe52098d2e12
4
- data.tar.gz: 72105530a61172bef15077fe2bc124e1881b654e
3
+ metadata.gz: 73f90ae5ab23f0a6ee9d6adb00a1643345464d6e
4
+ data.tar.gz: f4896faf865420c8caa3032960df2b56acff4716
5
5
  SHA512:
6
- metadata.gz: 2095f6d61b3bfbe04f1e579ab56804b6a969e99c4321b34e23f8b242b4fcf04397c8ac2b3566ab459e1a440873114709fe16484ebe3f5d907615b3654cad96e0
7
- data.tar.gz: 516911c93592734de4a4c84ba9518361d55a7188817cdd16c9723b1c04be51c25d02bdb2ce8f2459133cf96f8ed2ede8d67eb37c53a2f822f59a9937b5f11ddf
6
+ metadata.gz: 7c4287b04ac3e88e6442d1bc33d66902048f2a68cab2c036eade46327ddd3363b24e6a7c4c3cf8b31a64a0a69abc4e218c1f17c30b99e0e9f01e93294952f4ec
7
+ data.tar.gz: 4c4f09df041ea676293dd9f30ec40f1a44a5133d6dc840c6e07be0917080c00d7d7ecd927c780ffcac0732a260d39c27c57713174cf00ce02819aacf2e4c7b90
data/README.md CHANGED
@@ -7,9 +7,10 @@ your app and provides a fallback in case nobody would receive the mail. This
7
7
  can be useful to make sure no accidental emails are sent from your staging
8
8
  environment, but your mails can still be checked.
9
9
 
10
- One way to use it is to set an environment variable `MAIL_WHITELIST` and check
11
- for its existence and use it to instantiate the `MailWhitelist` class so that
12
- within this environment only those email addresses will have mail sent to them.
10
+ One way to use it is to set an environment variable `MAIL_WHITELIST`, check
11
+ for its existence and use it to instantiate a `MailWhitelist` so that within
12
+ this environment only those emailaddresses can have mail sent to them.
13
+ See below for a code exapmle.
13
14
 
14
15
  ## Installation
15
16
 
@@ -30,13 +31,19 @@ Or install it yourself as:
30
31
  ## Usage
31
32
 
32
33
  Specify your whitelist as an array of email addresses and register them in an
33
- initializer in your Rails app as such:
34
+ initializer in your Rails app. Optionally specify a fallback address as second
35
+ argument.
36
+
37
+ Example Rails app initializer using `ENV` variables:
34
38
 
35
39
  ```ruby
36
40
  require 'mail_whitelist'
37
41
 
38
- whitelist = ['tom@brightin.nl']
39
- ActionMailer::Base.register_interceptor(MailWhitelist.new(whitelist)
42
+ if ENV.key?('MAIL_WHITELIST')
43
+ whitelist = ENV['MAIL_WHITELIST'].split(',')
44
+ fallback = ENV['MAIL_WHITELIST_FALLBACK']
45
+ ActionMailer::Base.register_interceptor(MailWhitelist.new(whitelist, fallback))
46
+ end
40
47
  ```
41
48
 
42
49
  ## Development
@@ -13,9 +13,19 @@ class MailWhitelist
13
13
  end
14
14
 
15
15
  def delivering_email(mail)
16
- mail.to = mail.to.select do |recipient|
17
- whitelist.include?(recipient)
18
- end
16
+ mail.to = mail.to.select { |recipient| whitelisted?(recipient) }
19
17
  mail.to = [fallback] unless mail.to.any?
20
18
  end
19
+
20
+ private
21
+
22
+ def whitelisted?(recipient)
23
+ whitelist.any? do |whitelisted_address|
24
+ if whitelisted_address.start_with?('@')
25
+ recipient.end_with?(whitelisted_address)
26
+ else
27
+ whitelisted_address == recipient
28
+ end
29
+ end
30
+ end
21
31
  end
@@ -1,3 +1,3 @@
1
1
  class MailWhitelist
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_whitelist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Kruijsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-16 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.6.8
94
+ rubygems_version: 2.6.13
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Easily whitelist email addresses in your Rails app.