email-validator-1.4.0/0000755000000000000000000000000012317564142013271 5ustar rootrootemail-validator-1.4.0/LICENSE0000644000000000000000000000204312317564142014275 0ustar rootrootCopyright (c) 2009 Brian Alexander Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. email-validator-1.4.0/lib/0000755000000000000000000000000012317564142014037 5ustar rootrootemail-validator-1.4.0/lib/email_validator/0000755000000000000000000000000012317564142017173 5ustar rootrootemail-validator-1.4.0/lib/email_validator/strict.rb0000644000000000000000000000020612317564142021026 0ustar rootroot# require this file to enable :strict_mode by default require 'email_validator' EmailValidator::default_options[:strict_mode] = trueemail-validator-1.4.0/lib/email_validator.rb0000644000000000000000000000106512317564142017522 0ustar rootroot# Based on work from http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/ class EmailValidator < ActiveModel::EachValidator @@default_options = {} def self.default_options @@default_options end def validate_each(record, attribute, value) options = @@default_options.merge(self.options) name_validation = options[:strict_mode] ? "-a-z0-9+._" : "^@\\s" unless value =~ /\A\s*([#{name_validation}]{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i record.errors.add(attribute, options[:message] || :invalid) end end end email-validator-1.4.0/.travis.yml0000644000000000000000000000012712317564142015402 0ustar rootrootrvm: - 1.8.7 - 1.9.2 - 1.9.3 - 2.0.0 - jruby-18mode - jruby-19mode - ree email-validator-1.4.0/Rakefile0000644000000000000000000000113512317564142014736 0ustar rootrootrequire 'bundler' require 'rake/testtask' begin require 'rdoc/task' rescue LoadError require 'rake/rdoctask' # deprecated in Ruby 1.9.3 but needed for Ruby 1.8.7 and JRuby end require 'rspec/core/rake_task' Bundler::GemHelper.install_tasks RSpec::Core::RakeTask.new do |t| t.rspec_opts = %w(--format documentation --colour) end Rake::RDocTask.new do |rdoc| version = File.exist?('VERSION') ? File.read('VERSION') : "" rdoc.rdoc_dir = 'rdoc' rdoc.title = "email_validator #{version}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end task :default => 'spec'email-validator-1.4.0/README.md0000644000000000000000000000231212317564142014546 0ustar rootroot[![Build Status](https://secure.travis-ci.org/balexand/email_validator.png)](http://travis-ci.org/balexand/email_validator) ## Usage Add to your Gemfile: ```ruby gem 'email_validator' ``` Run: ``` bundle install ``` Then add the following to your model: ```ruby validates :my_email_attribute, :email => true ``` ## Strict mode In order to have stricter validation (according to http://www.remote.org/jochen/mail/info/chars.html) enable strict mode. You can do this globally by adding the following to your Gemfile: ```ruby gem 'email_validator', :require => 'email_validator/strict' ``` Or you can do this in a specific `validates` call: ```ruby validates :my_email_attribute, :email => {:strict_mode => true} ``` ## Thread safety This gem is thread safe, with one caveat: `EmailValidator.default_options` must be configured before use in a multi-threaded environment. If you configure `default_options` in a Rails initializer file, then you're good to go since initializers are run before worker threads are spawned. ## Credit Based on http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3 Regular Expression based on http://fightingforalostcause.net/misc/2006/compare-email-regex.php tests. email-validator-1.4.0/spec/0000755000000000000000000000000012317564142014223 5ustar rootrootemail-validator-1.4.0/spec/spec_helper.rb0000644000000000000000000000061012317564142017036 0ustar rootrootrequire 'rubygems' require 'rspec' require 'active_model' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'email_validator' class TestModel include ActiveModel::Validations def initialize(attributes = {}) @attributes = attributes end def read_attribute_for_validation(key) @attributes[key] end endemail-validator-1.4.0/spec/email_validator_spec.rb0000644000000000000000000001156612317564142020727 0ustar rootrootrequire 'spec_helper' class TestUser < TestModel validates :email, :email => true end class StrictUser < TestModel validates :email, :email => {:strict_mode => true} end class TestUserAllowsNil < TestModel validates :email, :email => {:allow_nil => true} end class TestUserAllowsNilFalse < TestModel validates :email, :email => {:allow_nil => false} end class TestUserWithMessage < TestModel validates :email_address, :email => {:message => 'is not looking very good!'} end describe EmailValidator do describe "validation" do context "given the valid emails" do [ "a+b@plus-in-local.com", "a_b@underscore-in-local.com", "user@example.com", " user@example.com ", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org", "01234567890@numbers-in-local.net", "a@single-character-in-local.org", "one-character-third-level@a.example.com", "single-character-in-sld@x.org", "local@dash-in-sld.com", "letters-in-sld@123.com", "one-letter-sld@x.org", "uncommon-tld@sld.museum", "uncommon-tld@sld.travel", "uncommon-tld@sld.mobi", "country-code-tld@sld.uk", "country-code-tld@sld.rw", "local@sld.newTLD", "local@sub.domains.com", "aaa@bbb.co.jp", "nigel.worthington@big.co.uk", "f@c.com", "areallylongnameaasdfasdfasdfasdf@asdfasdfasdfasdfasdf.ab.cd.ef.gh.co.ca" ].each do |email| it "#{email.inspect} should be valid" do TestUser.new(:email => email).should be_valid end it "#{email.inspect} should be valid in strict_mode" do StrictUser.new(:email => email).should be_valid end end end context "given the invalid emails" do [ "", "f@s", "f@s.c", "@bar.com", "test@example.com@example.com", "test@", "@missing-local.org", "a b@space-in-local.com", "! \#$%\`|@invalid-characters-in-local.org", "<>@[]\`|@even-more-invalid-characters-in-local.org", "missing-sld@.com", "invalid-characters-in-sld@! \"\#$%(),/;<>_[]\`|.org", "missing-dot-before-tld@com", "missing-tld@sld.", " ", "missing-at-sign.net", "unbracketed-IP@127.0.0.1", "invalid-ip@127.0.0.1.26", "another-invalid-ip@127.0.0.256", "IP-and-port@127.0.0.1:25", "the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net", "user@example.com\n" ].each do |email| it "#{email.inspect} should not be valid" do TestUser.new(:email => email).should_not be_valid end it "#{email.inspect} should not be valid in strict_mode" do StrictUser.new(:email => email).should_not be_valid end end end context "given the emails that should be invalid in strict_mode but valid in normal mode" do [ "hans,peter@example.com", "hans(peter@example.com", "hans)peter@example.com", "partially.\"quoted\"@sld.com", "&'*+-./=?^_{}~@other-valid-characters-in-local.net", "mixed-1234-in-{+^}-local@sld.net" ].each do |email| it "#{email.inspect} should be valid" do TestUser.new(:email => email).should be_valid end it "#{email.inspect} should not be valid in strict_mode" do StrictUser.new(:email => email).should_not be_valid end end end end describe "error messages" do context "when the message is not defined" do subject { TestUser.new :email => 'invalidemail@' } before { subject.valid? } it "should add the default message" do subject.errors[:email].should include "is invalid" end end context "when the message is defined" do subject { TestUserWithMessage.new :email_address => 'invalidemail@' } before { subject.valid? } it "should add the customized message" do subject.errors[:email_address].should include "is not looking very good!" end end end describe "nil email" do it "should not be valid when :allow_nil option is missing" do TestUser.new(:email => nil).should_not be_valid end it "should be valid when :allow_nil options is set to true" do TestUserAllowsNil.new(:email => nil).should be_valid end it "should not be valid when :allow_nil option is set to false" do TestUserAllowsNilFalse.new(:email => nil).should_not be_valid end end describe "default_options" do context "when 'email_validator/strict' has been required" do before { require 'email_validator/strict' } it "should validate using strict mode" do TestUser.new(:email => "&'*+-./=?^_{}~@other-valid-characters-in-local.net").should_not be_valid end end end end email-validator-1.4.0/.gitignore0000644000000000000000000000023712317564142015263 0ustar rootroot## MAC OS .DS_Store ## TEXTMATE *.tmproj tmtags ## EMACS *~ \#* .\#* ## VIM *.swp ## PROJECT::GENERAL Gemfile.lock coverage rdoc pkg ## PROJECT::SPECIFIC email-validator-1.4.0/checksums.yaml.gz0000444000000000000000000000041412317564142016556 0ustar rootrootUQe;V0 "O,YNGG kwfu.ox\||߯3#+Lր535c$t k{fyFJ8<ƢњzJcR?nKx1()Sj ڇ?m񆔉{ .q(Huȕ8w ARf.5%Ή io`gln≔WYD(K薧%?:/#^6\XN2mAK8dy$Qemail-validator-1.4.0/metadata.yml0000644000000000000000000000440412317564142015576 0ustar rootroot--- !ruby/object:Gem::Specification name: email_validator version: !ruby/object:Gem::Version version: 1.4.0 platform: ruby authors: - Brian Alexander autorequire: bindir: bin cert_chain: [] date: 2013-03-29 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: activemodel requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' description: 'An email validator for Rails 3+. See homepage for details: http://github.com/balexand/email_validator' email: balexand@gmail.com executables: [] extensions: [] extra_rdoc_files: - LICENSE files: - .document - .gitignore - .travis.yml - Gemfile - LICENSE - README.md - Rakefile - email_validator.gemspec - lib/email_validator.rb - lib/email_validator/strict.rb - spec/email_validator_spec.rb - spec/spec_helper.rb homepage: https://github.com/balexand/email_validator licenses: [] metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.0.0 signing_key: specification_version: 4 summary: An email validator for Rails 3+. test_files: [] email-validator-1.4.0/.document0000644000000000000000000000007412317564142015111 0ustar rootrootREADME.rdoc lib/**/*.rb bin/* features/**/*.feature LICENSE email-validator-1.4.0/Gemfile0000644000000000000000000000004612317564142014564 0ustar rootrootsource "https://rubygems.org" gemspecemail-validator-1.4.0/email_validator.gemspec0000644000000000000000000000126612317564142017777 0ustar rootrootGem::Specification.new do |s| s.name = %q{email_validator} s.version = "1.4.0" s.authors = ["Brian Alexander"] s.description = %q{An email validator for Rails 3+. See homepage for details: http://github.com/balexand/email_validator} s.email = %q{balexand@gmail.com} s.extra_rdoc_files = [ "LICENSE", ] s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {spec}/*`.split("\n") s.homepage = %q{https://github.com/balexand/email_validator} s.require_paths = %w(lib) s.summary = %q{An email validator for Rails 3+.} s.add_dependency("activemodel", ">= 0") s.add_development_dependency("rake") s.add_development_dependency("rspec", ">= 0") end