summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-01-18 15:16:31 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-01-18 15:16:31 +0000
commit1d783106a34bb9216762d5bc50d9d9583fbc08bf (patch)
tree686cf16b9e9f4de181e650a1efe111c0c5005bde /app
parenta4882467cbab94d444a6eb5030c68fc0f5097f05 (diff)
downloadredmine-1d783106a34bb9216762d5bc50d9d9583fbc08bf.tar.gz
redmine-1d783106a34bb9216762d5bc50d9d9583fbc08bf.zip
Adds Message-Id and References headers to email notifications so that issues and messages threads can be displayed by email clients (#1401).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2281 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/mailer.rb46
1 files changed, 45 insertions, 1 deletions
diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index beef97a7b..0fd708879 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -27,6 +27,7 @@ class Mailer < ActionMailer::Base
'Issue-Id' => issue.id,
'Issue-Author' => issue.author.login
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
+ message_id issue
recipients issue.recipients
cc(issue.watcher_recipients - @recipients)
subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
@@ -40,6 +41,8 @@ class Mailer < ActionMailer::Base
'Issue-Id' => issue.id,
'Issue-Author' => issue.author.login
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
+ message_id journal
+ references issue
@author = journal.user
recipients issue.recipients
# Watchers in cc
@@ -95,6 +98,7 @@ class Mailer < ActionMailer::Base
def news_added(news)
redmine_headers 'Project' => news.project.identifier
+ message_id news
recipients news.project.recipients
subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
body :news => news,
@@ -104,6 +108,8 @@ class Mailer < ActionMailer::Base
def message_posted(message, recipients)
redmine_headers 'Project' => message.project.identifier,
'Topic-Id' => (message.parent_id || message.id)
+ message_id message
+ references message.parent unless message.parent.nil?
recipients(recipients)
subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
body :message => message,
@@ -156,7 +162,15 @@ class Mailer < ActionMailer::Base
return false if (recipients.nil? || recipients.empty?) &&
(cc.nil? || cc.empty?) &&
(bcc.nil? || bcc.empty?)
- super
+
+ # Set Message-Id and References
+ if @message_id_object
+ mail.message_id = self.class.message_id_for(@message_id_object)
+ end
+ if @references_objects
+ mail.references = @references_objects.collect {|o| self.class.message_id_for(o)}
+ end
+ super(mail)
end
# Sends reminders to issue assignees
@@ -250,4 +264,34 @@ class Mailer < ActionMailer::Base
def self.controller_path
''
end unless respond_to?('controller_path')
+
+ # Returns a predictable Message-Id for the given object
+ def self.message_id_for(object)
+ # id + timestamp should reduce the odds of a collision
+ # as far as we don't send multiple emails for the same object
+ hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{object.created_on.strftime("%Y%m%d%H%M%S")}"
+ host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
+ host = "#{::Socket.gethostname}.redmine" if host.empty?
+ "<#{hash}@#{host}>"
+ end
+
+ private
+
+ def message_id(object)
+ @message_id_object = object
+ end
+
+ def references(object)
+ @references_objects ||= []
+ @references_objects << object
+ end
+end
+
+# Patch TMail so that message_id is not overwritten
+module TMail
+ class Mail
+ def add_message_id( fqdn = nil )
+ self.message_id ||= ::TMail::new_message_id(fqdn)
+ end
+ end
end