sanitize_email 1.1.7 → 1.2.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 +13 -8
- data/CHANGELOG.md +5 -0
- data/README.md +138 -119
- data/gemfiles/Gemfile.rails-3.0.x +1 -0
- data/gemfiles/Gemfile.rails-3.1.x +1 -0
- data/gemfiles/Gemfile.rails-3.2.x +3 -0
- data/gemfiles/Gemfile.rails-4.0.x +3 -0
- data/gemfiles/Gemfile.rails-4.1.x +3 -0
- data/lib/sanitize_email/bleach.rb +55 -29
- data/lib/sanitize_email/config.rb +1 -1
- data/lib/sanitize_email/deprecation.rb +1 -1
- data/lib/sanitize_email/engine.rb +2 -2
- data/lib/sanitize_email/mail_header_tools.rb +1 -1
- data/lib/sanitize_email/overridden_addresses.rb +1 -1
- data/lib/sanitize_email/railtie.rb +3 -3
- data/lib/sanitize_email/rspec_matchers.rb +1 -1
- data/lib/sanitize_email/test_helpers.rb +1 -1
- data/lib/sanitize_email/version.rb +2 -2
- data/lib/sanitize_email.rb +2 -2
- data/sanitize_email.gemspec +1 -0
- data/spec/sanitize_email_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f2dcec848cb80945d5c1e1401891002dc28fb62
|
4
|
+
data.tar.gz: b1b05a2965281e341720c78ceac9b66e10cdbf71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0755c678a8004229ee7f5368798bfe5f33c5ab55170a99b4b8ebb65d2132b8d99bade1ab6e448df6b556c3eca9582e93a667c5ada1799b0bb1b03030677b266d
|
7
|
+
data.tar.gz: ad9ae2126562b3beec645ca2cc2bb48d233cf5cbd1013162c60c509ebfe0c3dcf685a009954db92b259593a0a754c2f4d6f3ff322be666fc3d75e2c4a75e2e5d
|
data/.travis.yml
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
sudo: false
|
2
4
|
rvm:
|
3
|
-
- 2.0
|
4
|
-
- 2.1
|
5
|
-
- 2.2
|
5
|
+
- 2.0
|
6
|
+
- 2.1
|
7
|
+
- 2.2
|
8
|
+
- ruby-head
|
6
9
|
gemfile:
|
7
10
|
- gemfiles/Gemfile.rails-3.2.x
|
8
11
|
- gemfiles/Gemfile.rails-4.0.x
|
9
12
|
- gemfiles/Gemfile.rails-4.1.x
|
10
13
|
- gemfiles/Gemfile.rails-4.2.x
|
11
14
|
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: ruby-head
|
17
|
+
- rvm: 1.9
|
12
18
|
exclude:
|
13
|
-
- rvm: 2.0
|
19
|
+
- rvm: 2.0
|
14
20
|
gemfile: gemfiles/Gemfile.rails-4.2.x
|
15
|
-
- rvm: 2.1
|
21
|
+
- rvm: 2.1
|
16
22
|
gemfile: gemfiles/Gemfile.rails-4.2.x
|
17
|
-
matrix:
|
18
23
|
include:
|
19
|
-
- rvm: 1.9
|
24
|
+
- rvm: 1.9
|
20
25
|
gemfile: gemfiles/Gemfile.rails-3.0.x
|
21
|
-
- rvm: 1.9
|
26
|
+
- rvm: 1.9
|
22
27
|
gemfile: gemfiles/Gemfile.rails-3.1.x
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
HEAD
|
2
2
|
|
3
|
+
Version 1.2.0- JUL.24.2016
|
4
|
+
* No longer registers instance of SanitizeEmail::Bleach to avoid the dev env reloading problem (fixes #12)
|
5
|
+
* Instead registers SanitizeEmail::Bleach class.
|
6
|
+
* Deprecate sending arguments to SanitizeEmail::Bleach.new
|
7
|
+
|
3
8
|
Version 1.1.7 - AUG.30.2015
|
4
9
|
* No API changes
|
5
10
|
* General improvement to the code base by Peter Boling
|
data/README.md
CHANGED
@@ -6,17 +6,18 @@ This gem allows you to override your mail delivery settings, globally or in a lo
|
|
6
6
|
|------------------------ | ----------------- |
|
7
7
|
| gem name | sanitize_email |
|
8
8
|
| license | MIT |
|
9
|
-
|
|
10
|
-
|
|
9
|
+
| expert support | [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github) |
|
10
|
+
| download rank | [![Total Downloads](https://img.shields.io/gem/rt/sanitize_email.svg)](https://rubygems.org/gems/sanitize_email) |
|
11
|
+
| version | [![Version](https://img.shields.io/gem/v/sanitize_email.svg)](https://rubygems.org/gems/sanitize_email) |
|
11
12
|
| dependencies | [![Dependency Status](https://gemnasium.com/pboling/sanitize_email.png)](https://gemnasium.com/pboling/sanitize_email) |
|
12
|
-
| code quality | [![Code
|
13
|
-
| inline documenation | [![
|
14
|
-
| continuous integration | [![Build
|
13
|
+
| code quality | [![Code Quality](https://img.shields.io/codeclimate/github/pboling/sanitize_email.svg)](https://codeclimate.com/github/pboling/sanitize_email) |
|
14
|
+
| inline documenation | [![Documentation](http://inch-ci.org/github/pboling/sanitize_email.png)](http://inch-ci.org/github/pboling/sanitize_email) |
|
15
|
+
| continuous integration | [![Build](https://img.shields.io/travis/pboling/sanitize_email.svg)](https://travis-ci.org/pboling/sanitize_email) |
|
15
16
|
| test coverage | [![Coverage Status](https://coveralls.io/repos/pboling/sanitize_email/badge.png)](https://coveralls.io/r/pboling/sanitize_email) |
|
16
|
-
| homepage | [
|
17
|
+
| homepage | [http://www.railsbling.com/tags/sanitize_email/][homepage] |
|
17
18
|
| documentation | [http://rdoc.info/github/pboling/sanitize_email/frames][documentation] |
|
18
|
-
|
|
19
|
-
| Spread ~♡ⓛⓞⓥⓔ♡~ | [
|
19
|
+
| live chat | [![Join the chat at https://gitter.im/pboling/sanitize_email](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pboling/sanitize_email?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
|
20
|
+
| Spread ~♡ⓛⓞⓥⓔ♡~ | [on Coderbits](https://coderbits.com/pboling), [on Coderwall](http://coderwall.com/pboling) |
|
20
21
|
|
21
22
|
## Summary
|
22
23
|
|
@@ -58,41 +59,47 @@ SanitizeEmail comes with some lightweight RspecMatchers covering most of what em
|
|
58
59
|
|
59
60
|
In Gemfile:
|
60
61
|
|
61
|
-
|
62
|
+
```ruby
|
63
|
+
gem 'sanitize_email'
|
64
|
+
```
|
62
65
|
|
63
66
|
Then:
|
64
67
|
|
65
|
-
|
68
|
+
```bash
|
69
|
+
$ bundle install
|
70
|
+
```
|
66
71
|
|
67
72
|
## Setup with Ruby
|
68
73
|
|
69
74
|
*keep scrolling for Rails, but read this for a better understanding of Magic*
|
70
75
|
|
71
|
-
There are
|
72
|
-
|
73
|
-
1. Only useful for local context. Inside a method where you will be sending an email, set SanitizeEmail.force_sanitize = true just prior to delivering it. Also useful in the console.
|
74
|
-
|
75
|
-
SanitizeEmail.force_sanitize = true # by default it is nil
|
76
|
+
There are three ways SanitizeEmail can be turned on; in order of precedence they are:
|
76
77
|
|
77
|
-
|
78
|
+
1. Only useful for local context. Inside a method where you will be sending an email, set `SanitizeEmail.force_sanitize = true` just prior to delivering it. Also useful in the console.
|
78
79
|
|
79
|
-
|
80
|
+
```ruby
|
81
|
+
SanitizeEmail.force_sanitize = true # by default it is nil
|
82
|
+
```
|
80
83
|
|
81
|
-
|
84
|
+
2. If SanitizeEmail seems to not be sanitizing you have probably not registered the interceptor. SanitizeEmail tries to do this for you. *Note*: If you are working in an environment that has a Mail or Mailer class that uses the register_interceptor API, the interceptor will already have been registered by SanitizeEmail:
|
82
85
|
|
83
|
-
|
86
|
+
```ruby
|
87
|
+
# The gem will probably have already done this for you, but some really old versions of Rails may need you to do this manually:
|
88
|
+
Mail.register_interceptor(SanitizeEmail::Bleach)
|
89
|
+
```
|
84
90
|
|
85
|
-
|
91
|
+
Once registered, SanitizeEmail needs to be engaged:
|
86
92
|
|
87
|
-
|
93
|
+
```ruby
|
94
|
+
# in config/initializers/sanitize_email.rb
|
95
|
+
SanitizeEmail::Config.configure {|config| config[:engage] = true }
|
96
|
+
```
|
88
97
|
|
89
|
-
3. If you don't need to compute anything, then don't use this option, go with the
|
98
|
+
3. If you don't need to compute anything, then don't use this option, go with the previous option.
|
90
99
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
SanitizeEmail::Config.configure {|config| config[:engage] = true } # by default :engage is nil
|
100
|
+
```ruby
|
101
|
+
SanitizeEmail::Config.configure {|config| config[:activation_proc] = Proc.new { true } } # by default :activation_proc is false
|
102
|
+
```
|
96
103
|
|
97
104
|
### Notes
|
98
105
|
|
@@ -103,7 +110,11 @@ If installed but not configured, sanitize_email DOES NOTHING. Until configured
|
|
103
110
|
|
104
111
|
IMPORTANT: You may need to setup your own register_interceptor. If sanitize_email doesn't seem to be working for you find your Mailer/Mail class and try this:
|
105
112
|
|
106
|
-
|
113
|
+
```ruby
|
114
|
+
# in config/initializers/sanitize_email.rb
|
115
|
+
Mail.register_interceptor(SanitizeEmail::Bleach)
|
116
|
+
SanitizeEmail::Config.configure {|config| config[:engage] = true }
|
117
|
+
```
|
107
118
|
|
108
119
|
If that causes an error you will know why sanitize_email doesn't work.
|
109
120
|
Otherwise it will start working according to the rest of the configuration.
|
@@ -112,7 +123,7 @@ Otherwise it will start working according to the rest of the configuration.
|
|
112
123
|
|
113
124
|
Create an initializer, if you are using rails, or otherwise configure:
|
114
125
|
|
115
|
-
```
|
126
|
+
```ruby
|
116
127
|
SanitizeEmail::Config.configure do |config|
|
117
128
|
config[:sanitized_to] = 'to@sanitize_email.org'
|
118
129
|
config[:sanitized_cc] = 'cc@sanitize_email.org'
|
@@ -133,7 +144,7 @@ Let's say you have a method in your model that you can call to test the signup e
|
|
133
144
|
|
134
145
|
To override the environment based switch use `force_sanitize`, which is normally `nil`, and ignored by default. When set to `true` or `false` it will turn sanitization on or off:
|
135
146
|
|
136
|
-
```
|
147
|
+
```ruby
|
137
148
|
SanitizeEmail.force_sanitize = true
|
138
149
|
```
|
139
150
|
|
@@ -141,7 +152,7 @@ There are also two methods that take a block and turn SanitizeEmail on or off:
|
|
141
152
|
|
142
153
|
Regardless of the Config settings of SanitizeEmail you can do a local override to force unsanitary email in any environment.
|
143
154
|
|
144
|
-
```
|
155
|
+
```ruby
|
145
156
|
SanitizeEmail.unsanitary do
|
146
157
|
Mail.deliver do
|
147
158
|
from 'from@example.org'
|
@@ -154,9 +165,9 @@ Regardless of the Config settings of SanitizeEmail you can do a local override t
|
|
154
165
|
|
155
166
|
Regardless of the Config settings of SanitizeEmail you can do a local override to send sanitary email in any environment.
|
156
167
|
You have access to all the same configuration options in the parameter hash as you can set in the actual
|
157
|
-
SanitizeEmail.configure block.
|
168
|
+
`SanitizeEmail.configure` block.
|
158
169
|
|
159
|
-
```
|
170
|
+
```ruby
|
160
171
|
SanitizeEmail.sanitary({:sanitized_to => 'boo@example.com'}) do # these config options are merged with the globals
|
161
172
|
Mail.deliver do
|
162
173
|
from 'from@example.org'
|
@@ -173,114 +184,128 @@ SanitizeEmail.configure block.
|
|
173
184
|
|
174
185
|
In your `spec_helper.rb`:
|
175
186
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
187
|
+
```ruby
|
188
|
+
require 'sanitize_email'
|
189
|
+
# rspec matchers are *not* loaded by default in sanitize_email, as it is not primarily a gem for test suites.
|
190
|
+
require 'sanitize_email/rspec_matchers'
|
191
|
+
|
192
|
+
SanitizeEmail::Config.configure do |config|
|
193
|
+
config[:sanitized_to] = 'sanitize_email@example.org'
|
194
|
+
config[:sanitized_cc] = 'sanitize_email@example.org'
|
195
|
+
config[:sanitized_bcc] = 'sanitize_email@example.org'
|
196
|
+
# run/call whatever logic should turn sanitize_email on and off in this Proc.
|
197
|
+
# config[:activation_proc] = Proc.new { true }
|
198
|
+
# Since this configuration is *inside* the spec_helper, it might be assumed that we always want to sanitize. If we don't want to it can be easily manipulated with SanitizeEmail.unsanitary and SanitizeEmail.sanitary block helpers.
|
199
|
+
# Thus instead of using the Proc (slower) we just engage it always:
|
200
|
+
config[:engage] = true
|
201
|
+
config[:use_actual_email_prepended_to_subject] = true # or false
|
202
|
+
config[:use_actual_environment_prepended_to_subject] = true # or false
|
203
|
+
config[:use_actual_email_as_sanitized_user_name] = true # or false
|
204
|
+
end
|
205
|
+
|
206
|
+
# If your mail system is not one that sanitize_email automatically configures an interceptor for (ActionMailer, Mail)
|
207
|
+
# then you will need to do the equivalent for whatever Mail system you are using.
|
208
|
+
|
209
|
+
RSpec.configure do |config|
|
210
|
+
# ...
|
211
|
+
# From sanitize_email gem
|
212
|
+
config.include SanitizeEmail::RspecMatchers
|
213
|
+
end
|
214
|
+
|
215
|
+
context "an email test" do
|
216
|
+
subject { Mail.deliver(@message_hash) }
|
217
|
+
it { should have_to "sanitize_email@example.org" }
|
218
|
+
end
|
219
|
+
```
|
207
220
|
|
208
221
|
#### have_* matchers
|
209
222
|
|
210
223
|
These will look for an email address in any of the following
|
211
224
|
|
212
|
-
|
225
|
+
```ruby
|
226
|
+
:from, :to, :cc, :bcc, :subject, :reply_to
|
227
|
+
```
|
213
228
|
|
214
229
|
Example:
|
215
230
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
231
|
+
```ruby
|
232
|
+
context "the subject line must have the email address sanitize_email@example.org" do
|
233
|
+
subject { Mail.deliver(@message_hash) }
|
234
|
+
it { should have_subject "sanitize_email@example.org" }
|
235
|
+
end
|
236
|
+
```
|
220
237
|
|
221
238
|
#### be_* matchers
|
222
239
|
|
223
240
|
These will look for a matching string in any of the following
|
224
241
|
|
225
|
-
|
242
|
+
```ruby
|
243
|
+
:from, :to, :cc, :bcc, :subject, :reply_to
|
244
|
+
```
|
226
245
|
|
227
246
|
Example:
|
228
247
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
248
|
+
```ruby
|
249
|
+
context "the subject line must have the string 'foobarbaz'" do
|
250
|
+
subject { Mail.deliver(@message_hash) }
|
251
|
+
it { should be_subject "foobarbaz" }
|
252
|
+
end
|
253
|
+
```
|
233
254
|
|
234
255
|
#### have_to_username matcher
|
235
256
|
|
236
257
|
The `username` in the `:to` field is when the `:to` field is formatted like this:
|
237
258
|
|
238
|
-
|
259
|
+
`Peter Boling <sanitize_email@example.org>`
|
239
260
|
|
240
261
|
Example:
|
241
262
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
263
|
+
```ruby
|
264
|
+
context "the to field must have the username 'Peter Boling'" do
|
265
|
+
subject { Mail.deliver(@message_hash) }
|
266
|
+
it { should have_to_username "Peter Boling" }
|
267
|
+
end
|
268
|
+
```
|
246
269
|
|
247
270
|
### non-rspec (Test::Unit, mini-test, etc)
|
248
271
|
|
249
272
|
In your setup file:
|
250
273
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
274
|
+
```ruby
|
275
|
+
require 'sanitize_email'
|
276
|
+
# test helpers are *not* loaded by default in sanitize_email, as it is not primarily a gem for test suites.
|
277
|
+
require 'sanitize_email/test_helpers'
|
278
|
+
|
279
|
+
SanitizeEmail::Config.configure do |config|
|
280
|
+
config[:sanitized_to] = 'sanitize_email@example.org'
|
281
|
+
config[:sanitized_cc] = 'sanitize_email@example.org'
|
282
|
+
config[:sanitized_bcc] = 'sanitize_email@example.org'
|
283
|
+
# run/call whatever logic should turn sanitize_email on and off in this Proc.
|
284
|
+
# config[:activation_proc] = Proc.new { true }
|
285
|
+
# Since this configuration is *inside* the spec_helper, it might be assumed that we always want to sanitize. If we don't want to it can be easily manipulated with SanitizeEmail.unsanitary and SanitizeEmail.sanitary block helpers.
|
286
|
+
# Thus instead of using the Proc (slower) we just engage it always:
|
287
|
+
config[:engage] = true
|
288
|
+
config[:use_actual_email_prepended_to_subject] = true # or false
|
289
|
+
config[:use_actual_environment_prepended_to_subject] = true # or false
|
290
|
+
config[:use_actual_email_as_sanitized_user_name] = true # or false
|
291
|
+
end
|
292
|
+
|
293
|
+
# If your mail system is not one that sanitize_email automatically configures an interceptor for (ActionMailer, Mail)
|
294
|
+
# then you will need to do the equivalent for whatever Mail system you are using.
|
295
|
+
|
296
|
+
# You need to know what to do here... somehow get the methods into rhw scope of your tests.
|
297
|
+
# Something like this maybe?
|
298
|
+
include SanitizeEmail::TestHelpers
|
299
|
+
# Look here to see what it gives you:
|
300
|
+
# https://github.com/pboling/sanitize_email/blob/master/lib/sanitize_email/test_helpers.rb
|
301
|
+
```
|
277
302
|
|
278
303
|
## Deprecations
|
279
304
|
|
280
305
|
Sometimes things get deprecated (meaning they still work, but are noisy about it). If this happens to you, and you like your head in the sand, call this number:
|
281
306
|
|
282
|
-
```
|
283
|
-
|
307
|
+
```ruby
|
308
|
+
SanitizeEmail::Deprecation.deprecate_in_silence = true
|
284
309
|
```
|
285
310
|
|
286
311
|
## Authors
|
@@ -296,15 +321,11 @@ See the [Network View](https://github.com/pboling/sanitize_email/network) and th
|
|
296
321
|
|
297
322
|
Take a look at the `reek` list which is the file called `REEK` and stat fixing things. Once you complete a change, run the tests:
|
298
323
|
|
299
|
-
|
300
|
-
bundle exec rake test:all
|
301
|
-
```
|
324
|
+
`bundle exec rake test:all`
|
302
325
|
|
303
326
|
If the tests pass refresh the `reek` list:
|
304
327
|
|
305
|
-
|
306
|
-
bundle exec reek > REEK
|
307
|
-
```
|
328
|
+
`bundle exec reek > REEK`
|
308
329
|
|
309
330
|
Follow the instructions for "Contributing" below.
|
310
331
|
|
@@ -331,7 +352,9 @@ dependency on this gem using the [Pessimistic Version Constraint][pvc] with two
|
|
331
352
|
|
332
353
|
For example:
|
333
354
|
|
334
|
-
|
355
|
+
```ruby
|
356
|
+
spec.add_dependency 'sanitize_email', '~> 1.1'
|
357
|
+
```
|
335
358
|
|
336
359
|
## References
|
337
360
|
|
@@ -351,8 +374,4 @@ For example:
|
|
351
374
|
[railsbling]: http://www.railsbling.com
|
352
375
|
[peterboling]: http://www.peterboling.com
|
353
376
|
[documentation]: http://rdoc.info/github/pboling/sanitize_email/frames
|
354
|
-
[homepage]:
|
355
|
-
|
356
|
-
|
357
|
-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/pboling/sanitize_email/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
358
|
-
|
377
|
+
[homepage]: http://www.railsbling.com/tags/sanitize_email/
|
@@ -1,24 +1,31 @@
|
|
1
|
-
# Copyright (c) 2008-
|
1
|
+
# Copyright (c) 2008-16 Peter H. Boling of RailsBling.com
|
2
2
|
# Released under the MIT license
|
3
3
|
|
4
4
|
module SanitizeEmail
|
5
|
-
#
|
5
|
+
# Determines whether to sanitize the headers of an email,
|
6
|
+
# and does so when appropriate.
|
6
7
|
class Bleach
|
8
|
+
extend SanitizeEmail::Deprecation
|
9
|
+
attr_accessor :overridden_addresses # TODO: Just a stub, not implemented
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def initialize(*args)
|
12
|
+
deprecation_message = <<EOS
|
13
|
+
SanitizeEmail:
|
14
|
+
Passing arguments to SanitizeEmail::Bleach.new is deprecated.
|
15
|
+
SanitizeEmail::Bleach.new now takes no arguments.
|
16
|
+
EOS
|
17
|
+
if !args.empty?
|
18
|
+
self.class.deprecation_warning_message(deprecation_message)
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
# If all recipient addresses are white-listed the field is left alone.
|
18
|
-
def delivering_email(message)
|
23
|
+
def self.delivering_email(message)
|
19
24
|
if self.sanitize_engaged?(message)
|
20
|
-
SanitizeEmail::MailHeaderTools.
|
21
|
-
|
25
|
+
SanitizeEmail::MailHeaderTools.
|
26
|
+
add_original_addresses_as_headers(message)
|
27
|
+
SanitizeEmail::MailHeaderTools.
|
28
|
+
prepend_custom_subject(message)
|
22
29
|
|
23
30
|
overridden = SanitizeEmail::OverriddenAddresses.new(message)
|
24
31
|
|
@@ -28,28 +35,47 @@ module SanitizeEmail
|
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
31
|
-
#
|
32
|
-
# There are
|
38
|
+
# Will be called by the Hook to determine if an override should occur
|
39
|
+
# There are three ways SanitizeEmail can be turned on;
|
40
|
+
# in order of precedence they are:
|
33
41
|
#
|
34
42
|
# 1. SanitizeEmail.force_sanitize = true # by default it is nil
|
35
|
-
# Only useful for local context.
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
+
# Only useful for local context.
|
44
|
+
# Inside a method where you will be sending an email, set
|
45
|
+
#
|
46
|
+
# SanitizeEmail.force_sanitize = true
|
47
|
+
#
|
48
|
+
# just prior to delivering it. Also useful in the console.
|
49
|
+
#
|
50
|
+
# 2. If SanitizeEmail seems to not be sanitizing,
|
51
|
+
# you have probably not registered the interceptor.
|
52
|
+
# SanitizeEmail tries to do this for you.
|
53
|
+
# *Note*: If you are working in an environment that has
|
54
|
+
# a Mail or Mailer class that uses the register_interceptor API,
|
55
|
+
# the interceptor will already have been registered.
|
56
|
+
# The gem will probably have already done this for you,
|
57
|
+
# but some really old versions of Rails may need you to do this manually:
|
58
|
+
#
|
59
|
+
# Mail.register_interceptor(SanitizeEmail::Bleach)
|
60
|
+
#
|
61
|
+
# Once registered, SanitizeEmail needs to be engaged:
|
62
|
+
#
|
63
|
+
# # in config/initializers/sanitize_email.rb
|
43
64
|
# SanitizeEmail::Config.configure {|config| config[:engage] = true }
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
65
|
+
#
|
66
|
+
# 3. SanitizeEmail::Config.configure do |config|
|
67
|
+
# config[:activation_proc] = Proc.new { true }
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# If you don't need to compute anything,
|
71
|
+
# then don't use the Proc, go with the previous option.
|
47
72
|
#
|
48
73
|
# Note: Number 1 is the method used by the SanitizeEmail.sanitary block
|
49
|
-
# Note: Number 2
|
74
|
+
# Note: Number 2 You may need to setup your own register_interceptor
|
50
75
|
#
|
51
|
-
# If installed but not configured, sanitize_email DOES NOTHING.
|
52
|
-
|
76
|
+
# If installed but not configured, sanitize_email DOES NOTHING.
|
77
|
+
# Until configured the defaults leave it turned off.
|
78
|
+
def self.sanitize_engaged?(message)
|
53
79
|
|
54
80
|
# Don't sanitize the message if it will not be delivered
|
55
81
|
return false unless message.perform_deliveries
|
@@ -59,7 +85,7 @@ module SanitizeEmail
|
|
59
85
|
return forced unless forced.nil?
|
60
86
|
|
61
87
|
# Is this particular instance of Bleach engaged
|
62
|
-
engaged =
|
88
|
+
engaged = SanitizeEmail::Config.config[:engage]
|
63
89
|
return engaged unless engaged.nil?
|
64
90
|
|
65
91
|
# Should we sanitize due to the activation_proc?
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2008-
|
1
|
+
# Copyright (c) 2008-16 Peter H. Boling of RailsBling.com
|
2
2
|
# Released under the MIT license
|
3
3
|
|
4
4
|
module SanitizeEmail
|
@@ -6,7 +6,7 @@ module SanitizeEmail
|
|
6
6
|
class Engine < ::Rails::Engine
|
7
7
|
|
8
8
|
config.to_prepare do
|
9
|
-
ActionMailer::Base.register_interceptor(SanitizeEmail::Bleach
|
9
|
+
ActionMailer::Base.register_interceptor(SanitizeEmail::Bleach)
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
# Copyright (c) 2008-
|
1
|
+
# Copyright (c) 2008-16 Peter H. Boling of RailsBling.com
|
2
2
|
# Released under the MIT license
|
3
3
|
|
4
4
|
module SanitizeEmail
|
5
|
-
# For Rails 3.0, which didn't yet support Engines
|
5
|
+
# For Rails 3.0, which didn't yet support Engines
|
6
6
|
class Railtie < ::Rails::Railtie
|
7
7
|
|
8
8
|
config.after_initialize do
|
9
|
-
ActionMailer::Base.register_interceptor(SanitizeEmail::Bleach
|
9
|
+
ActionMailer::Base.register_interceptor(SanitizeEmail::Bleach)
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
data/lib/sanitize_email.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2008-
|
1
|
+
# Copyright (c) 2008-16 Peter H. Boling of RailsBling.com
|
2
2
|
# Released under the MIT license
|
3
3
|
|
4
4
|
module SanitizeEmail
|
@@ -28,7 +28,7 @@ module SanitizeEmail
|
|
28
28
|
mailer = Mail
|
29
29
|
end
|
30
30
|
if mailer.respond_to?(:register_interceptor)
|
31
|
-
mailer.register_interceptor(SanitizeEmail::Bleach
|
31
|
+
mailer.register_interceptor(SanitizeEmail::Bleach)
|
32
32
|
else
|
33
33
|
warn "SanitizeEmail was unable to detect a compatible Mail class to register an interceptor on."
|
34
34
|
end
|
data/sanitize_email.gemspec
CHANGED
@@ -33,6 +33,7 @@ EOS
|
|
33
33
|
#s.add_runtime_dependency("facets", ["> 0"])
|
34
34
|
|
35
35
|
# Development Dependencies
|
36
|
+
s.add_development_dependency "bundler"
|
36
37
|
s.add_development_dependency("rails", [">= 3.0"])
|
37
38
|
s.add_development_dependency("actionmailer", [">= 3.0"])
|
38
39
|
s.add_development_dependency("letter_opener", [">= 0"])
|
data/spec/sanitize_email_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2008-
|
1
|
+
# Copyright (c) 2008-16 Peter H. Boling of RailsBling.com
|
2
2
|
# Released under the MIT license
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -56,7 +56,7 @@ describe SanitizeEmail do
|
|
56
56
|
config[:sanitized_recipients] = options[:sanitized_recipients] if options[:sanitized_recipients]
|
57
57
|
config[:force_sanitize] = options[:force_sanitize] unless options[:force_sanitize].nil?
|
58
58
|
end
|
59
|
-
Mail.register_interceptor(SanitizeEmail::Bleach
|
59
|
+
Mail.register_interceptor(SanitizeEmail::Bleach)
|
60
60
|
end
|
61
61
|
|
62
62
|
def funky_config
|
@@ -70,7 +70,7 @@ describe SanitizeEmail do
|
|
70
70
|
config[:use_actual_environment_prepended_to_subject] = true
|
71
71
|
config[:use_actual_email_as_sanitized_user_name] = false
|
72
72
|
end
|
73
|
-
Mail.register_interceptor(SanitizeEmail::Bleach
|
73
|
+
Mail.register_interceptor(SanitizeEmail::Bleach)
|
74
74
|
end
|
75
75
|
|
76
76
|
def sanitary_mail_delivery(config_options = {})
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanitize_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
@@ -10,8 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-07-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
15
29
|
- !ruby/object:Gem::Dependency
|
16
30
|
name: rails
|
17
31
|
requirement: !ruby/object:Gem::Requirement
|