rfc822 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +65 -0
- data/lib/rfc822.rb +27 -2
- metadata +14 -12
data/README.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
= Introduction
|
2
|
+
|
3
|
+
This is a simple gem for Ruby that simplifies validating email addresses. It conforms with RFC2822.
|
4
|
+
|
5
|
+
Here comes a quick code sample. Currently no docs.
|
6
|
+
|
7
|
+
require 'rfc822'
|
8
|
+
|
9
|
+
# To test if whole string is an email... ugly way
|
10
|
+
# (returns 0 on success, nil on failure):
|
11
|
+
|
12
|
+
"tom@example.com" =~ RFC822::EMAIL_REGEXP_WHOLE
|
13
|
+
|
14
|
+
# or nice one (returns true/false):
|
15
|
+
|
16
|
+
"tom@example.com".is_email?
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
# To test if string contains an email... ugly way
|
21
|
+
# (returns 0 on success, nil on failure):
|
22
|
+
|
23
|
+
"demo john@example.comFooBar" =~ RFC822::EMAIL_REGEXP_PART
|
24
|
+
|
25
|
+
# or nice one (returns true/false):
|
26
|
+
|
27
|
+
"demo john@example.comFooBar".contains_email?
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
# To scan for emails within a string... ugly way
|
32
|
+
# (returns an array):
|
33
|
+
|
34
|
+
"something a@example.com xyz".scan(RFC822::EMAIL_REGEXP_PART)
|
35
|
+
|
36
|
+
# or nice one (also returns an array):
|
37
|
+
|
38
|
+
"something a@example.com xyz".scan_for_emails
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
= Installation
|
44
|
+
|
45
|
+
=== Ruby Versions
|
46
|
+
|
47
|
+
Code was tested with ruby-1.8.7-p334 [ i386 ] and ruby-1.9.2-p180 [ i386 ] under RVM.
|
48
|
+
|
49
|
+
=== Gems
|
50
|
+
|
51
|
+
The gems are hosted at Rubygems.org[http://rubygems.org]. Make sure you're
|
52
|
+
using the latest version of rubygems:
|
53
|
+
|
54
|
+
$ gem update --system
|
55
|
+
|
56
|
+
Then you can install the jack-ffi gem as follows:
|
57
|
+
|
58
|
+
$ gem install rfc822
|
59
|
+
|
60
|
+
=== From the GitHub source
|
61
|
+
|
62
|
+
The source code is available at http://github.com/saepia/rfc822.
|
63
|
+
You can either clone the git repository or download a tarball or zip file.
|
64
|
+
Once you have the source, you can unpack it and use from wherever you downloaded.
|
65
|
+
|
data/lib/rfc822.rb
CHANGED
@@ -13,7 +13,32 @@ module RFC822
|
|
13
13
|
LOCAL_PART = "#{WORD}(?:\\x2e#{WORD})*"
|
14
14
|
ADDR_SPEC = "#{LOCAL_PART}\\x40#{DOMAIN}"
|
15
15
|
|
16
|
-
EMAIL_REGEXP_WHOLE =
|
17
|
-
EMAIL_REGEXP_PART =
|
16
|
+
EMAIL_REGEXP_WHOLE = Regexp.new("^#{ADDR_SPEC}$", nil, 'n')
|
17
|
+
EMAIL_REGEXP_PART = Regexp.new("#{ADDR_SPEC}", nil, 'n')
|
18
18
|
end
|
19
19
|
|
20
|
+
class String
|
21
|
+
def is_email?
|
22
|
+
if RUBY_VERSION >= "1.9"
|
23
|
+
(self.force_encoding("BINARY") =~ RFC822::EMAIL_REGEXP_WHOLE) != nil
|
24
|
+
else
|
25
|
+
(self =~ RFC822::EMAIL_REGEXP_WHOLE) != nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def contains_email?
|
30
|
+
if RUBY_VERSION >= "1.9"
|
31
|
+
(self.force_encoding("BINARY") =~ RFC822::EMAIL_REGEXP_PART) != nil
|
32
|
+
else
|
33
|
+
(self =~ RFC822::EMAIL_REGEXP_PART) != nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def scan_for_emails
|
38
|
+
if RUBY_VERSION >= "1.9"
|
39
|
+
self.force_encoding("BINARY").scan(RFC822::EMAIL_REGEXP_PART)
|
40
|
+
else
|
41
|
+
self.scan(RFC822::EMAIL_REGEXP_PART)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
name: rfc822
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
hash: 27
|
5
|
-
prerelease:
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marcin Lewandowski
|
@@ -15,27 +15,29 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-11-21 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
22
22
|
description: Gem containing just e-mail validation regexp based on RFC822, please use RFC822::EMAIL_REGEXP_WHOLE for checking if whole string is an valid email, and RFC822::EMAIL_REGEXP_PART for e.g. scanning a string for e-mail address extraction.
|
23
|
-
email:
|
23
|
+
email:
|
24
|
+
- edek123456@gmail.com
|
24
25
|
executables: []
|
25
26
|
|
26
27
|
extensions: []
|
27
28
|
|
28
|
-
extra_rdoc_files:
|
29
|
-
|
29
|
+
extra_rdoc_files:
|
30
|
+
- README.rdoc
|
30
31
|
files:
|
31
32
|
- lib/rfc822.rb
|
33
|
+
- README.rdoc
|
32
34
|
has_rdoc: true
|
33
|
-
homepage: http://saepia
|
35
|
+
homepage: http://github.com/saepia/rfc822
|
34
36
|
licenses: []
|
35
37
|
|
36
38
|
post_install_message:
|
37
|
-
rdoc_options:
|
38
|
-
|
39
|
+
rdoc_options: []
|
40
|
+
|
39
41
|
require_paths:
|
40
42
|
- lib
|
41
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -59,9 +61,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
61
|
requirements: []
|
60
62
|
|
61
63
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.
|
64
|
+
rubygems_version: 1.6.2
|
63
65
|
signing_key:
|
64
66
|
specification_version: 3
|
65
|
-
summary: Gem containing just e-mail validation regexp based on
|
67
|
+
summary: Gem containing just e-mail validation regexp based on RFC822, please use RFC822::EMAIL_REGEXP_WHOLE for checking if whole string is an valid email, and RFC822::EMAIL_REGEXP_PART for e.g. scanning a string for e-mail address extraction.
|
66
68
|
test_files: []
|
67
69
|
|