@@ -1,163 +1,172 | |||||
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 |
|
24 | |||
25 | def issue_add(issue) |
|
25 | def issue_add(issue) | |
26 | recipients issue.recipients |
|
26 | recipients issue.recipients | |
27 | subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" |
|
27 | subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" | |
28 | body :issue => issue, |
|
28 | body :issue => issue, | |
29 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
29 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | def issue_edit(journal) |
|
32 | def issue_edit(journal) | |
33 | issue = journal.journalized |
|
33 | issue = journal.journalized | |
34 | recipients issue.recipients |
|
34 | recipients issue.recipients | |
35 | # Watchers in cc |
|
35 | # Watchers in cc | |
36 | cc(issue.watcher_recipients - @recipients) |
|
36 | cc(issue.watcher_recipients - @recipients) | |
37 | s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " |
|
37 | s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " | |
38 | s << "(#{issue.status.name}) " if journal.new_value_for('status_id') |
|
38 | s << "(#{issue.status.name}) " if journal.new_value_for('status_id') | |
39 | s << issue.subject |
|
39 | s << issue.subject | |
40 | subject s |
|
40 | subject s | |
41 | body :issue => issue, |
|
41 | body :issue => issue, | |
42 | :journal => journal, |
|
42 | :journal => journal, | |
43 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
43 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def document_added(document) |
|
46 | def document_added(document) | |
47 | recipients document.project.recipients |
|
47 | recipients document.project.recipients | |
48 | subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" |
|
48 | subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" | |
49 | body :document => document, |
|
49 | body :document => document, | |
50 | :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) |
|
50 | :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def attachments_added(attachments) |
|
53 | def attachments_added(attachments) | |
54 | container = attachments.first.container |
|
54 | container = attachments.first.container | |
55 | added_to = '' |
|
55 | added_to = '' | |
56 | added_to_url = '' |
|
56 | added_to_url = '' | |
57 | case container.class.name |
|
57 | case container.class.name | |
58 | when 'Version' |
|
58 | when 'Version' | |
59 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id) |
|
59 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id) | |
60 | added_to = "#{l(:label_version)}: #{container.name}" |
|
60 | added_to = "#{l(:label_version)}: #{container.name}" | |
61 | when 'Document' |
|
61 | when 'Document' | |
62 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) |
|
62 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) | |
63 | added_to = "#{l(:label_document)}: #{container.title}" |
|
63 | added_to = "#{l(:label_document)}: #{container.title}" | |
64 | end |
|
64 | end | |
65 | recipients container.project.recipients |
|
65 | recipients container.project.recipients | |
66 | subject "[#{container.project.name}] #{l(:label_attachment_new)}" |
|
66 | subject "[#{container.project.name}] #{l(:label_attachment_new)}" | |
67 | body :attachments => attachments, |
|
67 | body :attachments => attachments, | |
68 | :added_to => added_to, |
|
68 | :added_to => added_to, | |
69 | :added_to_url => added_to_url |
|
69 | :added_to_url => added_to_url | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def news_added(news) |
|
72 | def news_added(news) | |
73 | recipients news.project.recipients |
|
73 | recipients news.project.recipients | |
74 | subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
74 | subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" | |
75 | body :news => news, |
|
75 | body :news => news, | |
76 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) |
|
76 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | def message_posted(message, recipients) |
|
79 | def message_posted(message, recipients) | |
80 | recipients(recipients) |
|
80 | recipients(recipients) | |
81 | subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}" |
|
81 | subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}" | |
82 | body :message => message, |
|
82 | body :message => message, | |
83 | :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root) |
|
83 | :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root) | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def account_information(user, password) |
|
86 | def account_information(user, password) | |
87 | set_language_if_valid user.language |
|
87 | set_language_if_valid user.language | |
88 | recipients user.mail |
|
88 | recipients user.mail | |
89 | subject l(:mail_subject_register) |
|
89 | subject l(:mail_subject_register) | |
90 | body :user => user, |
|
90 | body :user => user, | |
91 | :password => password, |
|
91 | :password => password, | |
92 | :login_url => url_for(:controller => 'account', :action => 'login') |
|
92 | :login_url => url_for(:controller => 'account', :action => 'login') | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def account_activation_request(user) |
|
95 | def account_activation_request(user) | |
96 | # Send the email to all active administrators |
|
96 | # Send the email to all active administrators | |
97 | recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact |
|
97 | recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact | |
98 | subject l(:mail_subject_account_activation_request) |
|
98 | subject l(:mail_subject_account_activation_request) | |
99 | body :user => user, |
|
99 | body :user => user, | |
100 | :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc') |
|
100 | :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc') | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | def lost_password(token) |
|
103 | def lost_password(token) | |
104 | set_language_if_valid(token.user.language) |
|
104 | set_language_if_valid(token.user.language) | |
105 | recipients token.user.mail |
|
105 | recipients token.user.mail | |
106 | subject l(:mail_subject_lost_password) |
|
106 | subject l(:mail_subject_lost_password) | |
107 | body :token => token, |
|
107 | body :token => token, | |
108 | :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value) |
|
108 | :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value) | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | def register(token) |
|
111 | def register(token) | |
112 | set_language_if_valid(token.user.language) |
|
112 | set_language_if_valid(token.user.language) | |
113 | recipients token.user.mail |
|
113 | recipients token.user.mail | |
114 | subject l(:mail_subject_register) |
|
114 | subject l(:mail_subject_register) | |
115 | body :token => token, |
|
115 | body :token => token, | |
116 | :url => url_for(:controller => 'account', :action => 'activate', :token => token.value) |
|
116 | :url => url_for(:controller => 'account', :action => 'activate', :token => token.value) | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def test(user) |
|
119 | def test(user) | |
120 | set_language_if_valid(user.language) |
|
120 | set_language_if_valid(user.language) | |
121 | recipients user.mail |
|
121 | recipients user.mail | |
122 | subject 'Redmine test' |
|
122 | subject 'Redmine test' | |
123 | body :url => url_for(:controller => 'welcome') |
|
123 | body :url => url_for(:controller => 'welcome') | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
|
126 | # Overrides default deliver! method to prevent from sending an email | |||
|
127 | # with no recipient, cc or bcc | |||
|
128 | def deliver!(mail = @mail) | |||
|
129 | return false if (recipients.nil? || recipients.empty?) && | |||
|
130 | (cc.nil? || cc.empty?) && | |||
|
131 | (bcc.nil? || bcc.empty?) | |||
|
132 | super | |||
|
133 | end | |||
|
134 | ||||
126 | private |
|
135 | private | |
127 | def initialize_defaults(method_name) |
|
136 | def initialize_defaults(method_name) | |
128 | super |
|
137 | super | |
129 | set_language_if_valid Setting.default_language |
|
138 | set_language_if_valid Setting.default_language | |
130 | from Setting.mail_from |
|
139 | from Setting.mail_from | |
131 | default_url_options[:host] = Setting.host_name |
|
140 | default_url_options[:host] = Setting.host_name | |
132 | default_url_options[:protocol] = Setting.protocol |
|
141 | default_url_options[:protocol] = Setting.protocol | |
133 | end |
|
142 | end | |
134 |
|
143 | |||
135 | # Overrides the create_mail method |
|
144 | # Overrides the create_mail method | |
136 | def create_mail |
|
145 | def create_mail | |
137 | # Removes the current user from the recipients and cc |
|
146 | # Removes the current user from the recipients and cc | |
138 | # if he doesn't want to receive notifications about what he does |
|
147 | # if he doesn't want to receive notifications about what he does | |
139 | if User.current.pref[:no_self_notified] |
|
148 | if User.current.pref[:no_self_notified] | |
140 | recipients.delete(User.current.mail) if recipients |
|
149 | recipients.delete(User.current.mail) if recipients | |
141 | cc.delete(User.current.mail) if cc |
|
150 | cc.delete(User.current.mail) if cc | |
142 | end |
|
151 | end | |
143 | # Blind carbon copy recipients |
|
152 | # Blind carbon copy recipients | |
144 | if Setting.bcc_recipients? |
|
153 | if Setting.bcc_recipients? | |
145 | bcc([recipients, cc].flatten.compact.uniq) |
|
154 | bcc([recipients, cc].flatten.compact.uniq) | |
146 | recipients [] |
|
155 | recipients [] | |
147 | cc [] |
|
156 | cc [] | |
148 | end |
|
157 | end | |
149 | super |
|
158 | super | |
150 | end |
|
159 | end | |
151 |
|
160 | |||
152 | # Renders a message with the corresponding layout |
|
161 | # Renders a message with the corresponding layout | |
153 | def render_message(method_name, body) |
|
162 | def render_message(method_name, body) | |
154 | layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml' |
|
163 | layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml' | |
155 | body[:content_for_layout] = render(:file => method_name, :body => body) |
|
164 | body[:content_for_layout] = render(:file => method_name, :body => body) | |
156 | ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}") |
|
165 | ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}") | |
157 | end |
|
166 | end | |
158 |
|
167 | |||
159 | # Makes partial rendering work with Rails 1.2 (retro-compatibility) |
|
168 | # Makes partial rendering work with Rails 1.2 (retro-compatibility) | |
160 | def self.controller_path |
|
169 | def self.controller_path | |
161 | '' |
|
170 | '' | |
162 | end unless respond_to?('controller_path') |
|
171 | end unless respond_to?('controller_path') | |
163 | end |
|
172 | end |
General Comments 0
You need to be logged in to leave comments.
Login now