summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Jankovski <maxlazio@gmail.com>2014-10-27 13:05:50 +0100
committerMarin Jankovski <maxlazio@gmail.com>2014-10-27 13:05:50 +0100
commitd78e80fa74777e886ca131614f3b4d3f06bf9fff (patch)
tree66245e6df98ca99f2357d57cf05cd57b5c32b9d6
parentd504ca8a0c696b31eaf383f97f47e08afac23084 (diff)
downloadgitlab-ce-d78e80fa74777e886ca131614f3b4d3f06bf9fff.tar.gz
Add email interceptor to prevent mail sending if email sending is disabled.
-rw-r--r--config/initializers/disable_email_interceptor.rb2
-rw-r--r--lib/disable_email_interceptor.rb8
2 files changed, 10 insertions, 0 deletions
diff --git a/config/initializers/disable_email_interceptor.rb b/config/initializers/disable_email_interceptor.rb
new file mode 100644
index 00000000000..c76a6b8b19f
--- /dev/null
+++ b/config/initializers/disable_email_interceptor.rb
@@ -0,0 +1,2 @@
+# Interceptor in lib/disable_email_interceptor.rb
+ActionMailer::Base.register_interceptor(DisableEmailInterceptor) unless Gitlab.config.gitlab.email_enabled
diff --git a/lib/disable_email_interceptor.rb b/lib/disable_email_interceptor.rb
new file mode 100644
index 00000000000..1b80be112a4
--- /dev/null
+++ b/lib/disable_email_interceptor.rb
@@ -0,0 +1,8 @@
+# Read about interceptors in http://guides.rubyonrails.org/action_mailer_basics.html#intercepting-emails
+class DisableEmailInterceptor
+
+ def self.delivering_email(message)
+ message.perform_deliveries = false
+ Rails.logger.info "Emails disabled! Interceptor prevented sending mail #{message.subject}"
+ end
+end