-
-
Save ihower/145f96a0f2f0e56653cc506f13c863c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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