Module: IsEmail

Extended by:
IsEmail
Included in:
IsEmail
Defined in:
lib/is_email.rb,
lib/is_email/version.rb,
lib/is_email/diagnosis.rb,
lib/is_email/reference.rb,
lib/is_email/validators.rb,
lib/is_email/diagnosis/base.rb,
lib/is_email/diagnosis/cfws.rb,
lib/is_email/diagnosis/valid.rb,
lib/is_email/validators/base.rb,
lib/is_email/diagnosis/invalid.rb,
lib/is_email/diagnosis/rfc5321.rb,
lib/is_email/diagnosis/rfc5322.rb,
lib/is_email/validators/parser.rb,
lib/is_email/diagnosis/deprecated.rb

Overview

Gives an easy-to-use interface for checking the validity of email addresses

Email is one of the primary ways we interact with others on the internet. Unfortunately, it is also one of the primary ways we abuse others on the internet. Because of this, we (1) ask for email addresses too often in transactional relationships, (2) often give incorrect email addresses, and (3) want to make use of email functionality to sort emails coming into our inboxes.

You could say it’s a fraught relationship.

By doing one job, and doing it well, IsEmail can reduce the frustration of others whom we ask for their email address. No more will we be unable to use plus addressing to filter newsletters and track who sells our information. No more must we use conventional-looking email addresses to appease those who would fill our inboxes with messaging.

IsEmail exists to give you an easy way to validate an email address that you receive to check it for typos or formats in violation of the various email specifications, namely:

  1. [RFC1123], Requirements for Internet Hosts – Application and Support

  2. [RFC3696], Application Techniques for Checking and Transformation of Names

  3. [RFC4291], IP Version 6 Addressing Architecture

  4. [RFC5321], Simple Mail Transfer Protocol

  5. [RFC5322], Internet Message Format

[1]: datatracker.ietf.org/doc/html/rfc1123 [2]: datatracker.ietf.org/doc/html/rfc3696 [3]: datatracker.ietf.org/doc/html/rfc4291 [4]: datatracker.ietf.org/doc/html/rfc5321 [5]: datatracker.ietf.org/doc/html/rfc5322

Defined Under Namespace

Modules: Diagnosis, Validators Classes: Reference

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Instance Method Details

#email?(address, diagnose: false) ⇒ Boolean, Diagnosis

Validate an email address

Examples:

Checking whether an email is valid

IsEmail.email?("[email protected]")

Investigating why an email address is invalid

IsEmail.email?("test(comment)[email protected]", diagnose: true)

Parameters:

  • address (String)

    the email address to check

  • diagnose (Boolean) (defaults to: false)

    whether to return a diagnosis for invalidity

Returns:

  • (Boolean, Diagnosis)

    when not diagnosing, true when the address is valid and false otherwise; when diagnosing, the diagnosis for the status of the address



56
57
58
59
60
61
# File 'lib/is_email.rb', line 56

def email?(address, diagnose: false)
  threshold = Diagnosis::CATEGORIES["THRESHOLD"]
  diagnosis = Validators::Parser.new.email?(address, diagnose: true)

  diagnose ? diagnosis : diagnosis < threshold
end