annotate .svn/pristine/ab/ab96afdc85199bd90097700415e66f01fff19c6b.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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