diff app/models/mailer.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 0579821a129a
children 350acce374a2 cbb26bc654de
line wrap: on
line diff
--- a/app/models/mailer.rb	Thu Mar 03 11:42:28 2011 +0000
+++ b/app/models/mailer.rb	Mon Jun 06 14:24:13 2011 +0100
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006-2007  Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -31,7 +31,7 @@
     h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
     { :host => h, :protocol => Setting.protocol }
   end
-  
+
   # Builds a tmail object used to email recipients of the added issue.
   #
   # Example:
@@ -85,7 +85,7 @@
     subject l(:mail_subject_reminder, :count => issues.size, :days => days)
     body :issues => issues,
          :days => days,
-         :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc')
+         :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort => 'due_date:asc')
     render_multipart('reminder', body)
   end
 
@@ -114,11 +114,11 @@
     added_to_url = ''
     case container.class.name
     when 'Project'
-      added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container)
+      added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container)
       added_to = "#{l(:label_project)}: #{container}"
       recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect  {|u| u.mail}
     when 'Version'
-      added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
+      added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project)
       added_to = "#{l(:label_version)}: #{container.name}"
       recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect  {|u| u.mail}
     when 'Document'
@@ -133,7 +133,7 @@
          :added_to_url => added_to_url
     render_multipart('attachments_added', body)
   end
-  
+
   # Builds a tmail object used to email recipients of a news' project when a news item is added.
   #
   # Example:
@@ -149,7 +149,25 @@
     render_multipart('news_added', body)
   end
 
-  # Builds a tmail object used to email the recipients of the specified message that was posted. 
+  # Builds a tmail object used to email recipients of a news' project when a news comment is added.
+  #
+  # Example:
+  #   news_comment_added(comment) => tmail object
+  #   Mailer.news_comment_added(comment) => sends an email to the news' project recipients
+  def news_comment_added(comment)
+    news = comment.commented
+    redmine_headers 'Project' => news.project.identifier
+    message_id comment
+    recipients news.recipients
+    cc news.watcher_recipients
+    subject "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
+    body :news => news,
+         :comment => comment,
+         :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
+    render_multipart('news_comment_added', body)
+  end
+
+  # Builds a tmail object used to email the recipients of the specified message that was posted.
   #
   # Example:
   #   message_posted(message) => tmail object
@@ -166,8 +184,8 @@
          :message_url => url_for(message.event_url)
     render_multipart('message_posted', body)
   end
-  
-  # Builds a tmail object used to email the recipients of a project of the specified wiki content was added. 
+
+  # Builds a tmail object used to email the recipients of a project of the specified wiki content was added.
   #
   # Example:
   #   wiki_content_added(wiki_content) => tmail object
@@ -183,8 +201,8 @@
          :wiki_content_url => url_for(:controller => 'wiki', :action => 'show', :project_id => wiki_content.project, :id => wiki_content.page.title)
     render_multipart('wiki_content_added', body)
   end
-  
-  # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated. 
+
+  # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated.
   #
   # Example:
   #   wiki_content_updated(wiki_content) => tmail object
@@ -278,7 +296,7 @@
     return false if (recipients.nil? || recipients.empty?) &&
                     (cc.nil? || cc.empty?) &&
                     (bcc.nil? || bcc.empty?)
-                    
+
     # Set Message-Id and References
     if @message_id_object
       mail.message_id = self.class.message_id_for(@message_id_object)
@@ -286,7 +304,7 @@
     if @references_objects
       mail.references = @references_objects.collect {|o| self.class.message_id_for(o)}
     end
-    
+
     # Log errors when raise_delivery_errors is set to false, Rails does not
     raise_errors = self.class.raise_delivery_errors
     self.class.raise_delivery_errors = true
@@ -326,10 +344,10 @@
                                           :conditions => s.conditions
                                     ).group_by(&:assigned_to)
     issues_by_assignee.each do |assignee, issues|
-      deliver_reminder(assignee, issues, days) unless assignee.nil?
+      deliver_reminder(assignee, issues, days) if assignee && assignee.active?
     end
   end
-  
+
   # Activates/desactivates email deliveries during +block+
   def self.with_deliveries(enabled = true, &block)
     was_enabled = ActionMailer::Base.perform_deliveries
@@ -345,7 +363,7 @@
     @initial_language = current_language
     set_language_if_valid Setting.default_language
     from Setting.mail_from
-    
+
     # Common headers
     headers 'X-Mailer' => 'Redmine',
             'X-Redmine-Host' => Setting.host_name,
@@ -368,11 +386,11 @@
       recipients.delete(@author.mail) if recipients
       cc.delete(@author.mail) if cc
     end
-    
+
     notified_users = [recipients, cc].flatten.compact.uniq
     # Rails would log recipients only, not cc and bcc
     mylogger.info "Sending email notification to: #{notified_users.join(', ')}" if mylogger
-    
+
     # Blind carbon copy recipients
     if Setting.bcc_recipients?
       bcc(notified_users)
@@ -388,7 +406,7 @@
   #
   # https://rails.lighthouseapp.com/projects/8994/tickets/2338-actionmailer-mailer-views-and-content-type
   # https://rails.lighthouseapp.com/projects/8994/tickets/1799-actionmailer-doesnt-set-template_format-when-rendering-layouts
-  
+
   def render_multipart(method_name, body)
     if Setting.plain_text_mail?
       content_type "text/plain"
@@ -404,29 +422,29 @@
   def self.controller_path
     ''
   end unless respond_to?('controller_path')
-  
+
   # Returns a predictable Message-Id for the given object
   def self.message_id_for(object)
     # id + timestamp should reduce the odds of a collision
     # as far as we don't send multiple emails for the same object
-    timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on) 
+    timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on)
     hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}"
     host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
     host = "#{::Socket.gethostname}.redmine" if host.empty?
     "<#{hash}@#{host}>"
   end
-  
+
   private
-  
+
   def message_id(object)
     @message_id_object = object
   end
-  
+
   def references(object)
     @references_objects ||= []
     @references_objects << object
   end
-    
+
   def mylogger
     RAILS_DEFAULT_LOGGER
   end