mailsafe 0.0.1 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/README.md +31 -5
- data/lib/mailsafe.rb +3 -2
- data/lib/mailsafe/receipient_whitelist.rb +11 -3
- data/lib/mailsafe/version.rb +1 -1
- data/mailsafe.gemspec +1 -0
- data/spec/receipient_whitelist_spec.rb +61 -0
- data/spec/spec_helper.rb +16 -0
- metadata +23 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 047172ca62085b8affb85a38a9ffa18123dc8589
|
4
|
+
data.tar.gz: a07b0d33e190716d9d4076f90dc41ea9fa08726d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c494132d2bd2f9ba140c836a689f713b51b01cb4a78fad6e4169c8ccaa52c6944bddf0b9decf32327eeb190bb355c12c04e23f07b1de16faf33442a4da1d094e
|
7
|
+
data.tar.gz: 2924839ee61347f45107c12dd5af6e651deb196011144fc5d18b7d40726a7ffbec67fe133d8da534272be97c11b62b270e213203e43180d73a15eca75bbe97b5
|
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
[](https://codeclimate.com/github/stemps/mailsafe)
|
1
2
|
# Mailsafe
|
2
3
|
|
3
|
-
|
4
|
+
Safe emailing for Rails. Prevents you from sending emails to real customers from non-production environments. You can choose to either re-route all emails to a single developer account or allow only recipients of your own domain.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -12,13 +13,38 @@ And then execute:
|
|
12
13
|
|
13
14
|
$ bundle
|
14
15
|
|
15
|
-
|
16
|
+
## Usage
|
16
17
|
|
17
|
-
|
18
|
+
You can re-route all emails to your developer email account by adding this your _development.rb_ file
|
18
19
|
|
19
|
-
|
20
|
+
```ruby
|
21
|
+
Mailsafe.setup do |config|
|
22
|
+
config.override_receiver = "developer@devco.com"
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
The email subjects will be delivered to your account and prefixed with the original receiver in square brackets.
|
27
|
+
|
28
|
+
|
29
|
+
You can send emails to the intended recipients but only to a whitelist of receipient domains (e.g. helpful for a staging environment where you want to send emails to your company's and your client's domain)
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Mailsafe.setup do |config|
|
33
|
+
config.allowed_domain = "devco.com, clientco.com"
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
If you are running multiple environments with _mailsafe_ it can help to know which environment an email came from. You can have _mailsafe_ prefix the subject line with _[environment name]_
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
config.prefix_email_subject_with_rails_env = true
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
## Caveat
|
45
|
+
|
46
|
+
In order to filter (as in not send) emails I had to monkey patch the Mail#deliver method. If this makes you feel uneasy, better try out a different solution.
|
20
47
|
|
21
|
-
TODO: Write usage instructions here
|
22
48
|
|
23
49
|
## Contributing
|
24
50
|
|
data/lib/mailsafe.rb
CHANGED
@@ -14,8 +14,9 @@ module Mailsafe
|
|
14
14
|
mattr_accessor :prefix_email_subject_with_rails_env
|
15
15
|
@@prefix_email_subject_with_rails_env = false
|
16
16
|
|
17
|
-
# specify
|
18
|
-
# If empty, all emails are allowed to all
|
17
|
+
# specify one or more domains (comma separated) that are allowed to receive emails all emails
|
18
|
+
# to other domains are dropped. If empty, all emails are allowed to all
|
19
|
+
# domains
|
19
20
|
mattr_accessor :allowed_domain
|
20
21
|
@@allowed_domain = nil
|
21
22
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'mailsafe/receipient_whitelist'
|
2
|
+
|
1
3
|
module Mailsafe
|
2
4
|
class ReceipientWhitelist
|
3
5
|
def self.filter_receipient_domain(message)
|
@@ -13,9 +15,15 @@ module Mailsafe
|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
def self.email_has_domain?(email,
|
17
|
-
|
18
|
-
email_domain
|
18
|
+
def self.email_has_domain?(email, allowed_domain_config)
|
19
|
+
allowed_domains = allowed_domain_config.split(',').map(&:strip).map(&:downcase)
|
20
|
+
email_domain = email.split("@")[1]
|
21
|
+
|
22
|
+
if email_domain.present?
|
23
|
+
allowed_domains.include? email_domain.downcase
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
data/lib/mailsafe/version.rb
CHANGED
data/mailsafe.gemspec
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mailsafe
|
4
|
+
RSpec.describe ReceipientWhitelist do
|
5
|
+
|
6
|
+
describe ".email_has_domain" do
|
7
|
+
context "single whitelisted domain" do
|
8
|
+
let!(:whitelist) { "gmail.com" }
|
9
|
+
|
10
|
+
it "accepts the allowed domains" do
|
11
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@gmail.com", whitelist)).to be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "does not accept other domains" do
|
15
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@gmx.de", whitelist)).to be_false
|
16
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@yahoo.com", whitelist)).to be_false
|
17
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@ggmail.com", whitelist)).to be_false
|
18
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@gmail.com.de", whitelist)).to be_false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "multiple whitelisted domains" do
|
23
|
+
let!(:whitelist) { "gmail.com, gmx.de" }
|
24
|
+
|
25
|
+
it "accepts the allowed domains" do
|
26
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@gmail.com", whitelist)).to be_true
|
27
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@gmx.de", whitelist)).to be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "does not accept other domains" do
|
31
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@yahoo.com", whitelist)).to be_false
|
32
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@ggmail.com", whitelist)).to be_false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "invalid email addresses" do
|
37
|
+
let!(:whitelist) { "gmail.com" }
|
38
|
+
|
39
|
+
it "does not accept them" do
|
40
|
+
expect(ReceipientWhitelist.email_has_domain?("bert", whitelist)).to be_false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "invalid whitelist" do
|
45
|
+
let!(:whitelist) { "gmail.com, " }
|
46
|
+
|
47
|
+
it "accepts the allowed domains" do
|
48
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@gmail.com", whitelist)).to be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does not accept other domains" do
|
52
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@gmx.de", whitelist)).to be_false
|
53
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@yahoo.com", whitelist)).to be_false
|
54
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@ggmail.com", whitelist)).to be_false
|
55
|
+
expect(ReceipientWhitelist.email_has_domain?("bert@gmail.com.de", whitelist)).to be_false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'mailsafe'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
|
11
|
+
# Run specs in random order to surface order dependencies. If you find an
|
12
|
+
# order dependency and want to debug it, you can fix the order by providing
|
13
|
+
# the seed, which is printed after each run.
|
14
|
+
# --seed 1234
|
15
|
+
config.order = 'random'
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailsafe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Stemplinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.13.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.1.5
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.1.5
|
55
69
|
description: Safe emailing for Rails
|
56
70
|
email:
|
57
71
|
- simon@simon-stemplinger.com
|
@@ -60,6 +74,7 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- .gitignore
|
77
|
+
- .rspec
|
63
78
|
- Gemfile
|
64
79
|
- LICENSE.txt
|
65
80
|
- README.md
|
@@ -71,6 +86,8 @@ files:
|
|
71
86
|
- lib/mailsafe/reroute_interceptor.rb
|
72
87
|
- lib/mailsafe/version.rb
|
73
88
|
- mailsafe.gemspec
|
89
|
+
- spec/receipient_whitelist_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
74
91
|
homepage: https://github.com/stemps/mailsafe
|
75
92
|
licenses:
|
76
93
|
- MIT
|
@@ -91,9 +108,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
108
|
version: '0'
|
92
109
|
requirements: []
|
93
110
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.0.
|
111
|
+
rubygems_version: 2.0.3
|
95
112
|
signing_key:
|
96
113
|
specification_version: 4
|
97
114
|
summary: Safe emailing for Rails - do not send emails to real users from development
|
98
115
|
or staging environments.
|
99
|
-
test_files:
|
116
|
+
test_files:
|
117
|
+
- spec/receipient_whitelist_spec.rb
|
118
|
+
- spec/spec_helper.rb
|