mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 18:22:40 +08:00
better consistency around email case sensitivity
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
require 'mail'
|
||||
|
||||
module Email
|
||||
|
||||
def self.is_valid?(email)
|
||||
|
||||
parser = Mail::RFC2822Parser.new
|
||||
parser.root = :addr_spec
|
||||
result = parser.parse(email)
|
||||
@ -12,4 +12,9 @@ module Email
|
||||
result && result.respond_to?(:domain) && result.domain.dot_atom_text.elements.size > 1
|
||||
end
|
||||
|
||||
def self.downcase(email)
|
||||
return email unless Email.is_valid?(email)
|
||||
email.gsub(/^(.+@{1})([^@]+)$/) { $1 + $2.downcase }
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user