Class: Deliverable::Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/deliverable/verifier.rb

Constant Summary collapse

PROBLEMATIC_SERVER_PATTERNS =
[
  /migadu\.com$/,
  /gmail\.com$/,
  /google\.com$/,
  /googlemail\.com$/,
  /outlook\.com$/,
  /office365\.com$/,
  /protection\.outlook\.com$/,
  /proofpoint\.com$/,
  /mimecast\.com$/
].freeze
SMTP_PORTS =
[25, 587, 465].freeze
COMMON_DOMAINS =
%w[
  gmail.com yahoo.com hotmail.com outlook.com
  aol.com icloud.com live.com msn.com
  proton.me protonmail.com fastmail.com
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(email, smtp: true, timeout: 10, sender_email: nil, sender_domain: nil, logger: nil) ⇒ Verifier

Returns a new instance of Verifier.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/deliverable/verifier.rb', line 28

def initialize(email, smtp: true, timeout: 10, sender_email: nil, sender_domain: nil, logger: nil)
  @email = email&.strip&.downcase
  @smtp = smtp
  @timeout = timeout
  @sender_email = sender_email || Deliverable.config.sender_email
  @sender_domain = sender_domain || Deliverable.config.sender_domain
  @logger = logger || Deliverable.config.logger
  @errors = []
  @warnings = []
  @details = {
    syntax_valid: false,
    mx_verified: false,
    smtp_verified: false,
    smtp_failed_assumption: false,
    dns_failed_assumption: false,
    has_warnings: false,
    accepts_any_email: false
  }
  @accepts_any_email = nil
end

Instance Method Details

#callObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/deliverable/verifier.rb', line 49

def call
  ok = run_checks
  score = calculate_score
  Result.new(
    email: @email,
    score: score,
    score_details: @details.dup,
    classification: classification(ok),
    errors: @errors,
    warnings: @warnings,
    checks: {
      syntax: @details[:syntax_valid],
      mx_record: @details[:mx_verified],
      smtp_deliverable: @smtp ? @smtp_result : nil,
      disposable: disposable?,
      typo_suggestion: typo_suggestion,
      accepts_any_email: @accepts_any_email
    }
  )
end