Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre de La Morinerie <pierre@capitainetrain.com>2014-02-24 15:12:29 +0400
committerPierre de La Morinerie <pierre@capitainetrain.com>2014-06-10 19:09:15 +0400
commitde90b572d8f22708ea76ffbea9c513143fdeea2e (patch)
treea2613e9f30ec0e5516d489b02652c64459d11323 /app/mailers/notify.rb
parent466b768bb34730ee6a24d950333c232009c34bbd (diff)
Allow more mail clients to group emails by thread
* send a ‘In-Reply-To’ header along the ‘References’ header * subject of answers to an existing thread begins with ‘Re: ’ This fixes threading with at least Mail.app and Airmail.
Diffstat (limited to 'app/mailers/notify.rb')
-rw-r--r--app/mailers/notify.rb52
1 files changed, 44 insertions, 8 deletions
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb
index 8eea8cf25e0..d65bead9cfe 100644
--- a/app/mailers/notify.rb
+++ b/app/mailers/notify.rb
@@ -67,14 +67,6 @@ class Notify < ActionMailer::Base
end
end
- # Set the Message-ID header field
- #
- # local_part - The local part of the message ID
- #
- def set_message_id(local_part)
- headers["Message-ID"] = "<#{local_part}@#{Gitlab.config.gitlab.host}>"
- end
-
# Set the References header field
#
# local_part - The local part of the referenced message ID
@@ -107,4 +99,48 @@ class Notify < ActionMailer::Base
subject << extra.join(' | ') if extra.present?
subject
end
+
+ # Return a string suitable for inclusion in the 'Message-Id' mail header.
+ #
+ # The message-id is generated from the unique URL to a model object.
+ def message_id(model)
+ model_name = model.class.model_name.singular_route_key
+ "<#{model_name}_#{model.id}@#{Gitlab.config.gitlab.host}>"
+ 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)
+ raise ArgumentError, '"To:" header will be overwritten; use "Cc:" or "Bcc:"' unless headers[:to].nil?
+ headers[:to] = project_sender_address.format
+
+ headers['Message-ID'] = message_id(model)
+
+ mail(headers, &block)
+ end
+
+ # Send an email that responds to an existing conversation thread,
+ # with headers suitable for grouping by thread in email clients.
+ #
+ # For grouping emails by thread, email clients heuristics require the answers to:
+ #
+ # * have a subject that begin by 'Re: '
+ # * have a 'In-Reply-To' or 'References' header that references the original 'Message-ID'
+ # * have stable 'From' and 'To' headers between messages of the same thread
+ #
+ def mail_answer_thread(model, headers = {}, &block)
+ raise ArgumentError, '"To:" header will be overwritten; use "Cc:" or "Bcc:"' unless headers[:to].nil?
+ headers[:to] = project_sender_address.format
+
+ headers['In-Reply-To'] = message_id(model)
+ headers['References'] = message_id(model)
+
+ if (headers[:subject])
+ headers[:subject].prepend('Re: ')
+ end
+
+ mail(headers, &block)
+ end
end