Upgrade mail gem to remove dependency on mime-types.

* Use a EmailValidator.email_regexp for `Email.is_valid?`
  check as we're seeing an increase in allocation when
  parsing email addresses wih `Mail::Address`.
This commit is contained in:
Guo Xiang Tan
2018-03-14 14:36:23 +08:00
parent 51657d3426
commit 58b8ea4f41
3 changed files with 3 additions and 17 deletions

View File

@ -8,16 +8,7 @@ module Email
def self.is_valid?(email)
return false unless String === email
parsed = Mail::Address.new(email)
# Don't allow for a TLD by itself list (sam@localhost)
# The Grammar is: (local_part "@" domain) / local_part ... need to discard latter
parsed.address == email &&
parsed.local != parsed.address &&
parsed&.domain.split(".").size > 1
rescue Mail::Field::ParseError
false
!!(EmailValidator.email_regex =~ email)
end
def self.downcase(email)