~cytrogen/masto-fe

ref: 86c9c5afa045b9e2cfa41c15db63ad97d58954c1 masto-fe/app/helpers/email_helper.rb -rw-r--r-- 396 bytes
86c9c5af — Claire Merge commit '40ba6e119b7457161fd43b449875d0fb9d473c1a' into glitch-soc/merge-upstream 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

module EmailHelper
  def self.included(base)
    base.extend(self)
  end

  def email_to_canonical_email(str)
    username, domain = str.downcase.split('@', 2)
    username, = username.delete('.').split('+', 2)

    "#{username}@#{domain}"
  end

  def email_to_canonical_email_hash(str)
    Digest::SHA2.new(256).hexdigest(email_to_canonical_email(str))
  end
end