annotate app/models/mailer.rb @ 1296:038ba2d95de8 redmine-2.2

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