action_recipient 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 8494299046a94fa75e5f75127e0c3854e0af1da065108c7d8c61c39be550e8af
4
- data.tar.gz: a533cd9ad625688c008be2d95d6d493b57e4bc7c584d4168e58e87c999e4e74d
3
+ metadata.gz: '09e845ff355a04ccb8d66af051f105bcf697dce047c27bee099723149f536c01'
4
+ data.tar.gz: 407657879dfd3c599c7be2038f7351448870e10cfac466685779f779055aaf17
5
5
  SHA512:
6
- metadata.gz: 491a5b5e79f2a6fe708239a1d89a4dc0d82ac4e92deac38bbb5f08993151e65f6777dc412d46e055c1cccac0c6d3c27ba880631f3bc0b5cbd154e2b5aff686d5
7
- data.tar.gz: 8f2c371001d334168b1ee11622b4e1104b86ef51eb9e2a1859aaad7d12bf6704c13fbc82bcd29fd7dc1dfa7a0405c9d3abc413be7621538bae7206f4903b0b13
6
+ metadata.gz: ce9cc99d0a6a779738a755a5d35b45e3049681752c565d95425d123cb26de1989087a9abc246258d42faca85c9df4a304663ea0f22bd9899eaa937c089036f75
7
+ data.tar.gz: 277a74702a8d7a73d5e1fb9754584364c95807824742f9971489d5cb2fe0d6e06b3bae11bcdde69df4cfd1f05fbeacc1affdbe0e6d15f8851506e4b4fd25ed88
@@ -3,8 +3,10 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.3.0
7
- - 2.4.0
8
- - 2.5.0
9
- - 2.6.3
10
- before_install: gem install bundler -v 2.0.1
6
+ - 2.3.8
7
+ - 2.4.10
8
+ - 2.5.8
9
+ - 2.6.6
10
+ - 2.7.2
11
+ - 3.0.0
12
+ before_install: gem install bundler
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ ## [0.2.0]
4
+ ### Added
5
+ - Support whitelist for non-filtered addresses and domains
6
+
7
+ ## [0.3.0]
8
+ ### Added
9
+ - Accept regular expression for both whitelist addresses and domains
10
+ - Support Ruby3.0.0 and Ruby2.7.2 (with CI)
data/README.md CHANGED
@@ -4,15 +4,14 @@
4
4
 
5
5
  # ActionRecipient
6
6
 
7
- This gem overwrites email recipients addresses sent by ActionMailer , so that to prevent your application from dispatching emails accidentally to existing addresses, expecially your users or clients in non-production environments.
7
+ This gem dynamically overwrites email recipients addresses sent with ActionMailer.
8
+ With this gem, you no longer have to worry about your application delivering accidental emails to your real customer in non-production environments.
8
9
 
9
- ### IMPORTANT NOTES
10
+ It is particularily helpful if you are using gmail account for your staging mail, as it can append original recipients information in the address. (See [below](#Using Gmail) for details)
10
11
 
11
- * this gem is developed and tested carefully, but it does NOT mean this is 100% reliable. Please use this at your own risks, and test carefully before use.
12
+ * although this gem has been developed and tested carefully, but there is no guarantee that this is 100% reliable. Please use this at your own risks, and test carefully before use.
12
13
 
13
- * It HAS NO EFFECT on the Non-Actionmailer emails (i.e. if the emails are delivered out of ActionMailer's control)
14
-
15
- * for example, if you are sending batch emails directly via Mailgun API, the gem cannot overwrite its addresses - please consider managing recipient addresses on your own.
14
+ * Non-Actionmailer emails cannot be blocked nor redirected, as it works based on ActionMailer's interceptor mechanism.
16
15
 
17
16
  ## Installation
18
17
 
@@ -34,21 +33,41 @@ Or install it yourself as:
34
33
 
35
34
  ### Getting Started
36
35
 
37
- Let's say you want to trap all the emails that are sent out in staging environment. You need to replace outgoing emails' addresses to your work address `your_address_to_redirect@gmail.com`, with a few exception such as `my_personal_adddress@example.com`
36
+ Set up ActionRecipient as follows to prevent outgoing mails in your staging environment.
37
+
38
+ ```ruby
39
+ # config/initializers/action_recipient.rb
40
+
41
+ if Rails.env.staging? # effective only in staging environment
42
+
43
+ ActionRecipient.configure do |config|
44
+ config.format = 'your_address_to_redirect@your_domain.com' # address that the emails to be redirected
45
+ end
46
+
47
+ ActionMailer::Base.register_interceptor(ActionRecipient::Interceptor) # register it as interceptor
48
+ end
49
+ ```
38
50
 
39
- In `config/initializers`, register ActionRecipient as follows:
51
+ If your colleague (in staging environment) accidentally send an email to `admin@your_client.com`, this gem overwrites its addresses as `your_address_to_redirect+admin_at_your_client.com@gmail.com` with help of ActionMailer's interceptor.
52
+
53
+ ### Whitelist
54
+
55
+ Let's say, you wish to trap any outgoing emails, with an exception, e.g. `my_personal_adddress@example.com` that has to be actually delivered without interception.
56
+
57
+ You can' whitelist' such email addresses as follows:
40
58
 
41
59
  ```ruby
42
60
  # config/initializers/action_recipient.rb
43
61
 
44
- if Rails.env.staging? # works only in staging environment
62
+ if Rails.env.staging?
45
63
 
46
64
  ActionRecipient.configure do |config|
47
65
  config.format = 'your_address_to_redirect+%s@gmail.com'
48
66
 
67
+ # specify whitelisted addresses as follows
49
68
  config.whitelist.addresses = [
50
- 'safe_address@example.com',
51
- 'my_personal_adddress@example.com'
69
+ 'safe_address@my-company.com',
70
+ 'my_personal_adddress@my-company.com'
52
71
  ]
53
72
  end
54
73
 
@@ -56,11 +75,51 @@ if Rails.env.staging? # works only in staging environment
56
75
  end
57
76
  ```
58
77
 
59
- Then, if you send an email to `admin@your_client.com` using ActionMailer, this gem traps it and overwrites its addresses as `your_address_to_redirect+admin_at_your_client.com@gmail.com`.
78
+ You can also whitelist all the emails that belong to perticular domain:
79
+
80
+ ```ruby
81
+ ActionRecipient.configure do |config|
82
+ config.whitelist.domains = [
83
+ 'my-company.com'
84
+ ]
85
+ end
86
+ ```
87
+
88
+ Note: With a string matcher, you can whitelist only an address that has perfect match with it. If you prefer to whitelist all the addresses that belong to **any subdomains** under a specific domain, use regular expression instead.
89
+
90
+ ```ruby
91
+ ActionRecipient.configure do |config|
92
+ config.whitelist.domains = [
93
+ 'my-company.com\z'
94
+ ]
95
+ end
96
+ ```
97
+
98
+ This way an address such as `somebody@sales.my-company.com` is whitelisted, thus can deliver an out-going emails without getting trapped.
60
99
 
61
- You can find the email at your mailbox in `your_address_to_redirect@gmail.com`, just as your client would do if it were in production - with the only difference in its `to` address that are slightly modified.
100
+ ### Using Gmail
62
101
 
63
- ### Detailed Settings
102
+ You might wish to keep original recipient addresses somehow, so that you can confirm where the email must have been delivered to unless it gets trapped.
103
+
104
+ This gem accepts a format where `%s` are dynamically replaced with the original address, prefixed with type of destination field (`to`, `cc`, or `bcc`).
105
+
106
+
107
+ ```ruby
108
+ # config/initializers/action_recipient.rb
109
+
110
+ if Rails.env.staging? # effective only in staging environment
111
+
112
+ ActionRecipient.configure do |config|
113
+ config.format = 'your_address_to_redirect+%s@gmail.com' # destination type and original address will be appended after your address
114
+ end
115
+
116
+ ActionMailer::Base.register_interceptor(ActionRecipient::Interceptor)
117
+ end
118
+ ```
119
+
120
+ This feature is particularity useful if you use gmail - as it ignores any strings that follow after a plus (+) sign appended in your address.
121
+
122
+ ## Detailed Settings
64
123
 
65
124
  1. set your "safe address" to indicate ActionRecipient an address to redirect outgoing emails:
66
125
 
@@ -79,13 +138,13 @@ If you add **%s** in the format, it is automatically replaced with the original
79
138
  ```ruby
80
139
  ActionRecipient.configure do |config|
81
140
  config.whitelist.addresses = [
82
- 'my_personal_address@example.com',
83
- 'my_colleagues_address@example.com'
141
+ 'my_colleagues_address@my-workplace.com'
142
+ 'a-contractor@somebody.net',
84
143
  ]
85
144
 
86
145
  config.whitelist.domains = [
87
- 'my_office_domain.com',
88
- 'subdomain.my_office_domain.com'
146
+ 'my-department.my-workplace.com',
147
+ /my-private-domain.com\z/
89
148
  ]
90
149
  end
91
150
  ```
@@ -93,10 +152,12 @@ If you add **%s** in the format, it is automatically replaced with the original
93
152
  Whitelisted emails addresses are not overwritten, thus can be delivered as usual.
94
153
 
95
154
  IMPORTANT:
96
- With current version (version <~ 0.2.0) "domains" are the last part of email addresses after `@`, and matched with original email address literally on word-to-word basis.
155
+ "domains" are the last part of email addresses after `@`, and matched with original email address literally on word-to-word basis.
97
156
 
98
157
  So whitelisted domains such as `bar.com` does NOT whitelist emails to subdomains like `somebody@foo.bar.com` (therefore redirected).
99
158
 
159
+ If you wish to whitelist a domain including all the subdomains under it, use regular expressions as [described earlier](#detailed-settings)
160
+
100
161
  3. register ActionRecipient as the interceptor
101
162
 
102
163
  ```ruby
@@ -124,6 +185,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
124
185
 
125
186
  Bug reports and pull requests are welcome on GitHub at https://github.com/fursich/action_recipient.
126
187
 
188
+ ## Acknoledgement
189
+
190
+ I'd like to thank @akeyhero who came up with the original idea about appending recipient information after plus leveraging gmail feature.
191
+ Although the implementation work is done by myself seperately, this gem greatly benefited from his inspiring idea.
192
+
127
193
  ## License
128
194
 
129
195
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency 'mail', '>= 2.5.4' # to liaise with ActionMailer 4.2 or higher
33
33
 
34
34
  spec.add_development_dependency 'bundler', '~> 2.0'
35
- spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rake', '~> 12.3.3'
36
36
  spec.add_development_dependency 'rspec', '~> 3.0'
37
37
  spec.add_development_dependency 'pry'
38
38
  spec.add_development_dependency 'pry-doc'
@@ -19,7 +19,19 @@ module ActionRecipient
19
19
  end
20
20
 
21
21
  def whitelisted?(email)
22
- whitelist.addresses.include?(email) || whitelist.domains.include?(domain_for(email))
22
+ match_with_any_whitelisted_addresses?(email) || match_with_any_whitelisted_domains?(domain_for(email))
23
+ end
24
+
25
+ def match_with_any_whitelisted_addresses?(email)
26
+ whitelist.addresses.any? { |string_or_regexp|
27
+ string_or_regexp === email
28
+ }
29
+ end
30
+
31
+ def match_with_any_whitelisted_domains?(domain)
32
+ whitelist.domains.any? { |string_or_regexp|
33
+ string_or_regexp === domain
34
+ }
23
35
  end
24
36
 
25
37
  def whitelist
@@ -1,3 +1,3 @@
1
1
  module ActionRecipient
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_recipient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koji Onishi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-26 00:00:00.000000000 Z
11
+ date: 2020-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: 12.3.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: 12.3.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -105,6 +105,7 @@ files:
105
105
  - ".gitignore"
106
106
  - ".rspec"
107
107
  - ".travis.yml"
108
+ - CHANGELOG.md
108
109
  - Gemfile
109
110
  - LICENSE.txt
110
111
  - README.md
@@ -138,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  - !ruby/object:Gem::Version
139
140
  version: '0'
140
141
  requirements: []
141
- rubygems_version: 3.0.3
142
+ rubygems_version: 3.1.4
142
143
  signing_key:
143
144
  specification_version: 4
144
145
  summary: Overwrites email recipients with ActionMailer emails to prevent accidental