email_address 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +18 -0
- data/Gemfile +1 -1
- data/README.md +255 -123
- data/Rakefile +2 -3
- data/email_address.gemspec +27 -22
- data/lib/email_address/active_record_validator.rb +10 -11
- data/lib/email_address/address.rb +126 -80
- data/lib/email_address/canonical_email_address_type.rb +16 -12
- data/lib/email_address/config.rb +102 -51
- data/lib/email_address/email_address_type.rb +17 -13
- data/lib/email_address/exchanger.rb +44 -33
- data/lib/email_address/host.rb +217 -105
- data/lib/email_address/local.rb +127 -87
- data/lib/email_address/messages.yaml +21 -0
- data/lib/email_address/rewriter.rb +144 -0
- data/lib/email_address/version.rb +1 -1
- data/lib/email_address.rb +48 -53
- data/test/activerecord/test_ar.rb +17 -13
- data/test/activerecord/user.rb +31 -30
- data/test/email_address/test_address.rb +84 -21
- data/test/email_address/test_config.rb +10 -10
- data/test/email_address/test_exchanger.rb +6 -7
- data/test/email_address/test_host.rb +59 -21
- data/test/email_address/test_local.rb +49 -36
- data/test/email_address/test_rewriter.rb +11 -0
- data/test/test_aliasing.rb +53 -0
- data/test/test_email_address.rb +15 -19
- data/test/test_helper.rb +9 -8
- metadata +43 -21
- data/.travis.yml +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f9667acc31d6ce84fd3acb2e8e2f3ea04e496df5ff9dc5f89815fa148df1113e
|
4
|
+
data.tar.gz: e17aa2b229cb28ca80dcbf37226a5411052758db1e15cee0ddc2038d5244de42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 908fa1ffaa5692b07fa4e586a66a8fdf6395c1a51013ee389e0437df175d6712ecc57831b6616cfabd28463a87c7a60df9b6ba8382cba0c58d8449e4ada51c6d
|
7
|
+
data.tar.gz: a9f2a9bb8280118af5b21b08e8ca2273b16f3d5f700b91cb7c36b22444a7d5878e54a45292a2080243aff6fa4d31cd2ca3af4bd664f182b49d52ab42b864c711
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: CI Build
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
strategy:
|
7
|
+
matrix:
|
8
|
+
ruby-version: [2.6, 2.7, 3.0, jruby]
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: ${{ matrix.ruby-version }}
|
14
|
+
bundler-cache: true # runs `bundle install` and caches installed gems automatically
|
15
|
+
- name: Install dependencies
|
16
|
+
run: bundle install
|
17
|
+
- name: Run tests
|
18
|
+
run: bundle exec rake
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Email Address
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/email_address.svg)](http://rubygems.org/gems/email_address)
|
4
|
-
[![Build
|
4
|
+
[![CI Build](https://github.com/afair/email_address/actions/workflows/ci.yml/badge.svg)](https://github.com/afair/email_address/actions/workflows/ci.yml)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/afair/email_address/badges/gpa.svg)](https://codeclimate.com/github/afair/email_address)
|
6
6
|
|
7
7
|
The `email_address` gem provides a ruby language library for working
|
@@ -20,12 +20,51 @@ and can deal with gmail's "optional dots" in addresses.
|
|
20
20
|
It provides Active Record (Rails) extensions, including an
|
21
21
|
address validator and attributes API custom datatypes.
|
22
22
|
|
23
|
-
*Note:* Version 0.1.0 contains significant API and internal changes over the 0.0.3
|
24
|
-
version. If you have been using the 0.0.x series of the gem, you may
|
25
|
-
want to continue using with your current version.
|
26
|
-
|
27
23
|
Requires Ruby 2.0 or later.
|
28
24
|
|
25
|
+
Looking for a Javascript version of this library? Check out the
|
26
|
+
[email_address](https://www.npmjs.com/package/email_address) npm module.
|
27
|
+
|
28
|
+
## Quick Start
|
29
|
+
|
30
|
+
To quickly validate email addresses, use the valid? and error helpers.
|
31
|
+
`valid?` returns a boolean, and `error` returns nil if valid, otherwise
|
32
|
+
a basic error message.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
EmailAddress.valid? "allen@google.com" #=> true
|
36
|
+
EmailAddress.error "allen@bad-d0main.com" #=> "Invalid Host/Domain Name"
|
37
|
+
```
|
38
|
+
|
39
|
+
`EmailAddress` deeply validates your email addresses. It checks:
|
40
|
+
|
41
|
+
* Host name format and DNS setup
|
42
|
+
* Mailbox format according to "conventional" form. This matches most used user
|
43
|
+
email accounts, but is a subset of the RFC specification.
|
44
|
+
|
45
|
+
It does not check:
|
46
|
+
|
47
|
+
* The mail server is configured to accept connections
|
48
|
+
* The mailbox is valid and accepts email.
|
49
|
+
|
50
|
+
By default, MX records are required in DNS. MX or "mail exchanger" records
|
51
|
+
tell where to deliver email for the domain. Many domains run their
|
52
|
+
website on one provider (ISP, Heroku, etc.), and email on a different
|
53
|
+
provider (such as G Suite). Note that `example.com`, while
|
54
|
+
a valid domain name, does not have MX records.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
EmailAddress.valid? "allen@example.com" #=> false
|
58
|
+
EmailAddress.valid? "allen@example.com", host_validation: :syntax #=> true
|
59
|
+
```
|
60
|
+
|
61
|
+
Most mail servers do not yet support Unicode mailboxes, so the default here is ASCII.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
EmailAddress.error "Pelé@google.com" #=> "Invalid Recipient/Mailbox"
|
65
|
+
EmailAddress.valid? "Pelé@google.com", local_encoding: :unicode #=> true
|
66
|
+
```
|
67
|
+
|
29
68
|
## Background
|
30
69
|
|
31
70
|
The email address specification is complex and often not what you want
|
@@ -58,15 +97,20 @@ introduces terms to distinguish types of email addresses.
|
|
58
97
|
|
59
98
|
madness!."()<>[]:,;@\\\"!#$%&'*+-/=?^_`{}| ~.a(comment )"@example.org
|
60
99
|
|
100
|
+
* *Base* - A unique mailbox without tags. For gmail, is uses the incoming
|
101
|
+
punctation, essential when building an MD5, SHA1, or SHA256 to match services
|
102
|
+
like Gravatar, and email address digest interchange.
|
103
|
+
|
61
104
|
* *Canonical* - An unique account address, lower-cased, without the
|
62
105
|
tag, and with irrelevant characters stripped.
|
63
106
|
|
64
107
|
clark.kent+scoops@gmail.com => clarkkent@gmail.com
|
65
108
|
|
66
|
-
* *Reference* - The MD5 of the
|
109
|
+
* *Reference* - The MD5 of the Base format, used to share account
|
67
110
|
references without exposing the private email address directly.
|
68
111
|
|
69
|
-
Clark.Kent+scoops@gmail.com =>
|
112
|
+
Clark.Kent+scoops@gmail.com =>
|
113
|
+
clark.kent@gmail.com => 1429a1dfc797d6e93075fef011c373fb
|
70
114
|
|
71
115
|
* *Redacted* - A form of the email address where it is replaced by
|
72
116
|
a SHA1-based version to remove the original address from the
|
@@ -150,8 +194,10 @@ If you are not using Bundler, you need to install the gem yourself.
|
|
150
194
|
|
151
195
|
Require the gem inside your script.
|
152
196
|
|
153
|
-
|
154
|
-
|
197
|
+
```ruby
|
198
|
+
require 'rubygems'
|
199
|
+
require 'email_address'
|
200
|
+
```
|
155
201
|
|
156
202
|
## Usage
|
157
203
|
|
@@ -161,41 +207,58 @@ instantiate an object to inspect the address.
|
|
161
207
|
These top-level helpers return edited email addresses and validation
|
162
208
|
check.
|
163
209
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
210
|
+
```ruby
|
211
|
+
address = "Clark.Kent+scoops@gmail.com"
|
212
|
+
EmailAddress.valid?(address) #=> true
|
213
|
+
EmailAddress.normal(address) #=> "clark.kent+scoops@gmail.com"
|
214
|
+
EmailAddress.canonical(address) #=> "clarkkent@gmail.com"
|
215
|
+
EmailAddress.reference(address) #=> "c5be3597c391169a5ad2870f9ca51901"
|
216
|
+
EmailAddress.redact(address) #=> "{bea3f3560a757f8142d38d212a931237b218eb5e}@gmail.com"
|
217
|
+
EmailAddress.munge(address) #=> "cl*****@gm*****"
|
218
|
+
EmailAddress.matches?(address, 'google') #=> 'google' (true)
|
219
|
+
EmailAddress.error("#bad@example.com") #=> "Invalid Mailbox"
|
220
|
+
```
|
173
221
|
|
174
222
|
Or you can create an instance of the email address to work with it.
|
175
223
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
224
|
+
```ruby
|
225
|
+
email = EmailAddress.new(address) #=> #<EmailAddress::Address:0x007fe6ee150540 ...>
|
226
|
+
email.normal #=> "clark.kent+scoops@gmail.com"
|
227
|
+
email.canonical #=> "clarkkent@gmail.com"
|
228
|
+
email.original #=> "Clark.Kent+scoops@gmail.com"
|
229
|
+
email.valid? #=> true
|
230
|
+
```
|
181
231
|
|
182
232
|
Here are some other methods that are available.
|
183
233
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
234
|
+
```ruby
|
235
|
+
email.redact #=> "{bea3f3560a757f8142d38d212a931237b218eb5e}@gmail.com"
|
236
|
+
email.sha1 #=> "bea3f3560a757f8142d38d212a931237b218eb5e"
|
237
|
+
email.sha256 #=> "9e2a0270f2d6778e5f647fc9eaf6992705ca183c23d1ed1166586fd54e859f75"
|
238
|
+
email.md5 #=> "c5be3597c391169a5ad2870f9ca51901"
|
239
|
+
email.host_name #=> "gmail.com"
|
240
|
+
email.provider #=> :google
|
241
|
+
email.mailbox #=> "clark.kent"
|
242
|
+
email.tag #=> "scoops"
|
243
|
+
|
244
|
+
email.host.exchanger.first[:ip] #=> "2a00:1450:400b:c02::1a"
|
245
|
+
email.host.txt_hash #=> {:v=>"spf1", :redirect=>"\_spf.google.com"}
|
246
|
+
|
247
|
+
EmailAddress.normal("HIRO@こんにちは世界.com")
|
248
|
+
#=> "hiro@xn--28j2a3ar1pp75ovm7c.com"
|
249
|
+
EmailAddress.normal("hiro@xn--28j2a3ar1pp75ovm7c.com", host_encoding: :unicode)
|
250
|
+
#=> "hiro@こんにちは世界.com"
|
251
|
+
```
|
252
|
+
As of release 0.1.17, exchanger_match is no longer used for host provider
|
253
|
+
determination, which designated the set of rules for that domain.
|
254
|
+
Sometimes, as in Google-hosted domains, the address
|
255
|
+
rules are different, notably the optional dots in mailboxes for gmail.com
|
256
|
+
accounts do not apply to other private domains hosted at google.
|
257
|
+
|
258
|
+
To access the provider service, you can now call:
|
191
259
|
|
192
|
-
|
193
|
-
email.host.txt_hash #=> {:v=>"spf1", :redirect=>"\_spf.google.com"}
|
260
|
+
EmailAddress.new("user@hosteddomain.com").host.hosted_provider
|
194
261
|
|
195
|
-
EmailAddress.normal("HIRO@こんにちは世界.com")
|
196
|
-
#=> "hiro@xn--28j2a3ar1pp75ovm7c.com"
|
197
|
-
EmailAddress.normal("hiro@xn--28j2a3ar1pp75ovm7c.com", host_encoding: :unicode)
|
198
|
-
#=> "hiro@こんにちは世界.com"
|
199
262
|
|
200
263
|
#### Rails Validator
|
201
264
|
|
@@ -204,9 +267,30 @@ Specify your email address attributes with `field: :user_email`, or
|
|
204
267
|
`fields: [:email1, :email2]`. If neither is given, it assumes to use the
|
205
268
|
`email` or `email_address` attribute.
|
206
269
|
|
207
|
-
|
208
|
-
|
209
|
-
|
270
|
+
```ruby
|
271
|
+
class User < ActiveRecord::Base
|
272
|
+
validates_with EmailAddress::ActiveRecordValidator, field: :email
|
273
|
+
end
|
274
|
+
```
|
275
|
+
|
276
|
+
#### Rails I18n
|
277
|
+
|
278
|
+
Copy and adapt `lib/email_address/messages.yaml` into your locales and
|
279
|
+
create an after initialization callback:
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
# config/initializers/email_address.rb
|
283
|
+
|
284
|
+
Rails.application.config.after_initialize do
|
285
|
+
I18n.available_locales.each do |locale|
|
286
|
+
translations = I18n.t(:email_address, locale: locale)
|
287
|
+
|
288
|
+
next unless translations.is_a? Hash
|
289
|
+
|
290
|
+
EmailAddress::Config.error_messages translations.transform_keys(&:to_s), locale.to_s
|
291
|
+
end
|
292
|
+
end
|
293
|
+
```
|
210
294
|
|
211
295
|
#### Rails Email Address Type Attribute
|
212
296
|
|
@@ -216,9 +300,11 @@ First, you need to register the type in
|
|
216
300
|
`config/initializers/email_address.rb` along with any global
|
217
301
|
configurations you want.
|
218
302
|
|
219
|
-
|
220
|
-
|
221
|
-
|
303
|
+
```ruby
|
304
|
+
ActiveRecord::Type.register(:email_address, EmailAddress::EmailAddressType)
|
305
|
+
ActiveRecord::Type.register(:canonical_email_address,
|
306
|
+
EmailAddress::CanonicalEmailAddressType)
|
307
|
+
```
|
222
308
|
|
223
309
|
Assume the Users table contains the columns "email" and "canonical_email".
|
224
310
|
We want to normalize the address in "email" and store the canonical/unique
|
@@ -227,39 +313,42 @@ the email attribute is assigned. With the canonical_email column,
|
|
227
313
|
we can look up the User, even it the given email address didn't exactly
|
228
314
|
match the registered version.
|
229
315
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
316
|
+
```ruby
|
317
|
+
class User < ApplicationRecord
|
318
|
+
attribute :email, :email_address
|
319
|
+
attribute :canonical_email, :canonical_email_address
|
320
|
+
|
321
|
+
validates_with EmailAddress::ActiveRecordValidator,
|
322
|
+
fields: %i(email canonical_email)
|
323
|
+
|
324
|
+
def email=(email_address)
|
325
|
+
self[:canonical_email] = email_address
|
326
|
+
self[:email] = email_address
|
327
|
+
end
|
328
|
+
|
329
|
+
def self.find_by_email(email)
|
330
|
+
user = self.find_by(email: EmailAddress.normal(email))
|
331
|
+
user ||= self.find_by(canonical_email: EmailAddress.canonical(email))
|
332
|
+
user ||= self.find_by(canonical_email: EmailAddress.redacted(email))
|
333
|
+
user
|
334
|
+
end
|
335
|
+
|
336
|
+
def redact!
|
337
|
+
self[:canonical_email] = EmailAddress.redact(self.canonical_email)
|
338
|
+
self[:email] = self[:canonical_email]
|
339
|
+
end
|
340
|
+
end
|
341
|
+
```
|
254
342
|
|
255
343
|
Here is how the User model works:
|
256
344
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
345
|
+
```ruby
|
346
|
+
user = User.create(email:"Pat.Smith+registrations@gmail.com")
|
347
|
+
user.email #=> "pat.smith+registrations@gmail.com"
|
348
|
+
user.canonical_email #=> "patsmith@gmail.com"
|
349
|
+
User.find_by_email("PAT.SMITH@GMAIL.COM")
|
350
|
+
#=> #<User email="pat.smith+registrations@gmail.com">
|
351
|
+
```
|
263
352
|
|
264
353
|
The `find_by_email` method looks up a given email address by the
|
265
354
|
normalized form (lower case), then by the canonical form, then finally
|
@@ -282,17 +371,19 @@ which syntax and network validations to perform.
|
|
282
371
|
|
283
372
|
You can compare email addresses:
|
284
373
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
374
|
+
```ruby
|
375
|
+
e1 = EmailAddress.new("Clark.Kent@Gmail.com")
|
376
|
+
e2 = EmailAddress.new("clark.kent+Superman@Gmail.com")
|
377
|
+
e3 = EmailAddress.new(e2.redact)
|
378
|
+
e1.to_s #=> "clark.kent@gmail.com"
|
379
|
+
e2.to_s #=> "clark.kent+superman@gmail.com"
|
380
|
+
e3.to_s #=> "{bea3f3560a757f8142d38d212a931237b218eb5e}@gmail.com"
|
291
381
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
382
|
+
e1 == e2 #=> false (Matches by normalized address)
|
383
|
+
e1.same_as?(e2) #=> true (Matches as canonical address)
|
384
|
+
e1.same_as?(e3) #=> true (Matches as redacted address)
|
385
|
+
e1 < e2 #=> true (Compares using normalized address)
|
386
|
+
```
|
296
387
|
|
297
388
|
#### Matching
|
298
389
|
|
@@ -309,13 +400,15 @@ Matching addresses by simple patterns:
|
|
309
400
|
|
310
401
|
Usage:
|
311
402
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
403
|
+
```ruby
|
404
|
+
e = EmailAddress.new("Clark.Kent@Gmail.com")
|
405
|
+
e.matches?("gmail.com") #=> true
|
406
|
+
e.matches?("google") #=> true
|
407
|
+
e.matches?(".org") #=> false
|
408
|
+
e.matches?("g*com") #=> true
|
409
|
+
e.matches?("gmail.") #=> true
|
410
|
+
e.matches?("*kent*@") #=> true
|
411
|
+
```
|
319
412
|
|
320
413
|
### Configuration
|
321
414
|
|
@@ -323,26 +416,34 @@ You can pass an options hash on the `.new()` and helper class methods to
|
|
323
416
|
control how the library treats that address. These can also be
|
324
417
|
configured during initialization by provider and default (see below).
|
325
418
|
|
326
|
-
|
327
|
-
|
419
|
+
```ruby
|
420
|
+
EmailAddress.new("clark.kent@gmail.com",
|
421
|
+
host_validation: :syntax, host_encoding: :unicode)
|
422
|
+
```
|
328
423
|
|
329
424
|
Globally, you can change and query configuration options:
|
330
425
|
|
331
|
-
|
332
|
-
|
426
|
+
```ruby
|
427
|
+
EmailAddress::Config.setting(:host_validation, :mx)
|
428
|
+
EmailAddress::Config.setting(:host_validation) #=> :mx
|
429
|
+
```
|
333
430
|
|
334
431
|
Or set multiple settings at once:
|
335
432
|
|
336
|
-
|
433
|
+
```ruby
|
434
|
+
EmailAddress::Config.configure(local_downcase: false, host_validation: :syntax)
|
435
|
+
```
|
337
436
|
|
338
437
|
You can add special rules by domain or provider. It takes the options
|
339
438
|
above and adds the :domain_match and :exchanger_match rules.
|
340
439
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
440
|
+
```ruby
|
441
|
+
EmailAddress.define_provider('google',
|
442
|
+
domain_match: %w(gmail.com googlemail.com),
|
443
|
+
exchanger_match: %w(google.com), # Requires host_validation==:mx
|
444
|
+
local_size: 5..64,
|
445
|
+
mailbox_canonical: ->(m) {m.gsub('.','')})
|
446
|
+
```
|
346
447
|
|
347
448
|
The library ships with the most common set of provider rules. It is not meant
|
348
449
|
to house a database of all providers, but a separate `email_address-providers`
|
@@ -358,40 +459,48 @@ matches against the Mail Exchanger (SMTP receivers) hosts defined in
|
|
358
459
|
DNS. If you specify an exchanger pattern, but requires a DNS MX lookup.
|
359
460
|
|
360
461
|
For Rails application, create an initializer file with your default
|
361
|
-
configuration options
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
462
|
+
configuration options.
|
463
|
+
EmailAddress::Config.setting takes a single setting name and value,
|
464
|
+
while EmailAddress::Config.configure takes a hash of multiple settings.
|
465
|
+
|
466
|
+
```ruby
|
467
|
+
# ./config/initializers/email_address.rb
|
468
|
+
EmailAddress::Config.setting( :local_format, :relaxed )
|
469
|
+
EmailAddress::Config.configure( local_format: :relaxed, ... )
|
470
|
+
EmailAddress::Config.provider(:github,
|
471
|
+
host_match: %w(github.com), local_format: :standard)
|
472
|
+
```
|
367
473
|
|
368
474
|
#### Override Error Messaegs
|
369
475
|
|
370
476
|
You can override the default error messages as follows:
|
371
477
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
478
|
+
```ruby
|
479
|
+
EmailAddress::Config.error_messages({
|
480
|
+
invalid_address: "Invalid Email Address",
|
481
|
+
invalid_mailbox: "Invalid Recipient/Mailbox",
|
482
|
+
invalid_host: "Invalid Host/Domain Name",
|
483
|
+
exceeds_size: "Address too long",
|
484
|
+
not_allowed: "Address is not allowed",
|
485
|
+
incomplete_domain: "Domain name is incomplete"}, 'en')
|
486
|
+
```
|
487
|
+
Note: Release 0.1.14 fixed setting error messages by locale.
|
488
|
+
Also, it will accept a ruby "collected" hash as before,
|
379
489
|
|
380
490
|
Full translation support would be ideal though.
|
381
491
|
|
382
|
-
|
383
492
|
### Available Configuration Settings
|
384
493
|
|
385
|
-
* dns_lookup: Enables DNS lookup for validation by
|
386
|
-
* :mx - DNS MX Record lookup
|
387
|
-
* :a - DNS A Record lookup (as some domains don't specify an MX incorrectly)
|
388
|
-
* :off - Do not perform DNS lookup (Test mode, network unavailable)
|
389
|
-
|
390
494
|
* sha1_secret -
|
391
495
|
This application-level secret is appended to the email_address to compute
|
392
496
|
the SHA1 Digest, making it unique to your application so it can't easily be
|
393
497
|
discovered by comparing against a known list of email/sha1 pairs.
|
394
498
|
|
499
|
+
* sha256_secret -
|
500
|
+
This application-level secret is appended to the email_address to compute
|
501
|
+
the SHA256 Digest, making it unique to your application so it can't easily be
|
502
|
+
discovered by comparing against a known list of email/sha256 pairs.
|
503
|
+
|
395
504
|
* munge_string - "*****", the string to replace into munged addresses.
|
396
505
|
|
397
506
|
For local part configuration:
|
@@ -443,7 +552,7 @@ For the mailbox (AKA account, role), without the tag
|
|
443
552
|
:mx Ensure host is configured with DNS MX records
|
444
553
|
:a Ensure host is known to DNS (A Record)
|
445
554
|
:syntax Validate by syntax only, no Network verification
|
446
|
-
:connect Attempt host connection (not
|
555
|
+
:connect Attempt host connection (Dangerous: Do not use)
|
447
556
|
|
448
557
|
* host_size: 1..253,
|
449
558
|
A range specifying the size limit of the host part,
|
@@ -460,14 +569,38 @@ For the mailbox (AKA account, role), without the tag
|
|
460
569
|
* address_size: 3..254,
|
461
570
|
A range specifying the size limit of the complete address
|
462
571
|
|
463
|
-
* address_local: false,
|
464
|
-
Allow localhost, no domain, or local subdomains.
|
465
|
-
|
466
572
|
For provider rules to match to domain names and Exchanger hosts
|
467
573
|
The value is an array of match tokens.
|
468
574
|
* host_match: %w(.org example.com hotmail. user*@ sub.*.com)
|
469
575
|
* exchanger_match: %w(google.com 127.0.0.1 10.9.8.0/24 ::1/64)
|
470
576
|
|
577
|
+
### Namespace conflict resolution
|
578
|
+
|
579
|
+
If your application already uses the `EmailAddress` class name,
|
580
|
+
it's possible to create an alias prior to loading your code:
|
581
|
+
|
582
|
+
For a Rails application, you can do this in `config/application.rb`
|
583
|
+
after the `Bundler.require` line, usually:
|
584
|
+
|
585
|
+
```ruby
|
586
|
+
Bundler.require(*Rails.groups)
|
587
|
+
```
|
588
|
+
|
589
|
+
Add these lines immediately after that point:
|
590
|
+
|
591
|
+
```ruby
|
592
|
+
EmailAddressValidator = EmailAddress
|
593
|
+
Object.send(:remove_const, :EmailAddress)
|
594
|
+
```
|
595
|
+
|
596
|
+
Then your application loads with your EmailAddress class. You may
|
597
|
+
then use this gem with `EmailAddressValidator` or whatever name you
|
598
|
+
gave it above:
|
599
|
+
|
600
|
+
```ruby
|
601
|
+
EmailAddressValidator.valid?("clark.kent@gmail.com") # => true
|
602
|
+
```
|
603
|
+
|
471
604
|
## Notes
|
472
605
|
|
473
606
|
#### Internationalization
|
@@ -487,7 +620,6 @@ Proper personal identity can still be provided using
|
|
487
620
|
[MIME Encoded-Words](http://en.wikipedia.org/wiki/MIME#Encoded-Word)
|
488
621
|
in Email headers.
|
489
622
|
|
490
|
-
|
491
623
|
#### Email Addresses as Sensitive Data
|
492
624
|
|
493
625
|
Like Social Security and Credit Card Numbers, email addresses are
|
data/Rakefile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
|
-
require "bundler/gem_tasks"
|
4
3
|
require "bundler/setup"
|
5
|
-
require
|
4
|
+
require "rake/testtask"
|
6
5
|
|
7
|
-
task :
|
6
|
+
task default: :test
|
8
7
|
|
9
8
|
desc "Run the Test Suite, toot suite"
|
10
9
|
Rake::TestTask.new do |t|
|
data/email_address.gemspec
CHANGED
@@ -1,31 +1,36 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require "email_address/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.description
|
12
|
-
spec.summary
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
6
|
+
spec.name = "email_address"
|
7
|
+
spec.version = EmailAddress::VERSION
|
8
|
+
spec.authors = ["Allen Fair"]
|
9
|
+
spec.email = ["allen.fair@gmail.com"]
|
10
|
+
spec.description = "The EmailAddress Gem to work with and validate email addresses."
|
11
|
+
spec.summary = "This gem provides a ruby language library for working with and validating email addresses. By default, it validates against conventional usage, the format preferred for user email addresses. It can be configured to validate against RFC “Standard” formats, common email service provider formats, and perform DNS validation."
|
12
|
+
spec.homepage = "https://github.com/afair/email_address"
|
13
|
+
spec.license = "MIT"
|
15
14
|
|
16
|
-
spec.
|
17
|
-
spec.
|
18
|
-
spec.
|
15
|
+
spec.required_ruby_version = ">= 2.5", "< 4"
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "rake"
|
22
|
-
spec.add_development_dependency "minitest",
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
spec.add_development_dependency "minitest", "~> 5.11"
|
23
|
+
spec.add_development_dependency "bundler" # , "~> 1.16.0"
|
24
|
+
if RUBY_PLATFORM == "java"
|
25
|
+
spec.add_development_dependency "activerecord", "~> 5.2.6"
|
26
|
+
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "~> 52.7"
|
27
|
+
else
|
28
|
+
spec.add_development_dependency "activerecord", "~> 6.1.4"
|
29
|
+
spec.add_development_dependency "sqlite3"
|
30
|
+
end
|
31
|
+
spec.add_development_dependency "simplecov"
|
32
|
+
spec.add_development_dependency "pry"
|
33
|
+
spec.add_development_dependency "standard", "~> 1.1.1"
|
34
|
+
|
29
35
|
spec.add_dependency "simpleidn"
|
30
|
-
spec.add_dependency "netaddr"
|
31
36
|
end
|