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 +4 -4
- data/.travis.yml +7 -5
- data/CHANGELOG.md +10 -0
- data/README.md +85 -19
- data/action_recipient.gemspec +1 -1
- data/lib/action_recipient/rewriter.rb +13 -1
- data/lib/action_recipient/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09e845ff355a04ccb8d66af051f105bcf697dce047c27bee099723149f536c01'
|
4
|
+
data.tar.gz: 407657879dfd3c599c7be2038f7351448870e10cfac466685779f779055aaf17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce9cc99d0a6a779738a755a5d35b45e3049681752c565d95425d123cb26de1989087a9abc246258d42faca85c9df4a304663ea0f22bd9899eaa937c089036f75
|
7
|
+
data.tar.gz: 277a74702a8d7a73d5e1fb9754584364c95807824742f9971489d5cb2fe0d6e06b3bae11bcdde69df4cfd1f05fbeacc1affdbe0e6d15f8851506e4b4fd25ed88
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -4,15 +4,14 @@
|
|
4
4
|
|
5
5
|
# ActionRecipient
|
6
6
|
|
7
|
-
This gem overwrites email recipients addresses sent
|
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
|
-
|
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
|
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
|
-
*
|
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
|
-
|
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
|
-
|
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?
|
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@
|
51
|
-
'my_personal_adddress@
|
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
|
-
|
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
|
-
|
100
|
+
### Using Gmail
|
62
101
|
|
63
|
-
|
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
|
-
'
|
83
|
-
'
|
141
|
+
'my_colleagues_address@my-workplace.com'
|
142
|
+
'a-contractor@somebody.net',
|
84
143
|
]
|
85
144
|
|
86
145
|
config.whitelist.domains = [
|
87
|
-
'
|
88
|
-
|
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
|
-
|
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).
|
data/action_recipient.gemspec
CHANGED
@@ -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', '~>
|
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
|
-
|
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
|
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.
|
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:
|
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:
|
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:
|
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.
|
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
|