class MailWhitelist
Filter mails with a specific whitelist of e-mailaddresses and only leaves those in the 'to'.
Constants
- VERSION
Attributes
fallback[R]
whitelist[R]
Public Class Methods
new(whitelist, fallback = nil)
click to toggle source
@param [Array<String>, include?] whitelist @param [String] fallback
# File lib/mail_whitelist.rb, line 10 def initialize(whitelist, fallback = nil) @whitelist = whitelist @fallback = fallback end
Public Instance Methods
delivering_email(mail)
click to toggle source
# File lib/mail_whitelist.rb, line 15 def delivering_email(mail) mail.to = mail.to.select { |recipient| whitelisted?(recipient) } mail.to = [fallback] unless mail.to.any? end
Private Instance Methods
whitelisted?(recipient)
click to toggle source
# File lib/mail_whitelist.rb, line 22 def whitelisted?(recipient) whitelist.any? do |whitelisted_address| if whitelisted_address.start_with?('@') recipient.end_with?(whitelisted_address) else whitelisted_address == recipient end end end