summaryrefslogtreecommitdiff
path: root/app/mailers/notify.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/mailers/notify.rb')
-rw-r--r--app/mailers/notify.rb73
1 files changed, 33 insertions, 40 deletions
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb
index 79fb48b00d3..5717c89e61d 100644
--- a/app/mailers/notify.rb
+++ b/app/mailers/notify.rb
@@ -1,4 +1,4 @@
-class Notify < ActionMailer::Base
+class Notify < BaseMailer
include ActionDispatch::Routing::PolymorphicRoutes
include Emails::Issues
@@ -8,22 +8,9 @@ class Notify < ActionMailer::Base
include Emails::Profile
include Emails::Groups
- add_template_helper ApplicationHelper
- add_template_helper GitlabMarkdownHelper
add_template_helper MergeRequestsHelper
add_template_helper EmailsHelper
- attr_accessor :current_user
- helper_method :current_user, :can?
-
- default from: Proc.new { default_sender_address.format }
- default reply_to: Gitlab.config.gitlab.email_reply_to
-
- # Just send email with 2 seconds delay
- def self.delay
- delay_for(2.seconds)
- end
-
def test_email(recipient_email, subject, body)
mail(to: recipient_email,
subject: subject,
@@ -48,13 +35,6 @@ class Notify < ActionMailer::Base
private
- # The default email address to send emails from
- def default_sender_address
- address = Mail::Address.new(Gitlab.config.gitlab.email_from)
- address.display_name = Gitlab.config.gitlab.email_display_name
- address
- end
-
def can_send_from_user_email?(sender)
sender_domain = sender.email.split("@").last
self.class.allowed_email_domains.include?(sender_domain)
@@ -85,14 +65,6 @@ class Notify < ActionMailer::Base
@current_user.notification_email
end
- # Set the References header field
- #
- # local_part - The local part of the referenced message ID
- #
- def set_reference(local_part)
- headers["References"] = "<#{local_part}@#{Gitlab.config.gitlab.host}>"
- end
-
# Formats arguments into a String suitable for use as an email subject
#
# extra - Extra Strings to be inserted into the subject
@@ -126,14 +98,37 @@ class Notify < ActionMailer::Base
"<#{model_name}_#{model.id}@#{Gitlab.config.gitlab.host}>"
end
+ def mail_thread(model, headers = {})
+ if @project
+ headers['X-GitLab-Project'] = @project.name
+ headers['X-GitLab-Project-Id'] = @project.id
+ headers['X-GitLab-Project-Path'] = @project.path_with_namespace
+ end
+
+ headers["X-GitLab-#{model.class.name}-ID"] = model.id
+
+ if reply_key
+ headers['X-GitLab-Reply-Key'] = reply_key
+
+ address = Mail::Address.new(Gitlab::ReplyByEmail.reply_address(reply_key))
+ address.display_name = @project.name_with_namespace
+
+ headers['Reply-To'] = address
+
+ @reply_by_email = true
+ end
+
+ mail(headers)
+ end
+
# Send an email that starts a new conversation thread,
# with headers suitable for grouping by thread in email clients.
#
# See: mail_answer_thread
- def mail_new_thread(model, headers = {}, &block)
+ def mail_new_thread(model, headers = {})
headers['Message-ID'] = message_id(model)
- headers['X-GitLab-Project'] = "#{@project.name} | " if @project
- mail(headers, &block)
+
+ mail_thread(model, headers)
end
# Send an email that responds to an existing conversation thread,
@@ -144,19 +139,17 @@ class Notify < ActionMailer::Base
# * have a subject that begin by 'Re: '
# * have a 'In-Reply-To' or 'References' header that references the original 'Message-ID'
#
- def mail_answer_thread(model, headers = {}, &block)
+ def mail_answer_thread(model, headers = {})
+ headers['Message-ID'] = SecureRandom.hex
headers['In-Reply-To'] = message_id(model)
headers['References'] = message_id(model)
- headers['X-GitLab-Project'] = "#{@project.name} | " if @project
- if headers[:subject]
- headers[:subject].prepend('Re: ')
- end
+ headers[:subject].prepend('Re: ') if headers[:subject]
- mail(headers, &block)
+ mail_thread(model, headers)
end
- def can?
- Ability.abilities.allowed?(user, action, subject)
+ def reply_key
+ @reply_key ||= Gitlab::ReplyByEmail.reply_key
end
end