-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Implement auditor feature, #18
- Loading branch information
Showing
19 changed files
with
335 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
truemail (0.1.6) | ||
truemail (0.1.7) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
[![Maintainability](https://api.codeclimate.com/v1/badges/657aa241399927dcd2e2/maintainability)](https://codeclimate.com/github/rubygarage/truemail/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/657aa241399927dcd2e2/test_coverage)](https://codeclimate.com/github/rubygarage/truemail/test_coverage) [![Gem Version](https://badge.fury.io/rb/truemail.svg)](https://badge.fury.io/rb/truemail) [![CircleCI](https://circleci.com/gh/rubygarage/truemail/tree/master.svg?style=svg)](https://circleci.com/gh/rubygarage/truemail/tree/master) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md) | ||
|
||
The Truemail gem helps you validate emails by regex pattern, presence of domain mx-records, and real existence of email account on a current email server. | ||
The Truemail gem helps you validate emails by regex pattern, presence of domain mx-records, and real existence of email account on a current email server. Also Truemail gem allows performing an audit of the host in which runs. | ||
|
||
## Features | ||
|
||
|
@@ -137,7 +137,7 @@ Truemail.configuration | |
|
||
#### Regex validation | ||
|
||
Validation with regex pattern is the first validation level. By default this validation not performs strictly following RFC 5322 standart, so you can override Truemail default regex pattern if you want. | ||
Validation with regex pattern is the first validation level. By default this validation not performs strictly following RFC 5322 standard, so you can override Truemail default regex pattern if you want. | ||
|
||
Example of usage: | ||
|
||
|
@@ -383,6 +383,30 @@ Truemail.validate('[email protected]') | |
@validation_type=:smtp> | ||
``` | ||
|
||
### Host audit features | ||
|
||
Truemail gem allows performing an audit of the host in which runs. Only PTR record audit performs for today. | ||
|
||
#### PTR audit | ||
|
||
So what is a PTR record? A PTR record, or pointer record, enables someone to perform a reverse DNS lookup. This allows them to determine your domain name based on your IP address. Because generic domain names without a PTR are often associated with spammers, incoming mail servers identify email from hosts without PTR records as spam and you can't verify yours emails qualitatively. | ||
|
||
```ruby | ||
Truemail.host_audit | ||
# Everything is good | ||
=> #<Truemail::Auditor:0x00005580df358828 | ||
@result= | ||
#<struct Truemail::Auditor::Result | ||
warnings={}>> | ||
|
||
# Has PTR warning | ||
=> #<Truemail::Auditor:0x00005580df358828 | ||
@result= | ||
#<struct Truemail::Auditor::Result | ||
warnings= | ||
{:ptr=>"ptr record does not reference to current verifier domain"}>> | ||
``` | ||
|
||
### Truemail helpers | ||
|
||
#### .valid? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
module Audit | ||
class Base < Truemail::Worker | ||
private | ||
|
||
def add_warning(message) | ||
result.warnings[self.class.name.split('::').last.downcase.to_sym] = message | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
module Audit | ||
class Ptr < Truemail::Audit::Base | ||
require 'ipaddr' | ||
require 'resolv' | ||
|
||
NOT_FOUND = 'ptr record for current host address was not found' | ||
NOT_REFERENCES = 'ptr record does not reference to current verifier domain' | ||
|
||
def run | ||
return if ptr_records.empty? && add_warning(Truemail::Audit::Ptr::NOT_FOUND) | ||
return if ptr_references_to_verifier_domain? | ||
add_warning(Truemail::Audit::Ptr::NOT_REFERENCES) | ||
end | ||
|
||
private | ||
|
||
def current_host_address | ||
Resolv.getaddress(Socket.gethostname) | ||
end | ||
|
||
def current_host_reverse_lookup | ||
IPAddr.new(current_host_address).reverse | ||
end | ||
|
||
def ptr_records | ||
@ptr_records ||= Truemail::Wrapper.call do | ||
Resolv::DNS.new.getresources( | ||
current_host_reverse_lookup, Resolv::DNS::Resource::IN::PTR | ||
).map { |ptr_record| ptr_record.name.to_s } | ||
end || [] | ||
end | ||
|
||
def ptr_references_to_verifier_domain? | ||
ptr_records.include?(Truemail.configuration.verifier_domain) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
class Auditor | ||
Result = Struct.new(:warnings, keyword_init: true) do | ||
def initialize(warnings: {}, **args) | ||
super | ||
end | ||
end | ||
|
||
def self.run | ||
new.run | ||
end | ||
|
||
def result | ||
@result ||= Truemail::Auditor::Result.new | ||
end | ||
|
||
def run | ||
Truemail::Audit::Ptr.check(result) | ||
self | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
VERSION = '0.1.6' | ||
VERSION = '0.1.7' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
class Worker | ||
attr_reader :result | ||
|
||
def self.check(result) | ||
new(result).run | ||
end | ||
|
||
def initialize(result) | ||
@result = result | ||
end | ||
|
||
private | ||
|
||
def success(condition) | ||
result.success = condition || false | ||
end | ||
end | ||
end |
Oops, something went wrong.