is_email 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,158 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsEmail
4
+ # Gives contextual references to a diagnosis
5
+ #
6
+ # @api private
7
+ class Reference
8
+ DATA = {
9
+ "local-part" => {
10
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
11
+ citation: "RFC5322 section 3.4.1"
12
+ }.freeze,
13
+ "local-part-maximum" => {
14
+ link: "http://tools.ietf.org/html/rfc5321#section-4.5.3.1.1",
15
+ citation: "RFC5321 section 4.5.3.1.1"
16
+ }.freeze,
17
+ "obs-local-part" => {
18
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
19
+ citation: "RFC 5322 section 3.4.1"
20
+ }.freeze,
21
+ "dot-atom" => {
22
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
23
+ citation: "RFC 5322 section 3.4.1"
24
+ }.freeze,
25
+ "quoted-string" => {
26
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
27
+ citation: "RFC 5322 section 3.4.1"
28
+ }.freeze,
29
+ "CFWS-near-at" => {
30
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
31
+ citation: "RFC 5322 section 3.4.1"
32
+ }.freeze,
33
+ "SHOULD-NOT" => {
34
+ link: "http://tools.ietf.org/html/rfc2119",
35
+ citation: "RFC2119 section 4"
36
+ }.freeze,
37
+ "atext" => {
38
+ link: "http://tools.ietf.org/html/rfc5322#section-3.2.3",
39
+ citation: "RFC5322 section 3.2.3"
40
+ }.freeze,
41
+ "obs-domain" => {
42
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
43
+ citation: "RFC5322 section 3.4.1"
44
+ }.freeze,
45
+ "domain-RFC5322" => {
46
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
47
+ citation: "RFC5322 section 3.4.1"
48
+ }.freeze,
49
+ "domain-RFC5321" => {
50
+ link: "http://tools.ietf.org/html/rfc5321#section-4.1.2",
51
+ citation: "RFC5321 section 4.1.2"
52
+ }.freeze,
53
+ "label" => {
54
+ link: "http://tools.ietf.org/html/rfc1035#section-2.3.4",
55
+ citation: "RFC1035 section 2.3.4"
56
+ }.freeze,
57
+ "CRLF" => {
58
+ link: "http://tools.ietf.org/html/rfc5234#section-2.3",
59
+ citation: "RFC5234 section 2.3"
60
+ }.freeze,
61
+ "CFWS" => {
62
+ link: "http://tools.ietf.org/html/rfc5322#section-3.2.2",
63
+ citation: "RFC5322 section 3.2.2"
64
+ }.freeze,
65
+ "domain-literal" => {
66
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
67
+ citation: "RFC5322 section 3.4.1"
68
+ }.freeze,
69
+ "address-literal" => {
70
+ link: "http://tools.ietf.org/html/rfc5321#section-4.1.2",
71
+ citation: "RFC5321 section 4.1.2"
72
+ }.freeze,
73
+ "address-literal-IPv4" => {
74
+ link: "http://tools.ietf.org/html/rfc5321#section-4.1.3",
75
+ citation: "RFC5321 section 4.1.3"
76
+ }.freeze,
77
+ "address-literal-IPv6" => {
78
+ link: "http://tools.ietf.org/html/rfc5321#section-4.1.3",
79
+ citation: "RFC5321 section 4.1.3"
80
+ }.freeze,
81
+ "dtext" => {
82
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
83
+ citation: "RFC5322 section 3.4.1"
84
+ }.freeze,
85
+ "obs-dtext" => {
86
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
87
+ citation: "RFC5322 section 3.4.1"
88
+ }.freeze,
89
+ "qtext" => {
90
+ link: "http://tools.ietf.org/html/rfc5322#section-3.2.4",
91
+ citation: "RFC5322 section 3.2.4"
92
+ }.freeze,
93
+ "obs-qtext" => {
94
+ link: "http://tools.ietf.org/html/rfc5322#section-4.1",
95
+ citation: "RFC5322 section 4.1"
96
+ }.freeze,
97
+ "ctext" => {
98
+ link: "http://tools.ietf.org/html/rfc5322#section-3.2.3",
99
+ citation: "RFC5322 section 3.2.3"
100
+ }.freeze,
101
+ "obs-ctext" => {
102
+ link: "http://tools.ietf.org/html/rfc5322#section-4.1",
103
+ citation: "RFC5322 section 4.1"
104
+ }.freeze,
105
+ "quoted-pair" => {
106
+ link: "http://tools.ietf.org/html/rfc5322#section-3.2.1",
107
+ citation: "RFC5322 section 3.2.1"
108
+ }.freeze,
109
+ "obs-qp" => {
110
+ link: "http://tools.ietf.org/html/rfc5322#section-4.1",
111
+ citation: "RFC5322 section 4.1"
112
+ }.freeze,
113
+ "TLD" => {
114
+ link: "http://tools.ietf.org/html/rfc5321#section-2.3.5",
115
+ citation: "RFC5321 section 2.3.5"
116
+ }.freeze,
117
+ "TLD-format" => {
118
+ link: "http://www.rfc-editor.org/errata_search.php?eid=1353",
119
+ citation: "John Klensin, RFC 1123 erratum 1353"
120
+ }.freeze,
121
+ "mailbox-maximum" => {
122
+ link: "http://www.rfc-editor.org/errata_search.php?eid=1690",
123
+ citation: "Dominic Sayers, RFC 3696 erratum 1690"
124
+ }.freeze,
125
+ "domain-maximum" => {
126
+ link: "http://tools.ietf.org/html/rfc1035#section-4.5.3.1.2",
127
+ citation: "RFC 5321 section 4.5.3.1.2"
128
+ }.freeze,
129
+ "mailbox" => {
130
+ link: "http://tools.ietf.org/html/rfc5321#section-4.1.2",
131
+ citation: "RFC 5321 section 4.1.2"
132
+ }.freeze,
133
+ "addr-spec" => {
134
+ link: "http://tools.ietf.org/html/rfc5322#section-3.4.1",
135
+ citation: "RFC 5322 section 3.4.1"
136
+ }.freeze
137
+ }.freeze
138
+
139
+ # @param name [String]
140
+ # @return [void]
141
+ def initialize(name = "")
142
+ @data = DATA.fetch(name) { {link: "", citation: ""} }
143
+ @citation = @data[:citation]
144
+ @link = @data[:link]
145
+ end
146
+
147
+ # @return [String]
148
+ attr_reader :citation
149
+
150
+ # @return [String]
151
+ attr_reader :link
152
+
153
+ private
154
+
155
+ # @return [Hash<Symbol, String>]
156
+ attr_reader :data
157
+ end
158
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsEmail
4
+ module Validators
5
+ # An abstract base class for validators
6
+ #
7
+ # @api private
8
+ class Base
9
+ # Checks whether an address is valid, optionally returning a diagnosis
10
+ #
11
+ # @param address [String] the address to check
12
+ # @param diagnose [Boolean] whether to return a diagnosis or not
13
+ # @return [Boolean, Diagnosis] when not diagnosing, true when the address
14
+ # is valid and false otherwise; when diagnosing, the diagnosis for the
15
+ # status of the address
16
+ # :nocov:
17
+ def email?(address, diagnose: false)
18
+ raise NotImplementedError
19
+ end
20
+ # :nocov:
21
+ end
22
+ end
23
+ end