Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
inherit_from: .rubocop_todo.yml

# The behavior of RuboCop can be controlled via the .rubocop.yml
# configuration file. It makes it possible to enable/disable
# certain cops (checks) and to alter their behavior if they accept
# any parameters. The file can be placed either in your home
# directory or in some project directory.
#
# RuboCop will start looking for the configuration file in the directory
# where the inspected file is and continue its way up to the root directory.
#
# See https://docs.rubocop.org/rubocop/configuration

Style/StringLiterals:
EnforcedStyle: double_quotes
Gemspec/OrderedDependencies:
Enabled: no
263 changes: 263 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-02-14 12:05:00 UTC using RuboCop version 1.71.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/valid_email2/email_validator.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'lib/valid_email2.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/SpaceAfterComma:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator, EnforcedStyleForRationalLiterals.
# SupportedStylesForExponentOperator: space, no_space
# SupportedStylesForRationalLiterals: space, no_space
Layout/SpaceAroundOperators:
Exclude:
- 'lib/valid_email2.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Lint/ScriptPermission:
Exclude:
- 'pull_mailchecker_emails.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'lib/valid_email2/dns.rb'

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 63

# Offense count: 11
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 348

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 105

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 44

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 32

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 44

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# AllowedMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'lib/valid_email2/address.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- 'lib/valid_email2/email_validator.rb'

# Offense count: 4
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/valid_email2.rb'
- 'lib/valid_email2/address.rb'
- 'lib/valid_email2/dns.rb'
- 'lib/valid_email2/email_validator.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/ExpandPathArguments:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 10
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- '**/*.arb'
- 'Gemfile'
- 'Rakefile'
- 'gemfiles/activemodel6.gemfile'
- 'gemfiles/activemodel7.gemfile'
- 'gemfiles/activemodel8.gemfile'
- 'lib/valid_email2/dns.rb'
- 'lib/valid_email2/email_validator.rb'
- 'pull_mailchecker_emails.rb'
- 'spec/spec_helper.rb'
- 'valid_email2.gemspec'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
Style/GuardClause:
Exclude:
- 'lib/valid_email2/dns.rb'
- 'lib/valid_email2/email_validator.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedReceivers.
# AllowedReceivers: Thread.current
Style/HashEachMethods:
Exclude:
- 'lib/valid_email2/dns.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
# SupportedShorthandSyntax: always, never, either, consistent, either_consistent
Style/HashSyntax:
Exclude:
- 'Rakefile'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Style/MutableConstant:
Exclude:
- 'lib/valid_email2/dns.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Strict, AllowedNumbers, AllowedPatterns.
Style/NumericLiterals:
MinDigits: 6

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/valid_email2/address.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/Proc:
Exclude:
- 'spec/valid_email2_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'lib/valid_email2/address.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/SlicingWithRange:
Exclude:
- 'lib/valid_email2/address.rb'

# Offense count: 9
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowModifier.
Style/SoleNestedConditional:
Exclude:
- 'lib/valid_email2/email_validator.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: RequireEnglish, EnforcedStyle.
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
Style/SpecialGlobalVars:
Exclude:
- 'spec/spec_helper.rb'
- 'valid_email2.gemspec'

# Offense count: 35
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'Gemfile'
- 'gemfiles/activemodel6.gemfile'
- 'gemfiles/activemodel7.gemfile'
- 'gemfiles/activemodel8.gemfile'
- 'lib/valid_email2.rb'
- 'lib/valid_email2/address.rb'
- 'lib/valid_email2/email_validator.rb'
- 'spec/spec_helper.rb'
- 'spec/valid_email2_spec.rb'
- 'valid_email2.gemspec'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods.
# AllowedMethods: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym
Style/TrivialAccessors:
Exclude:
- 'lib/valid_email2/address.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
Exclude:
- 'spec/valid_email2_spec.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/ZeroLengthPredicate:
Exclude:
- 'lib/valid_email2/address.rb'

# Offense count: 17
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Max: 186
12 changes: 9 additions & 3 deletions lib/valid_email2/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,16 @@ def domain_is_in?(domain_list)
address_domain = address.domain.downcase
return true if domain_list.include?(address_domain)

i = address_domain.index('.')
return false unless i
tokens = address_domain.split('.')
return false if tokens.length < 3

domain_list.include?(address_domain[(i + 1)..-1])
# check only 6 elements deep
2.upto(6).each do |depth|
limited_sub_domain_part = tokens.reverse.first(depth).reverse.join('.')
return true if domain_list.include?(limited_sub_domain_part)
end

false
end

def mx_server_is_in?(domain_list)
Expand Down
47 changes: 46 additions & 1 deletion spec/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,52 @@

it "is valid if it contains special scandinavian characters" do
address = described_class.new("jørgen@email.dk")
expect(address.valid?).to eq true
expect(address.valid?).to be_truthy
end
end
end

describe "#disposable_domain?" do
context "when the disposable domain does not have subdomains" do
let(:disposable_domain) { ValidEmail2.disposable_emails.select { |domain| domain.count(".") == 1 }.sample }

it "is true if the domain is in the disposable_emails list" do
address = described_class.new("foo@#{disposable_domain}")
expect(address.disposable_domain?).to be_truthy
end

it "is true if the domain is a subdomain of a disposable domain" do
address = described_class.new("foo@sub.#{disposable_domain}")
expect(address.disposable_domain?).to be_truthy
end

it "is true if the domain is a deeply nested subdomain of a disposable domain" do
address = described_class.new("foo@sub3.sub2.sub1.#{disposable_domain}")
expect(address.disposable_domain?).to be_truthy
end

it "is false if the domain is not in the disposable_emails list" do
address = described_class.new("foo@example.com")
expect(address.disposable_domain?).to eq false
end
end

context "when the disposable domain has subdomains" do
let(:disposable_domain) { ValidEmail2.disposable_emails.select { |domain| domain.count(".") > 1 }.sample }

it "is true if the domain is in the disposable_emails list" do
address = described_class.new("foo@#{disposable_domain}")
expect(address.disposable_domain?).to be_truthy
end

it "is true if the domain is a subdomain of a disposable domain" do
address = described_class.new("foo@sub.#{disposable_domain}")
expect(address.disposable_domain?).to be_truthy
end

it "is true if the domain is a deeply nested subdomain of a disposable domain" do
address = described_class.new("foo@sub3.sub2.sub1.#{disposable_domain}")
expect(address.disposable_domain?).to be_truthy
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions valid_email2.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "valid_email2/version"

Expand All @@ -8,8 +7,8 @@ Gem::Specification.new do |spec|
spec.version = ValidEmail2::VERSION
spec.authors = ["Micke Lisinge"]
spec.email = ["hi@micke.me"]
spec.description = %q{ActiveModel validation for email. Including MX lookup and disposable email deny list}
spec.summary = %q{ActiveModel validation for email. Including MX lookup and disposable email deny list}
spec.description = 'ActiveModel validation for email. Including MX lookup and disposable email deny list'
spec.summary = 'ActiveModel validation for email. Including MX lookup and disposable email deny list'
spec.homepage = "https://github.com/micke/valid_email2"
spec.license = "MIT"

Expand All @@ -27,6 +26,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec-benchmark", "~> 0.6"
spec.add_development_dependency "net-smtp"
spec.add_development_dependency "debug"
spec.add_development_dependency "rubocop"
spec.add_runtime_dependency "mail", "~> 2.5"
spec.add_runtime_dependency "activemodel", ">= 6.0"
end