kawaii_email_address 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 729fb01293d001a4808d34917d5c15f127f7d0fc
4
+ data.tar.gz: 83e69e343781d45c9bfa9cd0850fac1cf659d5cb
5
+ SHA512:
6
+ metadata.gz: 3ec7512ebfa5577d26a3e08c2c29988c15b1d650f068d179056803de9a42f3400b28204640372371507d8df5f3070d04306472eb3511a19259d348dc067bf362
7
+ data.tar.gz: 33ca8999e410ea492652ab6a151ec8fe257812d43a5f05592d0e716bb71c5f767614b5b7c6c98ac50c1608c69eee09894b37acb5b17f18750dcae8240f307da5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kawaii_email_address.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tagaki Aki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # KawaiiEmailAddress
2
+
3
+ Extraction of validate logic from `validates_email_format_of` to support japanese docomo/au kawaii addresses.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'kawaii_email_address'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install kawaii_email_address
18
+
19
+ ## Usage
20
+
21
+ It's NOT Rails' validator. Use it with this
22
+
23
+ ```
24
+ # acdept `kawaii` local part with docomo or ezweb.
25
+ KawaiiEmailAddress::Validator.new('....-_-....@docomo.ne.jp').valid? # => true
26
+
27
+ # reject with other domains.
28
+ KawaiiEmailAddress::Validator.new('u3u...chu@example.com').valid? # => false
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
38
+
39
+ ## THANX
40
+
41
+ This library based on https://github.com/alexdunae/validates_email_format_of
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.pattern = "spec/**/*_spec.rb"
8
+ end
9
+
10
+ task :default => [:spec]
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kawaii_email_address/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kawaii_email_address"
8
+ spec.version = KawaiiEmailAddress::VERSION
9
+ spec.authors = ["moro", "akiinyo"]
10
+ spec.email = ["moronatural@gmail.com", "aki.hosecarioka@gmail.com"]
11
+ spec.description = %q{Extraction of validate logic from `validates_email_format_of` to support docomo addresses}
12
+ spec.summary = %q{Extraction of validate logic from `validates_email_format_of` to support docomo addresses}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
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
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,116 @@
1
+ require 'kawaii_email_address/version'
2
+ require 'ipaddr'
3
+
4
+ module KawaiiEmailAddress
5
+ class Validator
6
+ LocalPartChars = ((?A..?Z).to_a + (?a..?z).to_a + (0..9).to_a).join + %q[!#$%&'*-/=?+-^_`{|}~]
7
+ LocalPartQuotedStringChars = %q[()<>[]:;@,.] << ' '
8
+
9
+ PERIOD = '.'
10
+ BACKSLASH = '\\'
11
+ DOUBLE_QUOTE = '"'
12
+ DOMAIN_LITERAL_RE = /\A\[(?<ip_addr>.+)\]\z/
13
+
14
+ attr_reader :local_part, :domain_part
15
+
16
+ class << self
17
+ attr_accessor :period_restriction_violate_domains
18
+ end
19
+
20
+ self.period_restriction_violate_domains = %w[docomo.ne.jp ezweb.ne.jp]
21
+
22
+ def initialize(address)
23
+ @domain_part, @local_part = address.reverse.split('@', 2).map(&:reverse)
24
+ end
25
+
26
+ def valid?
27
+ valid_local_part? && valid_domain_part?
28
+ end
29
+
30
+ def to_s
31
+ [local_part, domain_part].join('@')
32
+ end
33
+
34
+ def valid_local_part?
35
+ return false if invalid_period_position?
36
+
37
+ in_quoted_pair = false
38
+ in_quoted_string = false
39
+
40
+ is_valid = local_part.chars.each.with_index.all? do |char, i|
41
+ # accept anything if it's got a backslash before it
42
+ if in_quoted_pair
43
+ in_quoted_pair = false
44
+ next true
45
+ end
46
+
47
+ case char
48
+ when BACKSLASH # backslash signifies the start of a quoted pair
49
+ # must be in quoted string per http://www.rfc-editor.org/errata_search.php?rfc=3696
50
+ if (i < local_part.length - 1) && in_quoted_string
51
+ in_quoted_pair = true
52
+ next true
53
+ end
54
+
55
+ when DOUBLE_QUOTE # double quote delimits quoted strings
56
+ in_quoted_string = !in_quoted_string
57
+ next true
58
+
59
+ when PERIOD
60
+ period_restriction_violate_domain? ||
61
+ in_quoted_string ||
62
+ local_part[i + 1] != PERIOD
63
+
64
+ else
65
+ LocalPartChars.include?(char) || \
66
+ (in_quoted_string && LocalPartQuotedStringChars.include?(char))
67
+
68
+ end
69
+ end
70
+
71
+ is_valid && !in_quoted_string
72
+ end
73
+
74
+ def valid_domain_part?
75
+ if match = DOMAIN_LITERAL_RE.match(domain_part)
76
+ valid_domain_literal?(match[:ip_addr])
77
+ else
78
+ valid_fqdn_domain_part?
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def valid_domain_literal?(domain)
85
+ begin
86
+ IPAddr.new(domain)
87
+ rescue IPAddr::InvalidAddressError
88
+ false
89
+ end
90
+ end
91
+
92
+ def valid_fqdn_domain_part?
93
+ parts = domain_part.downcase.split('.', -1)
94
+
95
+ return false if parts.length <= 1
96
+
97
+ return false if parts.any? do |part|
98
+ part.nil? || part.empty? || part !~ /\A[[:alnum:]\-]+\z/ || part.start_with?('-') || part.end_with?('-')
99
+ end
100
+
101
+ return false if parts.last.length < 2 || parts.last !~ /[a-z\-]/
102
+
103
+ return true
104
+ end
105
+
106
+ def period_restriction_violate_domain?
107
+ self.class.period_restriction_violate_domains.include?(domain_part)
108
+ end
109
+
110
+ def invalid_period_position?
111
+ return false if period_restriction_violate_domain?
112
+
113
+ local_part.start_with?(PERIOD) || local_part.end_with?(PERIOD)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,3 @@
1
+ module KawaiiEmailAddress
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,42 @@
1
+ require 'kawaii_email_address/validator'
2
+
3
+ describe KawaiiEmailAddress::Validator do
4
+
5
+ RSpec::Matchers.define(:pass_validation_with) do |addr|
6
+ match do |validator_klass|
7
+ validator_klass.new(addr).valid?
8
+ end
9
+ end
10
+
11
+ subject { KawaiiEmailAddress::Validator }
12
+
13
+ it { should pass_validation_with 'a@example.com' }
14
+ it { should pass_validation_with 'a.!/==@example.com' }
15
+
16
+ it { should_not pass_validation_with 'a@bc@example.com' }
17
+ it { should_not pass_validation_with 'a..b@example.com' }
18
+ it { should_not pass_validation_with 'a.@example.com' }
19
+ it { should_not pass_validation_with '.aaa@example.com' }
20
+
21
+ it { should pass_validation_with '"a@a"@example.com' }
22
+ it { should pass_validation_with "'or'1'='1'--@example.com" }
23
+
24
+ context 'kawaii: aka.docomo' do
25
+ it { should pass_validation_with 'mail..example@docomo.ne.jp' }
26
+ it { should pass_validation_with 'example.@docomo.ne.jp' }
27
+ it { should pass_validation_with '.example@docomo.ne.jp' }
28
+
29
+ it { should pass_validation_with 'u3u..chu.@docomo.ne.jp' }
30
+ it { should pass_validation_with '....-_-....@docomo.ne.jp' }
31
+ end
32
+
33
+ context 'domain part' do
34
+ it { should_not pass_validation_with 'example@c' }
35
+ it { should_not pass_validation_with 'example@-com.jp' }
36
+ it { should_not pass_validation_with 'example@com.jp-' }
37
+ it { should_not pass_validation_with 'example@com.j' }
38
+
39
+ it { should pass_validation_with 'example@[115.146.17.185]' }
40
+ it { should_not pass_validation_with 'example@[115.146.1722]' }
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kawaii_email_address
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - moro
8
+ - akiinyo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Extraction of validate logic from `validates_email_format_of` to support
57
+ docomo addresses
58
+ email:
59
+ - moronatural@gmail.com
60
+ - aki.hosecarioka@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rspec
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - kawaii_email_address.gemspec
72
+ - lib/kawaii_email_address/validator.rb
73
+ - lib/kawaii_email_address/version.rb
74
+ - spec/kawaii_email_address_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Extraction of validate logic from `validates_email_format_of` to support
100
+ docomo addresses
101
+ test_files:
102
+ - spec/kawaii_email_address_spec.rb
103
+ - spec/spec_helper.rb