mailsafe 0.0.1 → 0.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: 95e24ee796ff9c2f23aa366db6de505e63da5a1d
4
- data.tar.gz: 498a064060077b814f47b880e694e021fdd03ccb
3
+ metadata.gz: 047172ca62085b8affb85a38a9ffa18123dc8589
4
+ data.tar.gz: a07b0d33e190716d9d4076f90dc41ea9fa08726d
5
5
  SHA512:
6
- metadata.gz: 6893733905424132968b26449321d94ac3f5ab3dce01e67f89fa2190b7302939b5a5a6b8d2d7f914e4b18d13e6fb24dd9a094f238dfccdffeb8c042aac40b374
7
- data.tar.gz: d2c3c5f796ade3d98353feb26efec2839544c3844c0ba7bcfea9044a22fb166f7586b08387e087fdbed80c2c8dd380dd24294816c0c20bc6c0460210ade27e66
6
+ metadata.gz: c494132d2bd2f9ba140c836a689f713b51b01cb4a78fad6e4169c8ccaa52c6944bddf0b9decf32327eeb190bb355c12c04e23f07b1de16faf33442a4da1d094e
7
+ data.tar.gz: 2924839ee61347f45107c12dd5af6e651deb196011144fc5d18b7d40726a7ffbec67fe133d8da534272be97c11b62b270e213203e43180d73a15eca75bbe97b5
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
+ [![Code Climate](https://codeclimate.com/github/stemps/mailsafe.png)](https://codeclimate.com/github/stemps/mailsafe)
1
2
  # Mailsafe
2
3
 
3
- TODO: Write a gem description
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
- Or install it yourself as:
16
+ ## Usage
16
17
 
17
- $ gem install mailsafe
18
+ You can re-route all emails to your developer email account by adding this your _development.rb_ file
18
19
 
19
- ## Usage
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
 
@@ -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 a domain that is allowed to receive emails all emails to other domains are dropped.
18
- # If empty, all emails are allowed to all domains
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, domain)
17
- email_domain = email.split("@").second
18
- email_domain.downcase == domain.downcase
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
@@ -1,3 +1,3 @@
1
1
  module Mailsafe
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec", "~> 2.13.0"
24
+ spec.add_development_dependency "rails", "~> 4.1.5"
24
25
  end
@@ -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
@@ -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.1
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: 2013-04-30 00:00:00.000000000 Z
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.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