diff options
author | Pierre de La Morinerie <pierre@capitainetrain.com> | 2014-02-24 15:12:29 +0400 |
---|---|---|
committer | Pierre de La Morinerie <pierre@capitainetrain.com> | 2014-07-03 18:58:42 +0400 |
commit | 6dafbf24124a098f65864cdecd91bcb5e50c2540 (patch) | |
tree | 74d137cc6eba609a8d1153ba99832f8dcb3dbdbb /app/mailers/notify.rb | |
parent | e46ec91a942fc0773279999debe661f493999500 (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: '
Diffstat (limited to 'app/mailers/notify.rb')
-rw-r--r-- | app/mailers/notify.rb | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 84a0da0129d..bd438bab89a 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -1,4 +1,6 @@ class Notify < ActionMailer::Base + include ActionDispatch::Routing::PolymorphicRoutes + include Emails::Issues include Emails::MergeRequests include Emails::Notes @@ -53,14 +55,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 @@ -93,4 +87,40 @@ 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) + 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' + # + def mail_answer_thread(model, headers = {}, &block) + 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 |