Skip to content

Instantly share code, notes, and snippets.

@ihower
Created December 18, 2016 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihower/145f96a0f2f0e56653cc506f13c863c5 to your computer and use it in GitHub Desktop.
Save ihower/145f96a0f2f0e56653cc506f13c863c5 to your computer and use it in GitHub Desktop.
class EmailInterceptor
# For overwrite the deliver mail
def self.delivering_email(message)
original_to_emails = Array(message.to).join("+")
original_cc_emails = Array(message.cc).join("+")
original_bcc_emails = Array(message.bcc).join("+")
message.to = Array(message.to).select{ |x| x =~ /alphacamp/ }
message.cc = Array(message.cc).select{ |x| x =~ /alphacamp/ }
message.bcc = Array(message.bcc).select{ |x| x =~ /alphacamp/ }
new_to_emails = message.to.join("+")
new_cc_emails = message.cc.join("+")
new_bcc_emails = message.bcc.join("+")
if (new_to_emails != original_to_emails) || (new_cc_emails != original_cc_emails) || (new_bcc_emails != original_bcc_emails)
s = "[Dojo #{Rails.env.to_s.titleize} Interceptor][original to: #{original_to_emails}"
s << ", cc: #{original_cc_emails}" if original_cc_emails.present?
s << ", bcc: #{original_bcc_emails}" if original_bcc_emails.present?
s << "] #{message.subject}"
message.subject = s
end
Rails.logger.info("Dojo Email Interceptor: original_to_emails: #{original_to_emails},
original_cc_emails: #{original_cc_emails},
original_bcc_emails: #{original_bcc_emails},
new_to_emails: #{new_to_emails},
new_cc_emails: #{new_cc_emails},
new_bcc_emails: #{new_bcc_emails}")
message.to = ["engineering+dojotest@alphacamp.co"] if message.to.blank?
message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment