You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mastodon/app/models/concerns/canonical_email.rb

28 lines
523 B
Ruby

# frozen_string_literal: true
module CanonicalEmail
extend ActiveSupport::Concern
included do
normalizes :email, with: ->(value) { canonicalize_email(value) }
end
class_methods do
def canonicalize_email(email)
email
.downcase
.split('@', 2)
.then { |local, domain| [canonical_username(local), domain] }
.join('@')
end
def canonical_username(username)
username
.to_s
.delete('.')
.split('+', 2)
.first
end
end
end