1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00
mastodon/app/models/concerns/canonical_email.rb

25 lines
469 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module CanonicalEmail
extend ActiveSupport::Concern
class_methods do
def email_to_canonical_email_hash(str)
Digest::SHA2
.new(256)
.hexdigest(
email_to_canonical_email(str)
)
end
2024-07-29 13:44:20 -07:00
private
def email_to_canonical_email(str)
username, domain = str.downcase.split('@', 2)
username, = username.delete('.').split('+', 2)
"#{username}@#{domain}"
end
end
end