mail_allowed 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: adee71efbd21ad0aad2a00ef1a143641068e891d70f4d6b49f8d5be0206f1ac1
4
+ data.tar.gz: 5c422b58261eac4d0f82f28a2f942e71b4b7c4c1d9b27113eac802e06ebef989
5
+ SHA512:
6
+ metadata.gz: a2ce06a9f60904593117ecb978107da1a2ce74802c729a5b9b5c1b534cb3858651af6cd9881afd87ed5fc26b45e3877cb9165e9c6f869ff1936dd219a4c19e17
7
+ data.tar.gz: 1bfd4b951fcb518d080025384d92b45ae54f8514a4ae89c26f4976c28ec2ce3132faf3b30c67593eba17e012c1bdb30ee1340e2a704d9f1ee6cb96ceeb78c075
@@ -0,0 +1,45 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ parallelism: 1
5
+ working_directory: ~/ezcater
6
+ docker:
7
+ - image: circleci/ruby:2.5.7
8
+ steps:
9
+ - checkout
10
+
11
+ # Restore bundle cache
12
+ - restore_cache:
13
+ keys:
14
+ - ruby-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "mail_allowed.gemspec" }}
15
+ - ruby-cache-{{ arch }}-{{ .Branch }}-
16
+ - ruby-cache-
17
+
18
+ - run:
19
+ name: Setup Code Climate test-reporter
20
+ command: |
21
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 -o ./cc-test-reporter
22
+ chmod +x ./cc-test-reporter
23
+
24
+ # Bundle install dependencies
25
+ - run: gem install bundler -v 1.17.3 --no-document
26
+ - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
27
+ - run: bundle clean --force
28
+
29
+ # Store bundle cache
30
+ - save_cache:
31
+ key: ruby-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "mail_allowed.gemspec" }}
32
+ paths:
33
+ - vendor/bundle
34
+
35
+ # Run Rubocop
36
+ # - run:
37
+ # name: RuboCop
38
+ # command: bundle exec rubocop
39
+
40
+ - run:
41
+ name: rspec
42
+ command: |
43
+ ./cc-test-reporter before-build
44
+ bundle exec rspec --format RspecJunitFormatter --format progress
45
+ ./cc-test-reporter after-build -t simplecov || exit 0
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ # mail_allowed
2
+
3
+ ## v1.0.0
4
+ - Initial release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mail_allowed.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Brightin, Copyright (c) 2020 ezCater
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # MailAllowed
2
+
3
+ This gem is a renamed fork of an [existing gem](https://github.com/brightin/mail_whitelist).
4
+
5
+ MailAllowed is a class you can provide as an
6
+ [interceptor](http://guides.rubyonrails.org/action_mailer_basics.html#intercepting-emails)
7
+ to your Rails app. It ensures only some people are able to receive mails from
8
+ your app and provides a fallback in case nobody would receive the mail. This
9
+ can be useful to make sure no accidental emails are sent from your staging
10
+ environment, but your mails can still be checked.
11
+
12
+ One way to use it is to set an environment variable `MAIL_ALLOWED`, check
13
+ for its existence and use it to instantiate a `MailAllowed` so that within
14
+ this environment only those email addresses can have mail sent to them.
15
+ See below for a code example.
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'mail_allowed'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install mail_allowed
32
+
33
+ ## Usage
34
+
35
+ Specify your allowed as an array of email addresses and register them in an
36
+ initializer in your Rails app. Optionally specify a fallback address as second
37
+ argument.
38
+
39
+ Example Rails app initializer using `ENV` variables:
40
+
41
+ ```ruby
42
+ require 'mail_allowed'
43
+
44
+ if ENV.key?('MAIL_ALLOWED')
45
+ allowed_addresses = ENV['MAIL_ALLOWED'].split(',')
46
+ fallback = ENV['MAIL_ALLOWED_FALLBACK']
47
+ ActionMailer::Base.register_interceptor(MailAllowed.new(allowed_addresses, fallback))
48
+ end
49
+ ```
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ezcater/mail_allowed.
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mail_allowed'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ require 'mail_allowed/version'
2
+
3
+ # Filter mails with a specific allowed e-mail addresses and only leaves
4
+ # those in the 'to'.
5
+ class MailAllowed
6
+ attr_reader :allowed_addresses, :fallback
7
+
8
+ # @param [Array<String>, #include?] allowed_addresses
9
+ # @param [String] fallback
10
+ def initialize(allowed_addresses, fallback = nil)
11
+ @allowed_addresses = allowed_addresses
12
+ @fallback = fallback
13
+ end
14
+
15
+ def delivering_email(mail)
16
+ mail.to = mail.to.select { |recipient| allowed?(recipient) }
17
+ mail.to = [fallback] unless mail.to.any?
18
+ end
19
+
20
+ private
21
+
22
+ def allowed?(recipient)
23
+ allowed_addresses.any? do |address|
24
+ if address.start_with?('@')
25
+ recipient.end_with?(address)
26
+ else
27
+ address == recipient
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ class MailAllowed
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mail_allowed/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mail_allowed'
8
+ spec.version = MailAllowed::VERSION
9
+ spec.authors = ['ezCater Inc']
10
+ spec.email = ['engineering@ezcater.com']
11
+
12
+ spec.summary = 'Easily specify the allowed email addresses in your Rails app.'
13
+ spec.homepage = 'https://www.github.com/ezcater/mail_allowed'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.13'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency "rspec_junit_formatter"
25
+ spec.add_development_dependency "simplecov", "< 0.18.0"
26
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mail_allowed
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ezCater Inc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.18.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.18.0
83
+ description:
84
+ email:
85
+ - engineering@ezcater.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".circleci/config.yml"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - CHANGELOG.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/mail_allowed.rb
101
+ - lib/mail_allowed/version.rb
102
+ - mail_allowed.gemspec
103
+ homepage: https://www.github.com/ezcater/mail_allowed
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.0.6
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Easily specify the allowed email addresses in your Rails app.
126
+ test_files: []