annotate .svn/pristine/ab/ab96afdc85199bd90097700415e66f01fff19c6b.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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