Module: ActionRecipient::Rewriter

Defined in:
lib/action_recipient/rewriter.rb

Class Method Summary collapse

Class Method Details

.domain_for(email) ⇒ Object



45
46
47
# File 'lib/action_recipient/rewriter.rb', line 45

def domain_for(email)
  email.split('@').last
end

.formatObject



41
42
43
# File 'lib/action_recipient/rewriter.rb', line 41

def format
  ActionRecipient.config.format
end

.match_with_any_whitelisted_addresses?(email) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/action_recipient/rewriter.rb', line 25

def match_with_any_whitelisted_addresses?(email)
  whitelist.addresses.any? { |string_or_regexp|
    string_or_regexp === email
  }
end

.match_with_any_whitelisted_domains?(domain) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/action_recipient/rewriter.rb', line 31

def match_with_any_whitelisted_domains?(domain)
  whitelist.domains.any? { |string_or_regexp|
    string_or_regexp === domain
  }
end

.rewrite(email, prefix, format) ⇒ Object



17
18
19
# File 'lib/action_recipient/rewriter.rb', line 17

def rewrite(email, prefix, format)
  format % "#{prefix}#{email.gsub('@', '_at_').gsub(/[^\.\w]/, '-')}"
end

.rewrite_addresses!(message, type, prefix: '') ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/action_recipient/rewriter.rb', line 4

def rewrite_addresses!(message, type, prefix: '')
  address_container = message[type]&.field&.addrs
  return unless address_container

  message[type] = address_container.map { |address_object|
    if whitelisted?(address_object.address)
      address_object.to_s
    else
      rewrite(address_object.address, prefix, format)
    end
  }
end

.whitelistObject



37
38
39
# File 'lib/action_recipient/rewriter.rb', line 37

def whitelist
  ActionRecipient.config.whitelist
end

.whitelisted?(email) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/action_recipient/rewriter.rb', line 21

def whitelisted?(email)
  match_with_any_whitelisted_addresses?(email) || match_with_any_whitelisted_domains?(domain_for(email))
end