sanitize_email 2.0.2 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +3 -0
- data/CHANGELOG.md +82 -12
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTING.md +47 -0
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.md +371 -58
- data/SECURITY.md +15 -0
- data/lib/sanitize_email/bleach.rb +13 -8
- data/lib/sanitize_email/config.rb +20 -20
- data/lib/sanitize_email/deprecation.rb +6 -6
- data/lib/sanitize_email/engine.rb +1 -1
- data/lib/sanitize_email/mail_ext.rb +2 -0
- data/lib/sanitize_email/mail_header_tools.rb +19 -15
- data/lib/sanitize_email/overridden_addresses.rb +77 -19
- data/lib/sanitize_email/railtie.rb +1 -1
- data/lib/sanitize_email/rspec_matchers.rb +55 -31
- data/lib/sanitize_email/test_helpers.rb +6 -6
- data/lib/sanitize_email/version.rb +4 -2
- data/lib/sanitize_email.rb +28 -18
- data.tar.gz.sig +0 -0
- metadata +70 -90
- metadata.gz.sig +0 -0
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -12
- data/.pryrc +0 -11
- data/.reek +0 -9
- data/.rspec +0 -2
- data/.rubocop.yml +0 -73
- data/.rubocop_rspec.yml +0 -35
- data/.rubocop_todo.yml +0 -21
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -71
- data/Appraisals +0 -29
- data/Gemfile +0 -22
- data/REEK +0 -2
- data/Rakefile +0 -52
- data/gemfiles/rails_4_2.gemfile +0 -17
- data/gemfiles/rails_5_0.gemfile +0 -17
- data/gemfiles/rails_5_1.gemfile +0 -17
- data/gemfiles/rails_5_2.gemfile +0 -17
- data/init.rb +0 -3
- data/sanitize_email.gemspec +0 -49
- data/spec/sanitize_email_spec.rb +0 -944
- data/spec/spec_helper.rb +0 -28
data/README.md
CHANGED
@@ -1,23 +1,218 @@
|
|
1
1
|
# sanitize_email
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
3
|
+
<div id="badges">
|
4
|
+
|
5
|
+
[![CI Build][🚎dl-cwfi]][🚎dl-cwf]
|
6
|
+
[![Test Coverage][🔑cc-covi]][🔑cc-cov]
|
7
|
+
[![Maintainability][🔑cc-mnti]][🔑cc-mnt]
|
8
|
+
[![Depfu][🔑depfui]][🔑depfu]
|
9
|
+
|
10
|
+
[🚎dl-cwf]: https://github.com/pboling/sanitize_email/actions/workflows/supported.yml
|
11
|
+
[🚎dl-cwfi]: https://github.com/pboling/sanitize_email/actions/workflows/supported.yml/badge.svg
|
12
|
+
|
13
|
+
[comment]: <> ( 🔑 KEYED LINKS )
|
14
|
+
|
15
|
+
[🔑cc-mnt]: https://codeclimate.com/github/pboling/sanitize_email/maintainability
|
16
|
+
[🔑cc-mnti]: https://api.codeclimate.com/v1/badges/65af4948d859903a0372/maintainability
|
17
|
+
[🔑cc-cov]: https://codeclimate.com/github/pboling/sanitize_email/test_coverage
|
18
|
+
[🔑cc-covi]: https://api.codeclimate.com/v1/badges/65af4948d859903a0372/test_coverage
|
19
|
+
[🔑depfu]: https://depfu.com/github/pboling/sanitize_email
|
20
|
+
[🔑depfui]: https://badges.depfu.com/badges/bba430e8f19a2ba3273fb20d5e8c82d6/count.svg
|
21
|
+
|
22
|
+
-----
|
23
|
+
|
24
|
+
[![Liberapay Patrons][⛳liberapay-img]][⛳liberapay]
|
25
|
+
[![Sponsor Me on Github][🖇sponsor-img]][🖇sponsor]
|
26
|
+
<span class="badge-buymeacoffee">
|
27
|
+
<a href="https://ko-fi.com/O5O86SNP4" target='_blank' title="Donate to my FLOSS or refugee efforts at ko-fi.com"><img src="https://img.shields.io/badge/buy%20me%20coffee-donate-yellow.svg" alt="Buy me coffee donation button" /></a>
|
28
|
+
</span>
|
29
|
+
<span class="badge-patreon">
|
30
|
+
<a href="https://patreon.com/galtzo" title="Donate to my FLOSS or refugee efforts using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a>
|
31
|
+
</span>
|
32
|
+
|
33
|
+
</div>
|
34
|
+
|
35
|
+
[⛳liberapay-img]: https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay
|
36
|
+
[⛳liberapay]: https://liberapay.com/pboling/donate
|
37
|
+
[🖇sponsor-img]: https://img.shields.io/badge/Sponsor_Me!-pboling.svg?style=social&logo=github
|
38
|
+
[🖇sponsor]: https://github.com/sponsors/pboling
|
39
|
+
|
40
|
+
This gem allows you to override your mail delivery settings, globally or in a local context.
|
41
|
+
It is like a Ruby encrusted condom for your email server,
|
42
|
+
just in case it decides to have intercourse with other servers via sundry mail protocols.
|
43
|
+
|
44
|
+
Seriously though, this gem solves similar problems as the excellent [`mailcatcher`](https://mailcatcher.me/) gem,
|
45
|
+
and mailcatcher solves those problems far more easily.
|
46
|
+
|
47
|
+
In addition, this gem solves problems that mailcatcher does not solve. I recommend using both!
|
48
|
+
|
49
|
+
To make an analogy, `mailcatcher` is akin to `webmock`, entirely preventing interaction with your real live mail server,
|
50
|
+
while this gem allows you to effectively use your real live (production!) mail server, while
|
51
|
+
intercepting and modifying recipeients on the way out, so that testing emails go to safe locations.
|
52
|
+
|
53
|
+
It is a bit like using the "test" Visa credit card number `4701322211111234` with a real payment gateway.
|
54
|
+
|
55
|
+
## Encryption
|
56
|
+
|
57
|
+
Making special note of this use case because it is important for companies working on HIPAA-compliant products.
|
58
|
+
When you are sending emails through an encrypted email provider, e.g. [Paubox](https://www.paubox.com/),
|
59
|
+
testing your email in the aforementioned `mailcatcher` may not be enough.
|
60
|
+
|
61
|
+
If you want to test all the way through Paubox's system, but have the email go to a safe testing account address,
|
62
|
+
then this is the gem for you.
|
63
|
+
|
64
|
+
## 🛞 DVCS
|
65
|
+
|
66
|
+
This project does not trust any one version control system,
|
67
|
+
so it abides the principles of ["Distributed Version Control Systems"][💎d-in-dvcs]
|
68
|
+
|
69
|
+
Find this project on:
|
70
|
+
|
71
|
+
| Any | Of | These | DVCS |
|
72
|
+
|----------------|------------------|----------------|----------------|
|
73
|
+
| [🐙hub][🐙hub] | [🧊berg][🧊berg] | [🛖hut][🛖hut] | [🧪lab][🧪lab] |
|
74
|
+
|
75
|
+
[comment]: <> ( DVCS LINKS )
|
76
|
+
|
77
|
+
[💎d-in-dvcs]: https://railsbling.com/posts/dvcs/put_the_d_in_dvcs/
|
78
|
+
|
79
|
+
[🧊berg]: https://codeberg.org/pboling/sanitize_email
|
80
|
+
[🐙hub]: https://gitlab.com/pboling/sanitize_email
|
81
|
+
[🛖hut]: https://sr.ht/~galtzo/pboling/sanitize_email
|
82
|
+
[🧪lab]: https://gitlab.com/pboling/sanitize_email
|
83
|
+
|
84
|
+
<!--
|
85
|
+
Numbering rows and badges in each row as a visual "database" lookup,
|
86
|
+
as the table is extremely dense, and it can be very difficult to find anything
|
87
|
+
Putting one on each row here, to document the emoji that should be used, and for ease of copy/paste.
|
88
|
+
|
89
|
+
row #s:
|
90
|
+
1️⃣
|
91
|
+
2️⃣
|
92
|
+
3️⃣
|
93
|
+
4️⃣
|
94
|
+
5️⃣
|
95
|
+
6️⃣
|
96
|
+
7️⃣
|
97
|
+
|
98
|
+
badge #s:
|
99
|
+
⛳️
|
100
|
+
🖇
|
101
|
+
🏘
|
102
|
+
🚎
|
103
|
+
🖐
|
104
|
+
🧮
|
105
|
+
📗
|
106
|
+
|
107
|
+
appended indicators:
|
108
|
+
♻️ / 🔑 - Tagged URLs need to be updated from SAAS integration. Find / Replace is insufficient.
|
109
|
+
-->
|
110
|
+
|
111
|
+
| | Project | bundle add sanitize_email |
|
112
|
+
|:----|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
113
|
+
| 1️⃣ | name, license, docs, standards | [![RubyGems.org][⛳️name-img]][⛳️gem] [![License: MIT][🖇src-license-img]][🖇src-license] [![RubyDoc.info][🚎yard-img]][🚎yard] [![YARD Documentation](http://inch-ci.org/github/pboling/sanitize_email.svg)][🚎yard] [![SemVer 2.0.0][🧮semver-img]][🧮semver] [![Keep-A-Changelog 1.0.0][📗keep-changelog-img]][📗keep-changelog] |
|
114
|
+
| 2️⃣ | version & activity | [![Gem Version][⛳️version-img]][⛳️gem] [![Total Downloads][🖇DL-total-img]][⛳️gem] [![Download Rank][🏘DL-rank-img]][⛳️gem] [![Source Code][🚎src-main-img]][🚎src-main] [![Open PRs][🖐prs-o-img]][🖐prs-o] [![Closed PRs][🧮prs-c-img]][🧮prs-c] |
|
115
|
+
| 3️⃣ | maintenance & linting | [![Maintainability][🔑cc-mnti]][🔑cc-mnt] [![Helpers][🖇triage-help-img]][🖇triage-help] [![Depfu][🔑depfui]][🔑depfu] [![Contributors][🚎contributors-img]][🚎contributors] [![Style][🖐style-wf-img]][🖐style-wf] |
|
116
|
+
| 4️⃣ | testing | [![Supported][🏘sup-wf-img]][🏘sup-wf] [![Heads][🚎heads-wf-img]][🚎heads-wf] |
|
117
|
+
| 5️⃣ | coverage & security | [![CodeClimate][🔑cc-covi]][🔑cc-cov] [![CodeCov][🖇codecov-img♻️]][🖇codecov] [![Coveralls][🏘coveralls-img]][🏘coveralls] [![Security Policy][🚎sec-pol-img]][🚎sec-pol] [![CodeQL][🖐codeQL-img]][🖐codeQL] [![Code Coverage][🧮cov-wf-img]][🧮cov-wf] |
|
118
|
+
| 6️⃣ | resources | [![Get help on Codementor][🖇codementor-img]][🖇codementor] [![Chat][🏘chat-img]][🏘chat] [![Blog][🚎blog-img]][🚎blog] [![Wiki][🖐wiki-img]][🖐wiki] |
|
119
|
+
| 7️⃣ | ... 💖 | [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] [![Sponsor Me][🖇sponsor-img]][🖇sponsor] [![Follow Me on LinkedIn][🖇linkedin-img]][🖇linkedin] [![Find Me on WellFound:][✌️wellfound-img]][✌️wellfound] [![Find Me on CrunchBase][💲crunchbase-img]][💲crunchbase] [![My LinkTree][🌳linktree-img]][🌳linktree] [![Follow Me on Ruby.Social][🐘ruby-mast-img]][🐘ruby-mast] [![Follow Me on FLOSS.Social][🐘floss-mast-img]][🐘floss-mast] [![Follow Me on Mastodon.Social][🐘mast-img]][🐘mast] [![Tweet @ Peter][🐦tweet-img]][🐦tweet] [💻][coderme] [🌏][aboutme] |
|
120
|
+
|
121
|
+
<!--
|
122
|
+
The link tokens in the following sections should be kept ordered by the row and badge numbering scheme
|
123
|
+
-->
|
124
|
+
|
125
|
+
<!-- 1️⃣ name, license, docs -->
|
126
|
+
[⛳️gem]: https://rubygems.org/gems/sanitize_email
|
127
|
+
[⛳️name-img]: https://img.shields.io/badge/name-sanitize_email-brightgreen.svg?style=flat
|
128
|
+
[🖇src-license]: https://opensource.org/licenses/MIT
|
129
|
+
[🖇src-license-img]: https://img.shields.io/badge/License-MIT-green.svg
|
130
|
+
[🚎yard]: https://www.rubydoc.info/gems/sanitize_email
|
131
|
+
[🚎yard-img]: https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat
|
132
|
+
[🧮semver]: http://semver.org/
|
133
|
+
[🧮semver-img]: https://img.shields.io/badge/semver-2.0.0-FFDD67.svg?style=flat
|
134
|
+
[📗keep-changelog]: https://keepachangelog.com/en/1.0.0/
|
135
|
+
[📗keep-changelog-img]: https://img.shields.io/badge/keep--a--changelog-1.0.0-FFDD67.svg?style=flat
|
136
|
+
|
137
|
+
<!-- 2️⃣ version & activity -->
|
138
|
+
[⛳️version-img]: http://img.shields.io/gem/v/sanitize_email.svg
|
139
|
+
[🖇DL-total-img]: https://img.shields.io/gem/dt/sanitize_email.svg
|
140
|
+
[🏘DL-rank-img]: https://img.shields.io/gem/rt/sanitize_email.svg
|
141
|
+
[🚎src-main]: https://gitlab.com/pboling/sanitize_email
|
142
|
+
[🚎src-main-img]: https://img.shields.io/badge/source-gitlab-brightgreen.svg?style=flat
|
143
|
+
[🖐prs-o]: https://gitlab.com/pboling/sanitize_email/-/merge_requests
|
144
|
+
[🖐prs-o-img]: https://img.shields.io/github/issues-pr/pboling/sanitize_email
|
145
|
+
[🧮prs-c]: https://github.com/pboling/sanitize_email/pulls?q=is%3Apr+is%3Aclosed
|
146
|
+
[🧮prs-c-img]: https://img.shields.io/github/issues-pr-closed/pboling/sanitize_email
|
147
|
+
|
148
|
+
<!-- 3️⃣ maintenance & linting -->
|
149
|
+
[🖇triage-help]: https://www.codetriage.com/pboling/sanitize_email
|
150
|
+
[🖇triage-help-img]: https://www.codetriage.com/pboling/sanitize_email/badges/users.svg
|
151
|
+
[🚎contributors]: https://gitlab.com/pboling/sanitize_email/-/graphs/main
|
152
|
+
[🚎contributors-img]: https://img.shields.io/github/contributors-anon/pboling/sanitize_email
|
153
|
+
[🖐style-wf]: https://github.com/pboling/sanitize_email/actions/workflows/style.yml
|
154
|
+
[🖐style-wf-img]: https://github.com/pboling/sanitize_email/actions/workflows/style.yml/badge.svg
|
155
|
+
<!-- TODO: tokei/lines shields badge is broken -->
|
156
|
+
[🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
|
157
|
+
[🧮kloc-img]: https://img.shields.io/tokei/lines/github.com/pboling/sanitize_email
|
158
|
+
|
159
|
+
<!-- 4️⃣ testing -->
|
160
|
+
[🏘sup-wf]: https://github.com/pboling/sanitize_email/actions/workflows/supported.yml
|
161
|
+
[🏘sup-wf-img]: https://github.com/pboling/sanitize_email/actions/workflows/supported.yml/badge.svg
|
162
|
+
[🚎heads-wf]: https://github.com/pboling/sanitize_email/actions/workflows/heads.yml
|
163
|
+
[🚎heads-wf-img]: https://github.com/pboling/sanitize_email/actions/workflows/heads.yml/badge.svg
|
164
|
+
[🖐uns-wf]: https://github.com/pboling/sanitize_email/actions/workflows/unsupported.yml
|
165
|
+
[🖐uns-wf-img]: https://github.com/pboling/sanitize_email/actions/workflows/unsupported.yml/badge.svg
|
166
|
+
[🧮mac-wf]: https://github.com/pboling/sanitize_email/actions/workflows/macos.yml
|
167
|
+
[🧮mac-wf-img]: https://github.com/pboling/sanitize_email/actions/workflows/macos.yml/badge.svg
|
168
|
+
[📗win-wf]: https://github.com/pboling/sanitize_email/actions/workflows/windows.yml
|
169
|
+
[📗win-wf-img]: https://github.com/pboling/sanitize_email/actions/workflows/windows.yml/badge.svg
|
170
|
+
|
171
|
+
<!-- 5️⃣ coverage & security -->
|
172
|
+
[🖇codecov-img♻️]: https://codecov.io/gh/pboling/sanitize_email/graph/badge.svg?token=Joire8DbSW
|
173
|
+
[🖇codecov]: https://codecov.io/gh/pboling/sanitize_email
|
174
|
+
[🏘coveralls]: https://coveralls.io/github/pboling/sanitize_email?branch=main
|
175
|
+
[🏘coveralls-img]: https://coveralls.io/repos/github/pboling/sanitize_email/badge.svg?branch=main
|
176
|
+
[🚎sec-pol]: https://gitlab.com/pboling/sanitize_email/-/blob/main/SECURITY.md
|
177
|
+
[🚎sec-pol-img]: https://img.shields.io/badge/security-policy-brightgreen.svg?style=flat
|
178
|
+
[🖐codeQL]: https://github.com/pboling/sanitize_email/security/code-scanning
|
179
|
+
[🖐codeQL-img]: https://github.com/pboling/sanitize_email/actions/workflows/codeql-analysis.yml/badge.svg
|
180
|
+
[🧮cov-wf]: https://github.com/pboling/sanitize_email/actions/workflows/coverage.yml
|
181
|
+
[🧮cov-wf-img]: https://github.com/pboling/sanitize_email/actions/workflows/coverage.yml/badge.svg
|
182
|
+
|
183
|
+
<!-- 6️⃣ resources -->
|
184
|
+
[🖇codementor]: https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github
|
185
|
+
[🖇codementor-img]: https://cdn.codementor.io/badges/get_help_github.svg
|
186
|
+
[🏘chat]: https://gitter.im/pboling/sanitize_email
|
187
|
+
[🏘chat-img]: https://img.shields.io/gitter/room/pboling/sanitize_email.svg
|
188
|
+
[🚎blog]: http://www.railsbling.com/tags/sanitize_email/
|
189
|
+
[🚎blog-img]: https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat
|
190
|
+
[🖐wiki]: https://gitlab.com/pboling/sanitize_email/-/wikis/home
|
191
|
+
[🖐wiki-img]: https://img.shields.io/badge/wiki-examples-brightgreen.svg?style=flat
|
192
|
+
|
193
|
+
<!-- 7️⃣ spread 💖 -->
|
194
|
+
[🐦tweet-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow%20%40galtzo
|
195
|
+
[🐦tweet]: http://twitter.com/galtzo
|
196
|
+
[🚎blog]: http://www.railsbling.com/tags/debug_logging/
|
197
|
+
[🚎blog-img]: https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat
|
198
|
+
[🖇linkedin]: http://www.linkedin.com/in/peterboling
|
199
|
+
[🖇linkedin-img]: https://img.shields.io/badge/PeterBoling-blue?style=plastic&logo=linkedin
|
200
|
+
[✌️wellfound]: https://angel.co/u/peter-boling
|
201
|
+
[✌️wellfound-img]: https://img.shields.io/badge/peter--boling-orange?style=plastic&logo=angellist
|
202
|
+
[💲crunchbase]: https://www.crunchbase.com/person/peter-boling
|
203
|
+
[💲crunchbase-img]: https://img.shields.io/badge/peter--boling-purple?style=plastic&logo=crunchbase
|
204
|
+
[🐘ruby-mast]: https://ruby.social/@galtzo
|
205
|
+
[🐘ruby-mast-img]: https://img.shields.io/mastodon/follow/109447111526622197?domain=https%3A%2F%2Fruby.social&style=plastic&logo=mastodon&label=Ruby%20%40galtzo
|
206
|
+
[🐘floss-mast]: https://floss.social/@galtzo
|
207
|
+
[🐘floss-mast-img]: https://img.shields.io/mastodon/follow/110304921404405715?domain=https%3A%2F%2Ffloss.social&style=plastic&logo=mastodon&label=FLOSS%20%40galtzo
|
208
|
+
[🐘mast]: https://mastodon.social/@galtzo
|
209
|
+
[🐘mast-img]: https://img.shields.io/mastodon/follow/000924127?domain=https%3A%2F%2Fmastodon.social&style=plastic&logo=mastodon&label=Mastodon%20%40galtzo
|
210
|
+
[🌳linktree]: https://linktr.ee/galtzo
|
211
|
+
[🌳linktree-img]: https://img.shields.io/badge/galtzo-purple?style=plastic&logo=linktree
|
212
|
+
|
213
|
+
<!-- Maintainer Contact Links -->
|
214
|
+
[aboutme]: https://about.me/peter.boling
|
215
|
+
[coderme]: https://coderwall.com/Peter%20Boling
|
21
216
|
|
22
217
|
## Summary
|
23
218
|
|
@@ -51,11 +246,15 @@ Another very important use case for me is to transparently re-route email genera
|
|
51
246
|
|
52
247
|
If you install this gem on a production server (which I don't always do), you can load up script/console and override the to/cc/bcc on all emails for the duration of your console session. This allows you to poke and prod a live production instance, and route all email to your own inbox for inspection. The best part is that this can all be accomplished without changing a single line of your application code.
|
53
248
|
|
249
|
+
## Monitoring all email sent by server to a backup account
|
250
|
+
|
251
|
+
You may want to add a BCC automatically (e.g. to account-history@my-company.com) to every email sent by your system, for customer service purposes, and this gem allows that. Note that this may not be a good idea for all systems, for many reasons, e.g security!
|
252
|
+
|
54
253
|
## Using with a test suite as an alternative to the heavy email_spec
|
55
254
|
|
56
255
|
[email_spec](https://github.com/bmabey/email-spec) is a great gem, with awesome rspec matchers and helpers, but it has an undeclared dependency on ActionMailer. Sad face.
|
57
256
|
|
58
|
-
SanitizeEmail comes with some lightweight RspecMatchers covering most of what email_spec can do. It will help you test email functionality. It is useful when you are creating a gem to handle email features, or are writing a simple Ruby script, and don't want to pull in le Rails. SanitizeEmail has
|
257
|
+
SanitizeEmail comes with some lightweight RspecMatchers covering most of what email_spec can do. It will help you test email functionality. It is useful when you are creating a gem to handle email features, or are writing a simple Ruby script, and don't want to pull in le Rails. SanitizeEmail has two dependencies, `mail` gem, and `version_gem`. Your Mail system just needs to conform to `mail` gem's `register_interceptor` API.
|
59
258
|
|
60
259
|
## Install Like a Boss
|
61
260
|
|
@@ -103,6 +302,21 @@ There are three ways SanitizeEmail can be turned on; in order of precedence they
|
|
103
302
|
SanitizeEmail::Config.configure {|config| config[:activation_proc] = Proc.new { true } } # by default :activation_proc is false
|
104
303
|
```
|
105
304
|
|
305
|
+
### Examples
|
306
|
+
|
307
|
+
#### Only allow email to a specific domain
|
308
|
+
|
309
|
+
This works by ensuring that all recipients have the "allowed" domain.
|
310
|
+
In other words, none of the recipients have a domain other than the allowed domain.
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
ALLOWED_DOMAIN = 'example.com'
|
314
|
+
# NOTE: you may need to check CC and BCC also, depending on your use case...
|
315
|
+
config[:activation_proc] = ->(message) do
|
316
|
+
!Array(message.to).any? { |recipient| Mail::Address.new(recipient).domain != ALLOWED_DOMAIN }
|
317
|
+
end
|
318
|
+
```
|
319
|
+
|
106
320
|
### Notes
|
107
321
|
|
108
322
|
Number 1, above, is the method used by the SanitizeEmail.sanitary block.
|
@@ -222,10 +436,10 @@ end
|
|
222
436
|
|
223
437
|
#### have_* matchers
|
224
438
|
|
225
|
-
These will look for an email address in any of the following
|
439
|
+
These will look for an email address in any of the following mail attributes:
|
226
440
|
|
227
441
|
```ruby
|
228
|
-
:from, :to, :cc, :bcc, :subject, :reply_to
|
442
|
+
[:from, :to, :cc, :bcc, :subject, :reply_to]
|
229
443
|
```
|
230
444
|
|
231
445
|
Example:
|
@@ -258,7 +472,7 @@ end
|
|
258
472
|
|
259
473
|
The `username` in the `:to` field is when the `:to` field is formatted like this:
|
260
474
|
|
261
|
-
`Peter Boling <sanitize_email@example.org>`
|
475
|
+
`"Peter Boling" <sanitize_email@example.org>`
|
262
476
|
|
263
477
|
Example:
|
264
478
|
|
@@ -269,6 +483,58 @@ context "the to field must have the username 'Peter Boling'" do
|
|
269
483
|
end
|
270
484
|
```
|
271
485
|
|
486
|
+
#### have_sanitized_to_header matcher
|
487
|
+
|
488
|
+
Matches any part of the value of the first sanitized to header (`"X-Sanitize-Email-To"`),
|
489
|
+
which could be formatted like this:
|
490
|
+
|
491
|
+
`"Peter Boling" <sanitize_email@example.org>`
|
492
|
+
|
493
|
+
NOTE: It won't match subsequent headers like `"X-Sanitize-Email-To-2"`, or `"X-Sanitize-Email-To-3"`.
|
494
|
+
|
495
|
+
Example:
|
496
|
+
|
497
|
+
```ruby
|
498
|
+
context "the first 'X-Sanitize-Email-To' header must have the username 'Peter Boling'" do
|
499
|
+
subject { Mail.deliver(@message_hash) }
|
500
|
+
it { should have_sanitized_to_header "Peter Boling" }
|
501
|
+
end
|
502
|
+
```
|
503
|
+
|
504
|
+
#### have_cc_username matcher
|
505
|
+
|
506
|
+
The `username` in the `:cc` field is when the `:c` field is formatted like this:
|
507
|
+
|
508
|
+
`"Peter Boling" <sanitize_email@example.org>`
|
509
|
+
|
510
|
+
Example:
|
511
|
+
|
512
|
+
```ruby
|
513
|
+
context "the cc field must have the username 'Peter Boling'" do
|
514
|
+
subject { Mail.deliver(@message_hash) }
|
515
|
+
it { should have_cc_username "Peter Boling" }
|
516
|
+
end
|
517
|
+
```
|
518
|
+
|
519
|
+
#### have_sanitized_cc_header matcher
|
520
|
+
|
521
|
+
Matches any part of the value of the first sanitized cc header (`"X-Sanitize-Email-Cc"`),
|
522
|
+
which could be formatted like this:
|
523
|
+
|
524
|
+
`"Peter Boling" <sanitize_email@example.org>`
|
525
|
+
|
526
|
+
NOTE: It won't match subsequent headers like `"X-Sanitize-Email-Cc-2"`, or `"X-Sanitize-Email-Cc-3"`.
|
527
|
+
|
528
|
+
Example:
|
529
|
+
|
530
|
+
```ruby
|
531
|
+
context "the first 'X-Sanitize-Email-Cc' header must have the username 'Peter Boling'" do
|
532
|
+
subject { Mail.deliver(@message_hash) }
|
533
|
+
it { should have_sanitized_cc_header "Peter Boling" }
|
534
|
+
end
|
535
|
+
```
|
536
|
+
|
537
|
+
|
272
538
|
### non-rspec (Test::Unit, mini-test, etc)
|
273
539
|
|
274
540
|
In your setup file:
|
@@ -316,28 +582,51 @@ Peter Boling is the original author of the code, and current maintainer.
|
|
316
582
|
|
317
583
|
Thanks to John Trupiano for turning Peter's original Rails plugin into this gem!
|
318
584
|
|
319
|
-
##
|
585
|
+
## 🤝 Contributing
|
320
586
|
|
321
|
-
See
|
587
|
+
See [CONTRIBUTING.md][🤝contributing]
|
322
588
|
|
323
|
-
|
589
|
+
[🤝contributing]: CONTRIBUTING.md
|
324
590
|
|
325
|
-
|
591
|
+
### You can help!
|
592
|
+
|
593
|
+
Take a look at the `reek` list which is the file called `REEK` and start fixing things.
|
326
594
|
|
327
595
|
To refresh the `reek` list:
|
328
596
|
|
329
597
|
`bundle exec reek > REEK`
|
330
598
|
|
331
|
-
|
332
|
-
|
333
|
-
## Contributing
|
599
|
+
Then follow these instructions:
|
334
600
|
|
335
|
-
1. Fork
|
601
|
+
1. Fork the repository
|
336
602
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
337
|
-
3.
|
338
|
-
4.
|
339
|
-
5.
|
340
|
-
6.
|
603
|
+
3. Make some fixes.
|
604
|
+
4. Commit your changes (`git commit -am 'Added some feature'`)
|
605
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
606
|
+
6. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
607
|
+
7. Create new Pull Request.
|
608
|
+
|
609
|
+
## 🌈 Contributors
|
610
|
+
|
611
|
+
[![Contributors][🌈contrib-rocks-img]][🐙hub-contrib]
|
612
|
+
|
613
|
+
Contributor tiles (GitHub only) made with [contributors-img][🌈contrib-rocks].
|
614
|
+
|
615
|
+
Learn more about, or become one of, our 🎖 contributors on:
|
616
|
+
|
617
|
+
| Any | Of | These | DVCS |
|
618
|
+
|-------------------------------------|---------------------------------------|-------------------------------------|-------------------------------------|
|
619
|
+
| [🐙hub contributors][🐙hub-contrib] | [🧊berg contributors][🧊berg-contrib] | [🛖hut contributors][🛖hut-contrib] | [🧪lab contributors][🧪lab-contrib] |
|
620
|
+
|
621
|
+
[comment]: <> ( DVCS CONTRIB LINKS )
|
622
|
+
|
623
|
+
[🌈contrib-rocks]: https://contrib.rocks
|
624
|
+
[🌈contrib-rocks-img]: https://contrib.rocks/image?repo=pboling/sanitize_email
|
625
|
+
|
626
|
+
[🧊berg-contrib]: https://codeberg.org/pboling/sanitize_email/activity
|
627
|
+
[🐙hub-contrib]: https://github.com/pboling/sanitize_email/graphs/contributors
|
628
|
+
[🛖hut-contrib]: https://git.sr.ht/~galtzo/pboling-sanitize_email/log/
|
629
|
+
[🧪lab-contrib]: https://gitlab.com/pboling/sanitize_email/-/graphs/main?ref_type=heads
|
341
630
|
|
342
631
|
## Running Specs
|
343
632
|
|
@@ -347,35 +636,52 @@ appraisal install
|
|
347
636
|
appraisal rake test
|
348
637
|
```
|
349
638
|
|
350
|
-
Run the whole travis compatibility matrix:
|
351
|
-
```
|
352
|
-
rake wwtd:bundle
|
353
|
-
rake wwtd
|
354
|
-
```
|
355
|
-
|
356
639
|
Sometimes also:
|
357
640
|
```
|
358
641
|
appraisal update
|
359
642
|
```
|
360
643
|
|
361
|
-
|
644
|
+
### Code Coverage
|
645
|
+
|
646
|
+
[![Coverage Graph][🔑codecov-g]][🖇codecov]
|
647
|
+
|
648
|
+
[🔑codecov-g]: https://codecov.io/gh/pboling/sanitize_email/graphs/tree.svg?token=Joire8DbSW
|
649
|
+
|
650
|
+
## 🪇 Code of Conduct
|
651
|
+
|
652
|
+
Everyone interacting in this project's codebases, issue trackers,
|
653
|
+
chat rooms and mailing lists is expected to follow the [code of conduct][🪇conduct].
|
654
|
+
|
655
|
+
[🪇conduct]: CODE_OF_CONDUCT.md
|
362
656
|
|
363
|
-
|
364
|
-
Violations of this scheme should be reported as bugs. Specifically,
|
365
|
-
if a minor or patch version is released that breaks backward
|
366
|
-
compatibility, a new version should be immediately released that
|
367
|
-
restores compatibility. Breaking changes to the public API will
|
368
|
-
only be introduced with new major versions.
|
657
|
+
## 📌 Versioning
|
369
658
|
|
370
|
-
|
371
|
-
|
659
|
+
This Library adheres to [Semantic Versioning 2.0.0][📌semver].
|
660
|
+
Violations of this scheme should be reported as bugs.
|
661
|
+
Specifically, if a minor or patch version is released that breaks backward compatibility,
|
662
|
+
a new version should be immediately released that restores compatibility.
|
663
|
+
Breaking changes to the public API will only be introduced with new major versions.
|
664
|
+
|
665
|
+
To get a better understanding of how SemVer is intended to work over a project's lifetime,
|
666
|
+
read this article from the creator of SemVer:
|
667
|
+
|
668
|
+
- ["Major Version Numbers are Not Sacred"][📌major-versions-not-sacred]
|
669
|
+
|
670
|
+
As a result of this policy, you can (and should) specify a dependency on these libraries using
|
671
|
+
the [Pessimistic Version Constraint][📌pvc] with two digits of precision.
|
372
672
|
|
373
673
|
For example:
|
374
674
|
|
375
675
|
```ruby
|
376
|
-
spec.add_dependency
|
676
|
+
spec.add_dependency "sanitize_email", "~> 2.0"
|
377
677
|
```
|
378
678
|
|
679
|
+
[comment]: <> ( 📌 VERSIONING LINKS )
|
680
|
+
|
681
|
+
[📌pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
682
|
+
[📌semver]: http://semver.org/
|
683
|
+
[📌major-versions-not-sacred]: https://tom.preston-werner.com/2022/05/23/major-version-numbers-are-not-sacred.html
|
684
|
+
|
379
685
|
## References
|
380
686
|
|
381
687
|
* [Source Code](http://github.com/pboling/sanitize_email)
|
@@ -383,16 +689,23 @@ spec.add_dependency 'sanitize_email', '~> 1.3'
|
|
383
689
|
* [Peter's Original Writeup](http://galtzo.blogspot.com/2008/11/sanitize-email-never-worry-about.html)
|
384
690
|
* [Using sanitize_email to Preview HTML Emails Locally](http://blog.smartlogicsolutions.com/2009/04/30/using-sanitize-email-to-preview-html-emails-locally/)
|
385
691
|
|
386
|
-
##
|
692
|
+
## 📄 License
|
693
|
+
|
694
|
+
The gem is available as open source under the terms of
|
695
|
+
the [MIT License][📄license] [![License: MIT][📄license-img]][📄license-ref].
|
696
|
+
See [LICENSE.txt][📄license] for the official [Copyright Notice][📄copyright-notice-explainer].
|
697
|
+
|
698
|
+
[comment]: <> ( 📄 LEGAL LINKS )
|
699
|
+
|
700
|
+
[📄copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
|
701
|
+
[📄license]: LICENSE.txt
|
702
|
+
[📄license-ref]: https://opensource.org/licenses/MIT
|
703
|
+
[📄license-img]: https://img.shields.io/badge/License-MIT-green.svg
|
704
|
+
|
705
|
+
### © Copyright
|
387
706
|
|
388
|
-
* MIT License - See [LICENSE file][license] in this project
|
389
707
|
* Copyright (c) 2009 [John Trupiano](http://smartlogicsolutions.com/wiki/John_Trupiano) of [SmartLogic Solutions, LLC](http://www.smartlogicsolutions.com)
|
390
|
-
* Copyright (c) 2008-
|
708
|
+
* Copyright (c) 2008 - 2018, 2020, 2022, 2024 [Peter H. Boling][peterboling] of [Rails Bling][railsbling]
|
391
709
|
|
392
|
-
[license]: LICENSE
|
393
|
-
[semver]: http://semver.org/
|
394
|
-
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
395
710
|
[railsbling]: http://www.railsbling.com
|
396
711
|
[peterboling]: http://www.peterboling.com
|
397
|
-
[documentation]: http://rdoc.info/github/pboling/sanitize_email/frames
|
398
|
-
[homepage]: http://www.railsbling.com/tags/sanitize_email/
|
data/SECURITY.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Security Policy
|
2
|
+
|
3
|
+
## Supported Versions
|
4
|
+
|
5
|
+
| Version | Supported |
|
6
|
+
|---------|-----------|
|
7
|
+
| 2.x | ✅ |
|
8
|
+
| 1.x | ❌ |
|
9
|
+
| 0.x | ❌ |
|
10
|
+
|
11
|
+
## Reporting a Vulnerability
|
12
|
+
|
13
|
+
Peter Boling is the primary maintainer of this gem. Please find a way
|
14
|
+
to [contact him directly](https://railsbling.com/contact) to report the issue. Include as much relevant information as
|
15
|
+
possible.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2008-
|
3
|
+
# Copyright (c) 2008 - 2018, 2020, 2022, 2024 Peter H. Boling of RailsBling.com
|
4
4
|
# Released under the MIT license
|
5
5
|
|
6
6
|
module SanitizeEmail
|
@@ -14,19 +14,24 @@ module SanitizeEmail
|
|
14
14
|
deprecation_message unless args.empty?
|
15
15
|
end
|
16
16
|
|
17
|
-
# If all recipient addresses are
|
17
|
+
# If all recipient addresses are allow-listed the field is left alone.
|
18
18
|
def self.delivering_email(message)
|
19
|
-
return
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
return unless sanitize_engaged?(message)
|
20
|
+
|
21
|
+
SanitizeEmail::MailHeaderTools
|
22
|
+
.add_original_addresses_as_headers(message)
|
23
|
+
SanitizeEmail::MailHeaderTools
|
24
|
+
.prepend_custom_subject(message)
|
24
25
|
|
25
26
|
overridden = SanitizeEmail::OverriddenAddresses.new(message)
|
26
27
|
|
27
28
|
message.to = overridden.overridden_to
|
28
29
|
message.cc = overridden.overridden_cc
|
29
30
|
message.bcc = overridden.overridden_bcc
|
31
|
+
|
32
|
+
return if message["personalizations"].nil?
|
33
|
+
|
34
|
+
message["personalizations"].value = overridden.overridden_personalizations
|
30
35
|
end
|
31
36
|
|
32
37
|
# Will be called by the Hook to determine if an override should occur
|
@@ -85,7 +90,7 @@ module SanitizeEmail
|
|
85
90
|
SanitizeEmail.activate?(message)
|
86
91
|
end
|
87
92
|
|
88
|
-
|
93
|
+
private
|
89
94
|
|
90
95
|
def deprecation_message
|
91
96
|
deprecation = <<~DEPRECATION
|