##// END OF EJS Templates
Fixes code comments....
Jean-Philippe Lang -
r2657:fe8f4e5b8794
parent child
Show More
@@ -1,385 +1,385
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Mailer < ActionMailer::Base
18 class Mailer < ActionMailer::Base
19 helper :application
19 helper :application
20 helper :issues
20 helper :issues
21 helper :custom_fields
21 helper :custom_fields
22
22
23 include ActionController::UrlWriter
23 include ActionController::UrlWriter
24 include Redmine::I18n
24 include Redmine::I18n
25
25
26 def self.default_url_options
26 def self.default_url_options
27 h = Setting.host_name
27 h = Setting.host_name
28 h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
28 h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
29 { :host => h, :protocol => Setting.protocol }
29 { :host => h, :protocol => Setting.protocol }
30 end
30 end
31
31
32 # Builds a tmail object used to email recipients of the added issue.
32 # Builds a tmail object used to email recipients of the added issue.
33 #
33 #
34 # Example:
34 # Example:
35 # issue_add(issue) => tmail object
35 # issue_add(issue) => tmail object
36 # Mailer.deliver_issue_add(issue) => sends an email to issue recipients
36 # Mailer.deliver_issue_add(issue) => sends an email to issue recipients
37 def issue_add(issue)
37 def issue_add(issue)
38 redmine_headers 'Project' => issue.project.identifier,
38 redmine_headers 'Project' => issue.project.identifier,
39 'Issue-Id' => issue.id,
39 'Issue-Id' => issue.id,
40 'Issue-Author' => issue.author.login
40 'Issue-Author' => issue.author.login
41 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
41 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
42 message_id issue
42 message_id issue
43 recipients issue.recipients
43 recipients issue.recipients
44 cc(issue.watcher_recipients - @recipients)
44 cc(issue.watcher_recipients - @recipients)
45 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
45 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
46 body :issue => issue,
46 body :issue => issue,
47 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
47 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
48 end
48 end
49
49
50 # Builds a tmail object used to email recipients of the edited issue.
50 # Builds a tmail object used to email recipients of the edited issue.
51 #
51 #
52 # Example:
52 # Example:
53 # issue_edit(journal) => tmail object
53 # issue_edit(journal) => tmail object
54 # Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
54 # Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
55 def issue_edit(journal)
55 def issue_edit(journal)
56 issue = journal.journalized.reload
56 issue = journal.journalized.reload
57 redmine_headers 'Project' => issue.project.identifier,
57 redmine_headers 'Project' => issue.project.identifier,
58 'Issue-Id' => issue.id,
58 'Issue-Id' => issue.id,
59 'Issue-Author' => issue.author.login
59 'Issue-Author' => issue.author.login
60 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
60 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
61 message_id journal
61 message_id journal
62 references issue
62 references issue
63 @author = journal.user
63 @author = journal.user
64 recipients issue.recipients
64 recipients issue.recipients
65 # Watchers in cc
65 # Watchers in cc
66 cc(issue.watcher_recipients - @recipients)
66 cc(issue.watcher_recipients - @recipients)
67 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
67 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
68 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
68 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
69 s << issue.subject
69 s << issue.subject
70 subject s
70 subject s
71 body :issue => issue,
71 body :issue => issue,
72 :journal => journal,
72 :journal => journal,
73 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
73 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
74 end
74 end
75
75
76 def reminder(user, issues, days)
76 def reminder(user, issues, days)
77 set_language_if_valid user.language
77 set_language_if_valid user.language
78 recipients user.mail
78 recipients user.mail
79 subject l(:mail_subject_reminder, issues.size)
79 subject l(:mail_subject_reminder, issues.size)
80 body :issues => issues,
80 body :issues => issues,
81 :days => days,
81 :days => days,
82 :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc')
82 :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc')
83 end
83 end
84
84
85 # Builds a tmail object used to email users belonging to the added document's project.
85 # Builds a tmail object used to email users belonging to the added document's project.
86 #
86 #
87 # Example:
87 # Example:
88 # document_added(document) => tmail object
88 # document_added(document) => tmail object
89 # Mailer.deliver_document_added(document) => sends an email to the document's project recipients
89 # Mailer.deliver_document_added(document) => sends an email to the document's project recipients
90 def document_added(document)
90 def document_added(document)
91 redmine_headers 'Project' => document.project.identifier
91 redmine_headers 'Project' => document.project.identifier
92 recipients document.project.recipients
92 recipients document.project.recipients
93 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
93 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
94 body :document => document,
94 body :document => document,
95 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
95 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
96 end
96 end
97
97
98 # Builds a tmail object used to email recipients of a project when an attachements are added.
98 # Builds a tmail object used to email recipients of a project when an attachements are added.
99 #
99 #
100 # Example:
100 # Example:
101 # attachments_added(attachments) => tmail object
101 # attachments_added(attachments) => tmail object
102 # Mailer.deliver_attachments_added(attachments) => sends an email to the project's recipients
102 # Mailer.deliver_attachments_added(attachments) => sends an email to the project's recipients
103 def attachments_added(attachments)
103 def attachments_added(attachments)
104 container = attachments.first.container
104 container = attachments.first.container
105 added_to = ''
105 added_to = ''
106 added_to_url = ''
106 added_to_url = ''
107 case container.class.name
107 case container.class.name
108 when 'Project'
108 when 'Project'
109 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container)
109 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container)
110 added_to = "#{l(:label_project)}: #{container}"
110 added_to = "#{l(:label_project)}: #{container}"
111 when 'Version'
111 when 'Version'
112 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
112 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
113 added_to = "#{l(:label_version)}: #{container.name}"
113 added_to = "#{l(:label_version)}: #{container.name}"
114 when 'Document'
114 when 'Document'
115 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
115 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
116 added_to = "#{l(:label_document)}: #{container.title}"
116 added_to = "#{l(:label_document)}: #{container.title}"
117 end
117 end
118 redmine_headers 'Project' => container.project.identifier
118 redmine_headers 'Project' => container.project.identifier
119 recipients container.project.recipients
119 recipients container.project.recipients
120 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
120 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
121 body :attachments => attachments,
121 body :attachments => attachments,
122 :added_to => added_to,
122 :added_to => added_to,
123 :added_to_url => added_to_url
123 :added_to_url => added_to_url
124 end
124 end
125
125
126 # Builds a tmail object used to email recipients of a news' project when a news item is added.
126 # Builds a tmail object used to email recipients of a news' project when a news item is added.
127 #
127 #
128 # Example:
128 # Example:
129 # news_added(news) => tmail object
129 # news_added(news) => tmail object
130 # Mailer.deliver_news_added(news) => sends an email to the news' project recipients
130 # Mailer.deliver_news_added(news) => sends an email to the news' project recipients
131 def news_added(news)
131 def news_added(news)
132 redmine_headers 'Project' => news.project.identifier
132 redmine_headers 'Project' => news.project.identifier
133 message_id news
133 message_id news
134 recipients news.project.recipients
134 recipients news.project.recipients
135 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
135 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
136 body :news => news,
136 body :news => news,
137 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
137 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
138 end
138 end
139
139
140 # Builds a tmail object used to email the specified recipients of the specified message that was posted.
140 # Builds a tmail object used to email the specified recipients of the specified message that was posted.
141 #
141 #
142 # Example:
142 # Example:
143 # message_posted(message, recipients) => tmail object
143 # message_posted(message, recipients) => tmail object
144 # Mailer.deliver_message_posted(message, recipients) => sends an email to the recipients
144 # Mailer.deliver_message_posted(message, recipients) => sends an email to the recipients
145 def message_posted(message, recipients)
145 def message_posted(message, recipients)
146 redmine_headers 'Project' => message.project.identifier,
146 redmine_headers 'Project' => message.project.identifier,
147 'Topic-Id' => (message.parent_id || message.id)
147 'Topic-Id' => (message.parent_id || message.id)
148 message_id message
148 message_id message
149 references message.parent unless message.parent.nil?
149 references message.parent unless message.parent.nil?
150 recipients(recipients)
150 recipients(recipients)
151 subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
151 subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
152 body :message => message,
152 body :message => message,
153 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
153 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
154 end
154 end
155
155
156 # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated.
156 # Builds a tmail object used to email the recipients of a project of the specified wiki content was added.
157 #
157 #
158 # Example:
158 # Example:
159 # wiki_content_updated(wiki_content) => tmail object
159 # wiki_content_added(wiki_content) => tmail object
160 # Mailer.deliver_wiki_content_updated(wiki_content) => sends an email to the project's recipients
160 # Mailer.deliver_wiki_content_added(wiki_content) => sends an email to the project's recipients
161 def wiki_content_added(wiki_content)
161 def wiki_content_added(wiki_content)
162 redmine_headers 'Project' => wiki_content.project.identifier,
162 redmine_headers 'Project' => wiki_content.project.identifier,
163 'Wiki-Page-Id' => wiki_content.page.id
163 'Wiki-Page-Id' => wiki_content.page.id
164 message_id wiki_content
164 message_id wiki_content
165 recipients wiki_content.project.recipients
165 recipients wiki_content.project.recipients
166 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :page => wiki_content.page.pretty_title)}"
166 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :page => wiki_content.page.pretty_title)}"
167 body :wiki_content => wiki_content,
167 body :wiki_content => wiki_content,
168 :wiki_content_url => url_for(:controller => 'wiki', :action => 'index', :id => wiki_content.project, :page => wiki_content.page.title)
168 :wiki_content_url => url_for(:controller => 'wiki', :action => 'index', :id => wiki_content.project, :page => wiki_content.page.title)
169 end
169 end
170
170
171 # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated.
171 # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated.
172 #
172 #
173 # Example:
173 # Example:
174 # wiki_content_updated(wiki_content) => tmail object
174 # wiki_content_updated(wiki_content) => tmail object
175 # Mailer.deliver_wiki_content_updated(wiki_content) => sends an email to the project's recipients
175 # Mailer.deliver_wiki_content_updated(wiki_content) => sends an email to the project's recipients
176 def wiki_content_updated(wiki_content)
176 def wiki_content_updated(wiki_content)
177 redmine_headers 'Project' => wiki_content.project.identifier,
177 redmine_headers 'Project' => wiki_content.project.identifier,
178 'Wiki-Page-Id' => wiki_content.page.id
178 'Wiki-Page-Id' => wiki_content.page.id
179 message_id wiki_content
179 message_id wiki_content
180 recipients wiki_content.project.recipients
180 recipients wiki_content.project.recipients
181 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :page => wiki_content.page.pretty_title)}"
181 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :page => wiki_content.page.pretty_title)}"
182 body :wiki_content => wiki_content,
182 body :wiki_content => wiki_content,
183 :wiki_content_url => url_for(:controller => 'wiki', :action => 'index', :id => wiki_content.project, :page => wiki_content.page.title),
183 :wiki_content_url => url_for(:controller => 'wiki', :action => 'index', :id => wiki_content.project, :page => wiki_content.page.title),
184 :wiki_diff_url => url_for(:controller => 'wiki', :action => 'diff', :id => wiki_content.project, :page => wiki_content.page.title, :version => wiki_content.version)
184 :wiki_diff_url => url_for(:controller => 'wiki', :action => 'diff', :id => wiki_content.project, :page => wiki_content.page.title, :version => wiki_content.version)
185 end
185 end
186
186
187 # Builds a tmail object used to email the specified user their account information.
187 # Builds a tmail object used to email the specified user their account information.
188 #
188 #
189 # Example:
189 # Example:
190 # account_information(user, password) => tmail object
190 # account_information(user, password) => tmail object
191 # Mailer.deliver_account_information(user, password) => sends account information to the user
191 # Mailer.deliver_account_information(user, password) => sends account information to the user
192 def account_information(user, password)
192 def account_information(user, password)
193 set_language_if_valid user.language
193 set_language_if_valid user.language
194 recipients user.mail
194 recipients user.mail
195 subject l(:mail_subject_register, Setting.app_title)
195 subject l(:mail_subject_register, Setting.app_title)
196 body :user => user,
196 body :user => user,
197 :password => password,
197 :password => password,
198 :login_url => url_for(:controller => 'account', :action => 'login')
198 :login_url => url_for(:controller => 'account', :action => 'login')
199 end
199 end
200
200
201 # Builds a tmail object used to email all active administrators of an account activation request.
201 # Builds a tmail object used to email all active administrators of an account activation request.
202 #
202 #
203 # Example:
203 # Example:
204 # account_activation_request(user) => tmail object
204 # account_activation_request(user) => tmail object
205 # Mailer.deliver_account_activation_request(user)=> sends an email to all active administrators
205 # Mailer.deliver_account_activation_request(user)=> sends an email to all active administrators
206 def account_activation_request(user)
206 def account_activation_request(user)
207 # Send the email to all active administrators
207 # Send the email to all active administrators
208 recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
208 recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
209 subject l(:mail_subject_account_activation_request, Setting.app_title)
209 subject l(:mail_subject_account_activation_request, Setting.app_title)
210 body :user => user,
210 body :user => user,
211 :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
211 :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
212 end
212 end
213
213
214 # Builds a tmail object used to email the specified user that their account was activated by an administrator.
214 # Builds a tmail object used to email the specified user that their account was activated by an administrator.
215 #
215 #
216 # Example:
216 # Example:
217 # account_activated(user) => tmail object
217 # account_activated(user) => tmail object
218 # Mailer.deliver_account_activated(user) => sends an email to the registered user
218 # Mailer.deliver_account_activated(user) => sends an email to the registered user
219 def account_activated(user)
219 def account_activated(user)
220 set_language_if_valid user.language
220 set_language_if_valid user.language
221 recipients user.mail
221 recipients user.mail
222 subject l(:mail_subject_register, Setting.app_title)
222 subject l(:mail_subject_register, Setting.app_title)
223 body :user => user,
223 body :user => user,
224 :login_url => url_for(:controller => 'account', :action => 'login')
224 :login_url => url_for(:controller => 'account', :action => 'login')
225 end
225 end
226
226
227 def lost_password(token)
227 def lost_password(token)
228 set_language_if_valid(token.user.language)
228 set_language_if_valid(token.user.language)
229 recipients token.user.mail
229 recipients token.user.mail
230 subject l(:mail_subject_lost_password, Setting.app_title)
230 subject l(:mail_subject_lost_password, Setting.app_title)
231 body :token => token,
231 body :token => token,
232 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
232 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
233 end
233 end
234
234
235 def register(token)
235 def register(token)
236 set_language_if_valid(token.user.language)
236 set_language_if_valid(token.user.language)
237 recipients token.user.mail
237 recipients token.user.mail
238 subject l(:mail_subject_register, Setting.app_title)
238 subject l(:mail_subject_register, Setting.app_title)
239 body :token => token,
239 body :token => token,
240 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
240 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
241 end
241 end
242
242
243 def test(user)
243 def test(user)
244 set_language_if_valid(user.language)
244 set_language_if_valid(user.language)
245 recipients user.mail
245 recipients user.mail
246 subject 'Redmine test'
246 subject 'Redmine test'
247 body :url => url_for(:controller => 'welcome')
247 body :url => url_for(:controller => 'welcome')
248 end
248 end
249
249
250 # Overrides default deliver! method to prevent from sending an email
250 # Overrides default deliver! method to prevent from sending an email
251 # with no recipient, cc or bcc
251 # with no recipient, cc or bcc
252 def deliver!(mail = @mail)
252 def deliver!(mail = @mail)
253 return false if (recipients.nil? || recipients.empty?) &&
253 return false if (recipients.nil? || recipients.empty?) &&
254 (cc.nil? || cc.empty?) &&
254 (cc.nil? || cc.empty?) &&
255 (bcc.nil? || bcc.empty?)
255 (bcc.nil? || bcc.empty?)
256
256
257 # Set Message-Id and References
257 # Set Message-Id and References
258 if @message_id_object
258 if @message_id_object
259 mail.message_id = self.class.message_id_for(@message_id_object)
259 mail.message_id = self.class.message_id_for(@message_id_object)
260 end
260 end
261 if @references_objects
261 if @references_objects
262 mail.references = @references_objects.collect {|o| self.class.message_id_for(o)}
262 mail.references = @references_objects.collect {|o| self.class.message_id_for(o)}
263 end
263 end
264 super(mail)
264 super(mail)
265 end
265 end
266
266
267 # Sends reminders to issue assignees
267 # Sends reminders to issue assignees
268 # Available options:
268 # Available options:
269 # * :days => how many days in the future to remind about (defaults to 7)
269 # * :days => how many days in the future to remind about (defaults to 7)
270 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
270 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
271 # * :project => id or identifier of project to process (defaults to all projects)
271 # * :project => id or identifier of project to process (defaults to all projects)
272 def self.reminders(options={})
272 def self.reminders(options={})
273 days = options[:days] || 7
273 days = options[:days] || 7
274 project = options[:project] ? Project.find(options[:project]) : nil
274 project = options[:project] ? Project.find(options[:project]) : nil
275 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
275 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
276
276
277 s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date]
277 s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date]
278 s << "#{Issue.table_name}.assigned_to_id IS NOT NULL"
278 s << "#{Issue.table_name}.assigned_to_id IS NOT NULL"
279 s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
279 s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
280 s << "#{Issue.table_name}.project_id = #{project.id}" if project
280 s << "#{Issue.table_name}.project_id = #{project.id}" if project
281 s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
281 s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
282
282
283 issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker],
283 issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker],
284 :conditions => s.conditions
284 :conditions => s.conditions
285 ).group_by(&:assigned_to)
285 ).group_by(&:assigned_to)
286 issues_by_assignee.each do |assignee, issues|
286 issues_by_assignee.each do |assignee, issues|
287 deliver_reminder(assignee, issues, days) unless assignee.nil?
287 deliver_reminder(assignee, issues, days) unless assignee.nil?
288 end
288 end
289 end
289 end
290
290
291 private
291 private
292 def initialize_defaults(method_name)
292 def initialize_defaults(method_name)
293 super
293 super
294 set_language_if_valid Setting.default_language
294 set_language_if_valid Setting.default_language
295 from Setting.mail_from
295 from Setting.mail_from
296
296
297 # Common headers
297 # Common headers
298 headers 'X-Mailer' => 'Redmine',
298 headers 'X-Mailer' => 'Redmine',
299 'X-Redmine-Host' => Setting.host_name,
299 'X-Redmine-Host' => Setting.host_name,
300 'X-Redmine-Site' => Setting.app_title,
300 'X-Redmine-Site' => Setting.app_title,
301 'Precedence' => 'bulk',
301 'Precedence' => 'bulk',
302 'Auto-Submitted' => 'auto-generated'
302 'Auto-Submitted' => 'auto-generated'
303 end
303 end
304
304
305 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
305 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
306 def redmine_headers(h)
306 def redmine_headers(h)
307 h.each { |k,v| headers["X-Redmine-#{k}"] = v }
307 h.each { |k,v| headers["X-Redmine-#{k}"] = v }
308 end
308 end
309
309
310 # Overrides the create_mail method
310 # Overrides the create_mail method
311 def create_mail
311 def create_mail
312 # Removes the current user from the recipients and cc
312 # Removes the current user from the recipients and cc
313 # if he doesn't want to receive notifications about what he does
313 # if he doesn't want to receive notifications about what he does
314 @author ||= User.current
314 @author ||= User.current
315 if @author.pref[:no_self_notified]
315 if @author.pref[:no_self_notified]
316 recipients.delete(@author.mail) if recipients
316 recipients.delete(@author.mail) if recipients
317 cc.delete(@author.mail) if cc
317 cc.delete(@author.mail) if cc
318 end
318 end
319 # Blind carbon copy recipients
319 # Blind carbon copy recipients
320 if Setting.bcc_recipients?
320 if Setting.bcc_recipients?
321 bcc([recipients, cc].flatten.compact.uniq)
321 bcc([recipients, cc].flatten.compact.uniq)
322 recipients []
322 recipients []
323 cc []
323 cc []
324 end
324 end
325 super
325 super
326 end
326 end
327
327
328 # Renders a message with the corresponding layout
328 # Renders a message with the corresponding layout
329 def render_message(method_name, body)
329 def render_message(method_name, body)
330 layout = method_name.to_s.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
330 layout = method_name.to_s.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
331 body[:content_for_layout] = render(:file => method_name, :body => body)
331 body[:content_for_layout] = render(:file => method_name, :body => body)
332 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true)
332 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true)
333 end
333 end
334
334
335 # for the case of plain text only
335 # for the case of plain text only
336 def body(*params)
336 def body(*params)
337 value = super(*params)
337 value = super(*params)
338 if Setting.plain_text_mail?
338 if Setting.plain_text_mail?
339 templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}")
339 templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}")
340 unless String === @body or templates.empty?
340 unless String === @body or templates.empty?
341 template = File.basename(templates.first)
341 template = File.basename(templates.first)
342 @body[:content_for_layout] = render(:file => template, :body => @body)
342 @body[:content_for_layout] = render(:file => template, :body => @body)
343 @body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true)
343 @body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true)
344 return @body
344 return @body
345 end
345 end
346 end
346 end
347 return value
347 return value
348 end
348 end
349
349
350 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
350 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
351 def self.controller_path
351 def self.controller_path
352 ''
352 ''
353 end unless respond_to?('controller_path')
353 end unless respond_to?('controller_path')
354
354
355 # Returns a predictable Message-Id for the given object
355 # Returns a predictable Message-Id for the given object
356 def self.message_id_for(object)
356 def self.message_id_for(object)
357 # id + timestamp should reduce the odds of a collision
357 # id + timestamp should reduce the odds of a collision
358 # as far as we don't send multiple emails for the same object
358 # as far as we don't send multiple emails for the same object
359 timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on)
359 timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on)
360 hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}"
360 hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}"
361 host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
361 host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
362 host = "#{::Socket.gethostname}.redmine" if host.empty?
362 host = "#{::Socket.gethostname}.redmine" if host.empty?
363 "<#{hash}@#{host}>"
363 "<#{hash}@#{host}>"
364 end
364 end
365
365
366 private
366 private
367
367
368 def message_id(object)
368 def message_id(object)
369 @message_id_object = object
369 @message_id_object = object
370 end
370 end
371
371
372 def references(object)
372 def references(object)
373 @references_objects ||= []
373 @references_objects ||= []
374 @references_objects << object
374 @references_objects << object
375 end
375 end
376 end
376 end
377
377
378 # Patch TMail so that message_id is not overwritten
378 # Patch TMail so that message_id is not overwritten
379 module TMail
379 module TMail
380 class Mail
380 class Mail
381 def add_message_id( fqdn = nil )
381 def add_message_id( fqdn = nil )
382 self.message_id ||= ::TMail::new_message_id(fqdn)
382 self.message_id ||= ::TMail::new_message_id(fqdn)
383 end
383 end
384 end
384 end
385 end
385 end
General Comments 0
You need to be logged in to leave comments. Login now