email_helper.rb 398 B

123456789101112131415161718
  1. # frozen_string_literal: true
  2. module EmailHelper
  3. def self.included(base)
  4. base.extend(self)
  5. end
  6. def email_to_canonical_email(str)
  7. username, domain = str.downcase.split('@', 2)
  8. username, = username.gsub('.', '').split('+', 2)
  9. "#{username}@#{domain}"
  10. end
  11. def email_to_canonical_email_hash(str)
  12. Digest::SHA2.new(256).hexdigest(email_to_canonical_email(str))
  13. end
  14. end