Sha256: cd4d7b4c4775ac43108a1798c6d064f594ab54646cd90d6f0361bc7d23a77ed6
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
require 'mailsafe/receipient_whitelist' module Mailsafe class ReceipientWhitelist def self.filter_receipient_domain(message) allowed_domain = Mailsafe.allowed_domain if allowed_domain.present? receipients = [] message.to.each do |receipient| if email_has_domain?(receipient, allowed_domain) receipients << receipient end end message.to = receipients end end def self.email_has_domain?(email, allowed_domain_config) allowed_domains = allowed_domain_config.split(',').map(&:strip).map(&:downcase) email_domain = email.split("@")[1] if email_domain.present? allowed_domains.include? email_domain.downcase else false end end end end # Unfortunately, monkeypatching Mail is the only way I found to actually prevent sending an email require 'mail' class Mail::Message def deliver_with_recipient_filter Mailsafe::ReceipientWhitelist.filter_receipient_domain(self) self.deliver_without_recipient_filter unless self.to.blank? || self.to.empty? end alias_method_chain :deliver, :recipient_filter end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mailsafe-0.1.0 | lib/mailsafe/receipient_whitelist.rb |