annotate .svn/pristine/a5/a5766013768a71e99092a265b9e09c7b5e0e3333.svn-base @ 929:5f33065ddc4b redmine-1.3

Update to Redmine SVN rev 9414 on 1.3-stable branch
author Chris Cannam
date Wed, 27 Jun 2012 14:54:18 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require 'ar_condition'
Chris@909 19
Chris@909 20 class Mailer < ActionMailer::Base
Chris@909 21 layout 'mailer'
Chris@909 22 helper :application
Chris@909 23 helper :issues
Chris@909 24 helper :custom_fields
Chris@909 25
Chris@909 26 include ActionController::UrlWriter
Chris@909 27 include Redmine::I18n
Chris@909 28
Chris@909 29 def self.default_url_options
Chris@909 30 h = Setting.host_name
Chris@909 31 h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
Chris@909 32 { :host => h, :protocol => Setting.protocol }
Chris@909 33 end
Chris@909 34
Chris@909 35 # Builds a tmail object used to email recipients of the added issue.
Chris@909 36 #
Chris@909 37 # Example:
Chris@909 38 # issue_add(issue) => tmail object
Chris@909 39 # Mailer.deliver_issue_add(issue) => sends an email to issue recipients
Chris@909 40 def issue_add(issue)
Chris@909 41 redmine_headers 'Project' => issue.project.identifier,
Chris@909 42 'Issue-Id' => issue.id,
Chris@909 43 'Issue-Author' => issue.author.login
Chris@909 44 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
Chris@909 45 message_id issue
Chris@909 46 recipients issue.recipients
Chris@909 47 cc(issue.watcher_recipients - @recipients)
Chris@909 48 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
Chris@909 49 body :issue => issue,
Chris@909 50 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
Chris@909 51 render_multipart('issue_add', body)
Chris@909 52 end
Chris@909 53
Chris@909 54 # Builds a tmail object used to email recipients of the edited issue.
Chris@909 55 #
Chris@909 56 # Example:
Chris@909 57 # issue_edit(journal) => tmail object
Chris@909 58 # Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
Chris@909 59 def issue_edit(journal)
Chris@909 60 issue = journal.journalized.reload
Chris@909 61 redmine_headers 'Project' => issue.project.identifier,
Chris@909 62 'Issue-Id' => issue.id,
Chris@909 63 'Issue-Author' => issue.author.login
Chris@909 64 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
Chris@909 65 message_id journal
Chris@909 66 references issue
Chris@909 67 @author = journal.user
Chris@909 68 recipients issue.recipients
Chris@909 69 # Watchers in cc
Chris@909 70 cc(issue.watcher_recipients - @recipients)
Chris@909 71 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
Chris@909 72 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
Chris@909 73 s << issue.subject
Chris@909 74 subject s
Chris@909 75 body :issue => issue,
Chris@909 76 :journal => journal,
Chris@909 77 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
Chris@909 78
Chris@909 79 render_multipart('issue_edit', body)
Chris@909 80 end
Chris@909 81
Chris@909 82 def reminder(user, issues, days)
Chris@909 83 set_language_if_valid user.language
Chris@909 84 recipients user.mail
Chris@909 85 subject l(:mail_subject_reminder, :count => issues.size, :days => days)
Chris@909 86 body :issues => issues,
Chris@909 87 :days => days,
Chris@909 88 :issues_url => url_for(:controller => 'issues', :action => 'index',
Chris@909 89 :set_filter => 1, :assigned_to_id => user.id,
Chris@909 90 :sort => 'due_date:asc')
Chris@909 91 render_multipart('reminder', body)
Chris@909 92 end
Chris@909 93
Chris@909 94 # Builds a tmail object used to email users belonging to the added document's project.
Chris@909 95 #
Chris@909 96 # Example:
Chris@909 97 # document_added(document) => tmail object
Chris@909 98 # Mailer.deliver_document_added(document) => sends an email to the document's project recipients
Chris@909 99 def document_added(document)
Chris@909 100 redmine_headers 'Project' => document.project.identifier
Chris@909 101 recipients document.recipients
Chris@909 102 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
Chris@909 103 body :document => document,
Chris@909 104 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
Chris@909 105 render_multipart('document_added', body)
Chris@909 106 end
Chris@909 107
Chris@909 108 # Builds a tmail object used to email recipients of a project when an attachements are added.
Chris@909 109 #
Chris@909 110 # Example:
Chris@909 111 # attachments_added(attachments) => tmail object
Chris@909 112 # Mailer.deliver_attachments_added(attachments) => sends an email to the project's recipients
Chris@909 113 def attachments_added(attachments)
Chris@909 114 container = attachments.first.container
Chris@909 115 added_to = ''
Chris@909 116 added_to_url = ''
Chris@909 117 case container.class.name
Chris@909 118 when 'Project'
Chris@909 119 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container)
Chris@909 120 added_to = "#{l(:label_project)}: #{container}"
Chris@909 121 recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
Chris@909 122 when 'Version'
Chris@909 123 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project)
Chris@909 124 added_to = "#{l(:label_version)}: #{container.name}"
Chris@909 125 recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
Chris@909 126 when 'Document'
Chris@909 127 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
Chris@909 128 added_to = "#{l(:label_document)}: #{container.title}"
Chris@909 129 recipients container.recipients
Chris@909 130 end
Chris@909 131 redmine_headers 'Project' => container.project.identifier
Chris@909 132 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
Chris@909 133 body :attachments => attachments,
Chris@909 134 :added_to => added_to,
Chris@909 135 :added_to_url => added_to_url
Chris@909 136 render_multipart('attachments_added', body)
Chris@909 137 end
Chris@909 138
Chris@909 139 # Builds a tmail object used to email recipients of a news' project when a news item is added.
Chris@909 140 #
Chris@909 141 # Example:
Chris@909 142 # news_added(news) => tmail object
Chris@909 143 # Mailer.deliver_news_added(news) => sends an email to the news' project recipients
Chris@909 144 def news_added(news)
Chris@909 145 redmine_headers 'Project' => news.project.identifier
Chris@909 146 message_id news
Chris@909 147 recipients news.recipients
Chris@909 148 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
Chris@909 149 body :news => news,
Chris@909 150 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
Chris@909 151 render_multipart('news_added', body)
Chris@909 152 end
Chris@909 153
Chris@909 154 # Builds a tmail object used to email recipients of a news' project when a news comment is added.
Chris@909 155 #
Chris@909 156 # Example:
Chris@909 157 # news_comment_added(comment) => tmail object
Chris@909 158 # Mailer.news_comment_added(comment) => sends an email to the news' project recipients
Chris@909 159 def news_comment_added(comment)
Chris@909 160 news = comment.commented
Chris@909 161 redmine_headers 'Project' => news.project.identifier
Chris@909 162 message_id comment
Chris@909 163 recipients news.recipients
Chris@909 164 cc news.watcher_recipients
Chris@909 165 subject "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
Chris@909 166 body :news => news,
Chris@909 167 :comment => comment,
Chris@909 168 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
Chris@909 169 render_multipart('news_comment_added', body)
Chris@909 170 end
Chris@909 171
Chris@909 172 # Builds a tmail object used to email the recipients of the specified message that was posted.
Chris@909 173 #
Chris@909 174 # Example:
Chris@909 175 # message_posted(message) => tmail object
Chris@909 176 # Mailer.deliver_message_posted(message) => sends an email to the recipients
Chris@909 177 def message_posted(message)
Chris@909 178 redmine_headers 'Project' => message.project.identifier,
Chris@909 179 'Topic-Id' => (message.parent_id || message.id)
Chris@909 180 message_id message
Chris@909 181 references message.parent unless message.parent.nil?
Chris@909 182 recipients(message.recipients)
Chris@909 183 cc((message.root.watcher_recipients + message.board.watcher_recipients).uniq - @recipients)
Chris@909 184 subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
Chris@909 185 body :message => message,
Chris@909 186 :message_url => url_for(message.event_url)
Chris@909 187 render_multipart('message_posted', body)
Chris@909 188 end
Chris@909 189
Chris@909 190 # Builds a tmail object used to email the recipients of a project of the specified wiki content was added.
Chris@909 191 #
Chris@909 192 # Example:
Chris@909 193 # wiki_content_added(wiki_content) => tmail object
Chris@909 194 # Mailer.deliver_wiki_content_added(wiki_content) => sends an email to the project's recipients
Chris@909 195 def wiki_content_added(wiki_content)
Chris@909 196 redmine_headers 'Project' => wiki_content.project.identifier,
Chris@909 197 'Wiki-Page-Id' => wiki_content.page.id
Chris@909 198 message_id wiki_content
Chris@909 199 recipients wiki_content.recipients
Chris@909 200 cc(wiki_content.page.wiki.watcher_recipients - recipients)
Chris@909 201 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}"
Chris@909 202 body :wiki_content => wiki_content,
Chris@909 203 :wiki_content_url => url_for(:controller => 'wiki', :action => 'show',
Chris@909 204 :project_id => wiki_content.project,
Chris@909 205 :id => wiki_content.page.title)
Chris@909 206 render_multipart('wiki_content_added', body)
Chris@909 207 end
Chris@909 208
Chris@909 209 # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated.
Chris@909 210 #
Chris@909 211 # Example:
Chris@909 212 # wiki_content_updated(wiki_content) => tmail object
Chris@909 213 # Mailer.deliver_wiki_content_updated(wiki_content) => sends an email to the project's recipients
Chris@909 214 def wiki_content_updated(wiki_content)
Chris@909 215 redmine_headers 'Project' => wiki_content.project.identifier,
Chris@909 216 'Wiki-Page-Id' => wiki_content.page.id
Chris@909 217 message_id wiki_content
Chris@909 218 recipients wiki_content.recipients
Chris@909 219 cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients)
Chris@909 220 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}"
Chris@909 221 body :wiki_content => wiki_content,
Chris@909 222 :wiki_content_url => url_for(:controller => 'wiki', :action => 'show',
Chris@909 223 :project_id => wiki_content.project,
Chris@909 224 :id => wiki_content.page.title),
Chris@909 225 :wiki_diff_url => url_for(:controller => 'wiki', :action => 'diff',
Chris@909 226 :project_id => wiki_content.project, :id => wiki_content.page.title,
Chris@909 227 :version => wiki_content.version)
Chris@909 228 render_multipart('wiki_content_updated', body)
Chris@909 229 end
Chris@909 230
Chris@909 231 # Builds a tmail object used to email the specified user their account information.
Chris@909 232 #
Chris@909 233 # Example:
Chris@909 234 # account_information(user, password) => tmail object
Chris@909 235 # Mailer.deliver_account_information(user, password) => sends account information to the user
Chris@909 236 def account_information(user, password)
Chris@909 237 set_language_if_valid user.language
Chris@909 238 recipients user.mail
Chris@909 239 subject l(:mail_subject_register, Setting.app_title)
Chris@909 240 body :user => user,
Chris@909 241 :password => password,
Chris@909 242 :login_url => url_for(:controller => 'account', :action => 'login')
Chris@909 243 render_multipart('account_information', body)
Chris@909 244 end
Chris@909 245
Chris@909 246 # Builds a tmail object used to email all active administrators of an account activation request.
Chris@909 247 #
Chris@909 248 # Example:
Chris@909 249 # account_activation_request(user) => tmail object
Chris@909 250 # Mailer.deliver_account_activation_request(user)=> sends an email to all active administrators
Chris@909 251 def account_activation_request(user)
Chris@909 252 # Send the email to all active administrators
Chris@909 253 recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
Chris@909 254 subject l(:mail_subject_account_activation_request, Setting.app_title)
Chris@909 255 body :user => user,
Chris@909 256 :url => url_for(:controller => 'users', :action => 'index',
Chris@909 257 :status => User::STATUS_REGISTERED,
Chris@909 258 :sort_key => 'created_on', :sort_order => 'desc')
Chris@909 259 render_multipart('account_activation_request', body)
Chris@909 260 end
Chris@909 261
Chris@909 262 # Builds a tmail object used to email the specified user that their account was activated by an administrator.
Chris@909 263 #
Chris@909 264 # Example:
Chris@909 265 # account_activated(user) => tmail object
Chris@909 266 # Mailer.deliver_account_activated(user) => sends an email to the registered user
Chris@909 267 def account_activated(user)
Chris@909 268 set_language_if_valid user.language
Chris@909 269 recipients user.mail
Chris@909 270 subject l(:mail_subject_register, Setting.app_title)
Chris@909 271 body :user => user,
Chris@909 272 :login_url => url_for(:controller => 'account', :action => 'login')
Chris@909 273 render_multipart('account_activated', body)
Chris@909 274 end
Chris@909 275
Chris@909 276 def lost_password(token)
Chris@909 277 set_language_if_valid(token.user.language)
Chris@909 278 recipients token.user.mail
Chris@909 279 subject l(:mail_subject_lost_password, Setting.app_title)
Chris@909 280 body :token => token,
Chris@909 281 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
Chris@909 282 render_multipart('lost_password', body)
Chris@909 283 end
Chris@909 284
Chris@909 285 def register(token)
Chris@909 286 set_language_if_valid(token.user.language)
Chris@909 287 recipients token.user.mail
Chris@909 288 subject l(:mail_subject_register, Setting.app_title)
Chris@909 289 body :token => token,
Chris@909 290 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
Chris@909 291 render_multipart('register', body)
Chris@909 292 end
Chris@909 293
Chris@909 294 def test(user)
Chris@909 295 set_language_if_valid(user.language)
Chris@909 296 recipients user.mail
Chris@909 297 subject 'Redmine test'
Chris@909 298 body :url => url_for(:controller => 'welcome')
Chris@909 299 render_multipart('test', body)
Chris@909 300 end
Chris@909 301
Chris@909 302 # Overrides default deliver! method to prevent from sending an email
Chris@909 303 # with no recipient, cc or bcc
Chris@909 304 def deliver!(mail = @mail)
Chris@909 305 set_language_if_valid @initial_language
Chris@909 306 return false if (recipients.nil? || recipients.empty?) &&
Chris@909 307 (cc.nil? || cc.empty?) &&
Chris@909 308 (bcc.nil? || bcc.empty?)
Chris@909 309
Chris@909 310 # Set Message-Id and References
Chris@909 311 if @message_id_object
Chris@909 312 mail.message_id = self.class.message_id_for(@message_id_object)
Chris@909 313 end
Chris@909 314 if @references_objects
Chris@909 315 mail.references = @references_objects.collect {|o| self.class.message_id_for(o)}
Chris@909 316 end
Chris@909 317
Chris@909 318 # Log errors when raise_delivery_errors is set to false, Rails does not
Chris@909 319 raise_errors = self.class.raise_delivery_errors
Chris@909 320 self.class.raise_delivery_errors = true
Chris@909 321 begin
Chris@909 322 return super(mail)
Chris@909 323 rescue Exception => e
Chris@909 324 if raise_errors
Chris@909 325 raise e
Chris@909 326 elsif mylogger
Chris@909 327 mylogger.error "The following error occured while sending email notification: \"#{e.message}\". Check your configuration in config/configuration.yml."
Chris@909 328 end
Chris@909 329 ensure
Chris@909 330 self.class.raise_delivery_errors = raise_errors
Chris@909 331 end
Chris@909 332 end
Chris@909 333
Chris@909 334 # Sends reminders to issue assignees
Chris@909 335 # Available options:
Chris@909 336 # * :days => how many days in the future to remind about (defaults to 7)
Chris@909 337 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
Chris@909 338 # * :project => id or identifier of project to process (defaults to all projects)
Chris@909 339 # * :users => array of user ids who should be reminded
Chris@909 340 def self.reminders(options={})
Chris@909 341 days = options[:days] || 7
Chris@909 342 project = options[:project] ? Project.find(options[:project]) : nil
Chris@909 343 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
Chris@909 344 user_ids = options[:users]
Chris@909 345
Chris@909 346 s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date]
Chris@909 347 s << "#{Issue.table_name}.assigned_to_id IS NOT NULL"
Chris@909 348 s << ["#{Issue.table_name}.assigned_to_id IN (?)", user_ids] if user_ids.present?
Chris@909 349 s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
Chris@909 350 s << "#{Issue.table_name}.project_id = #{project.id}" if project
Chris@909 351 s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
Chris@909 352
Chris@909 353 issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker],
Chris@909 354 :conditions => s.conditions
Chris@909 355 ).group_by(&:assigned_to)
Chris@909 356 issues_by_assignee.each do |assignee, issues|
Chris@909 357 deliver_reminder(assignee, issues, days) if assignee && assignee.active?
Chris@909 358 end
Chris@909 359 end
Chris@909 360
Chris@909 361 # Activates/desactivates email deliveries during +block+
Chris@909 362 def self.with_deliveries(enabled = true, &block)
Chris@909 363 was_enabled = ActionMailer::Base.perform_deliveries
Chris@909 364 ActionMailer::Base.perform_deliveries = !!enabled
Chris@909 365 yield
Chris@909 366 ensure
Chris@909 367 ActionMailer::Base.perform_deliveries = was_enabled
Chris@909 368 end
Chris@909 369
Chris@909 370 private
Chris@909 371 def initialize_defaults(method_name)
Chris@909 372 super
Chris@909 373 @initial_language = current_language
Chris@909 374 set_language_if_valid Setting.default_language
Chris@909 375 from Setting.mail_from
Chris@909 376
Chris@909 377 # Common headers
Chris@909 378 headers 'X-Mailer' => 'Redmine',
Chris@909 379 'X-Redmine-Host' => Setting.host_name,
Chris@909 380 'X-Redmine-Site' => Setting.app_title,
Chris@909 381 'X-Auto-Response-Suppress' => 'OOF',
Chris@909 382 'Auto-Submitted' => 'auto-generated'
Chris@909 383 end
Chris@909 384
Chris@909 385 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
Chris@909 386 def redmine_headers(h)
Chris@909 387 h.each { |k,v| headers["X-Redmine-#{k}"] = v }
Chris@909 388 end
Chris@909 389
Chris@909 390 # Overrides the create_mail method
Chris@909 391 def create_mail
Chris@909 392 # Removes the current user from the recipients and cc
Chris@909 393 # if he doesn't want to receive notifications about what he does
Chris@909 394 @author ||= User.current
Chris@909 395 if @author.pref[:no_self_notified]
Chris@909 396 recipients.delete(@author.mail) if recipients
Chris@909 397 cc.delete(@author.mail) if cc
Chris@909 398 end
Chris@909 399
Chris@909 400 notified_users = [recipients, cc].flatten.compact.uniq
Chris@909 401 # Rails would log recipients only, not cc and bcc
Chris@909 402 mylogger.info "Sending email notification to: #{notified_users.join(', ')}" if mylogger
Chris@909 403
Chris@909 404 # Blind carbon copy recipients
Chris@909 405 if Setting.bcc_recipients?
Chris@909 406 bcc(notified_users)
Chris@909 407 recipients []
Chris@909 408 cc []
Chris@909 409 end
Chris@909 410 super
Chris@909 411 end
Chris@909 412
Chris@909 413 # Rails 2.3 has problems rendering implicit multipart messages with
Chris@909 414 # layouts so this method will wrap an multipart messages with
Chris@909 415 # explicit parts.
Chris@909 416 #
Chris@909 417 # https://rails.lighthouseapp.com/projects/8994/tickets/2338-actionmailer-mailer-views-and-content-type
Chris@909 418 # https://rails.lighthouseapp.com/projects/8994/tickets/1799-actionmailer-doesnt-set-template_format-when-rendering-layouts
Chris@909 419
Chris@909 420 def render_multipart(method_name, body)
Chris@909 421 if Setting.plain_text_mail?
Chris@909 422 content_type "text/plain"
Chris@909 423 body render(:file => "#{method_name}.text.erb",
Chris@909 424 :body => body,
Chris@909 425 :layout => 'mailer.text.erb')
Chris@909 426 else
Chris@909 427 content_type "multipart/alternative"
Chris@909 428 part :content_type => "text/plain",
Chris@909 429 :body => render(:file => "#{method_name}.text.erb",
Chris@909 430 :body => body, :layout => 'mailer.text.erb')
Chris@909 431 part :content_type => "text/html",
Chris@909 432 :body => render_message("#{method_name}.html.erb", body)
Chris@909 433 end
Chris@909 434 end
Chris@909 435
Chris@909 436 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
Chris@909 437 def self.controller_path
Chris@909 438 ''
Chris@909 439 end unless respond_to?('controller_path')
Chris@909 440
Chris@909 441 # Returns a predictable Message-Id for the given object
Chris@909 442 def self.message_id_for(object)
Chris@909 443 # id + timestamp should reduce the odds of a collision
Chris@909 444 # as far as we don't send multiple emails for the same object
Chris@909 445 timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on)
Chris@909 446 hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}"
Chris@909 447 host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
Chris@909 448 host = "#{::Socket.gethostname}.redmine" if host.empty?
Chris@909 449 "<#{hash}@#{host}>"
Chris@909 450 end
Chris@909 451
Chris@909 452 private
Chris@909 453
Chris@909 454 def message_id(object)
Chris@909 455 @message_id_object = object
Chris@909 456 end
Chris@909 457
Chris@909 458 def references(object)
Chris@909 459 @references_objects ||= []
Chris@909 460 @references_objects << object
Chris@909 461 end
Chris@909 462
Chris@909 463 def mylogger
Chris@909 464 Rails.logger
Chris@909 465 end
Chris@909 466 end
Chris@909 467
Chris@909 468 # Patch TMail so that message_id is not overwritten
Chris@909 469 module TMail
Chris@909 470 class Mail
Chris@909 471 def add_message_id( fqdn = nil )
Chris@909 472 self.message_id ||= ::TMail::new_message_id(fqdn)
Chris@909 473 end
Chris@909 474 end
Chris@909 475 end