truemail-rb / truemail

🚀 Configurable framework agnostic plain Ruby 📨 email validator/verifier. Verify email via Regex, DNS, SMTP and even more. Be sure that email address valid and exists.

Home Page:https://truemail-rb.org/truemail-gem

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[QUESTION] Suggestion allow to validate recipients with names

vizcay opened this issue · comments

Hey! First of all thanks for truemail, I'm looking forward to implement it with a few of our apps.

I was wondering, why Name <email> format is not supported out of the box?

Thanks!

Hola, Pablo! 😃 Current Truemail implementation is about validation/verification of addr-spec specifed in RFC 5322, sec. 3.4.1. While you suggest to validate angle-addr, described in RFC 5322, sec. 3.4. Also it's not a library's responsobility to validate recipient's name. However, thanks for your suggestion! 🍺

P.S.: is it a valid implementation example of your idea?

require 'truemail'

module AngleAddrValidator
  ANGLE_ADDR_PATTERN = /(.+) <(.+)>/.freeze

  def self.valid?(angle_addr)
    ANGLE_ADDR_PATTERN.match?(angle_addr) && Truemail.valid?(angle_addr[ANGLE_ADDR_PATTERN, 2])
  end
end

AngleAddrValidator.valid?('Name <existing_email@domain.com>')
=> true

AngleAddrValidator.valid?('<exising_email@domain.com>')
=> false

AngleAddrValidator.valid?('Name <not_existing_email@domain.com>')
=> false