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 +4 -4
- data/README.md +13 -6
- data/lib/mail_whitelist.rb +13 -3
- data/lib/mail_whitelist/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73f90ae5ab23f0a6ee9d6adb00a1643345464d6e
|
4
|
+
data.tar.gz: f4896faf865420c8caa3032960df2b56acff4716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
11
|
-
for its existence and use it to instantiate
|
12
|
-
|
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
|
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
|
-
|
39
|
-
|
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
|
data/lib/mail_whitelist.rb
CHANGED
@@ -13,9 +13,19 @@ class MailWhitelist
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def delivering_email(mail)
|
16
|
-
mail.to = mail.to.select
|
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
|
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.
|
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:
|
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.
|
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.
|