##// END OF EJS Templates
Add the following headers to email notifications (#830, #247):...
Jean-Philippe Lang -
r1250:f271e772afba
parent child
Show More
@@ -1,172 +1,194
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Mailer < ActionMailer::Base
19 19 helper :application
20 20 helper :issues
21 21 helper :custom_fields
22 22
23 23 include ActionController::UrlWriter
24 24
25 25 def issue_add(issue)
26 redmine_headers 'Project' => issue.project.identifier,
27 'Issue-Id' => issue.id,
28 'Issue-Author' => issue.author.login
29 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
26 30 recipients issue.recipients
27 31 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
28 32 body :issue => issue,
29 33 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
30 34 end
31 35
32 36 def issue_edit(journal)
33 37 issue = journal.journalized
38 redmine_headers 'Project' => issue.project.identifier,
39 'Issue-Id' => issue.id,
40 'Issue-Author' => issue.author.login
41 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
34 42 recipients issue.recipients
35 43 # Watchers in cc
36 44 cc(issue.watcher_recipients - @recipients)
37 45 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
38 46 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
39 47 s << issue.subject
40 48 subject s
41 49 body :issue => issue,
42 50 :journal => journal,
43 51 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
44 52 end
45 53
46 54 def document_added(document)
55 redmine_headers 'Project' => document.project.identifier
47 56 recipients document.project.recipients
48 57 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
49 58 body :document => document,
50 59 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
51 60 end
52 61
53 62 def attachments_added(attachments)
54 63 container = attachments.first.container
55 64 added_to = ''
56 65 added_to_url = ''
57 66 case container.class.name
58 67 when 'Version'
59 68 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
60 69 added_to = "#{l(:label_version)}: #{container.name}"
61 70 when 'Document'
62 71 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
63 72 added_to = "#{l(:label_document)}: #{container.title}"
64 73 end
74 redmine_headers 'Project' => container.project.identifier
65 75 recipients container.project.recipients
66 76 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
67 77 body :attachments => attachments,
68 78 :added_to => added_to,
69 79 :added_to_url => added_to_url
70 80 end
71 81
72 82 def news_added(news)
83 redmine_headers 'Project' => news.project.identifier
73 84 recipients news.project.recipients
74 85 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
75 86 body :news => news,
76 87 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
77 88 end
78 89
79 90 def message_posted(message, recipients)
91 redmine_headers 'Project' => message.project.identifier,
92 'Topic-Id' => (message.parent_id || message.id)
80 93 recipients(recipients)
81 94 subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
82 95 body :message => message,
83 96 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
84 97 end
85 98
86 99 def account_information(user, password)
87 100 set_language_if_valid user.language
88 101 recipients user.mail
89 102 subject l(:mail_subject_register, Setting.app_title)
90 103 body :user => user,
91 104 :password => password,
92 105 :login_url => url_for(:controller => 'account', :action => 'login')
93 106 end
94 107
95 108 def account_activation_request(user)
96 109 # Send the email to all active administrators
97 110 recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
98 111 subject l(:mail_subject_account_activation_request, Setting.app_title)
99 112 body :user => user,
100 113 :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
101 114 end
102 115
103 116 def lost_password(token)
104 117 set_language_if_valid(token.user.language)
105 118 recipients token.user.mail
106 119 subject l(:mail_subject_lost_password, Setting.app_title)
107 120 body :token => token,
108 121 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
109 122 end
110 123
111 124 def register(token)
112 125 set_language_if_valid(token.user.language)
113 126 recipients token.user.mail
114 127 subject l(:mail_subject_register, Setting.app_title)
115 128 body :token => token,
116 129 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
117 130 end
118 131
119 132 def test(user)
120 133 set_language_if_valid(user.language)
121 134 recipients user.mail
122 135 subject 'Redmine test'
123 136 body :url => url_for(:controller => 'welcome')
124 137 end
125 138
126 139 # Overrides default deliver! method to prevent from sending an email
127 140 # with no recipient, cc or bcc
128 141 def deliver!(mail = @mail)
129 142 return false if (recipients.nil? || recipients.empty?) &&
130 143 (cc.nil? || cc.empty?) &&
131 144 (bcc.nil? || bcc.empty?)
132 145 super
133 146 end
134 147
135 148 private
136 149 def initialize_defaults(method_name)
137 150 super
138 151 set_language_if_valid Setting.default_language
139 152 from Setting.mail_from
140 153 default_url_options[:host] = Setting.host_name
141 154 default_url_options[:protocol] = Setting.protocol
155 # Common headers
156 headers 'X-Mailer' => 'Redmine',
157 'X-Redmine-Host' => Setting.host_name,
158 'X-Redmine-Site' => Setting.app_title
159 end
160
161 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
162 def redmine_headers(h)
163 h.each { |k,v| headers["X-Redmine-#{k}"] = v }
142 164 end
143 165
144 166 # Overrides the create_mail method
145 167 def create_mail
146 168 # Removes the current user from the recipients and cc
147 169 # if he doesn't want to receive notifications about what he does
148 170 if User.current.pref[:no_self_notified]
149 171 recipients.delete(User.current.mail) if recipients
150 172 cc.delete(User.current.mail) if cc
151 173 end
152 174 # Blind carbon copy recipients
153 175 if Setting.bcc_recipients?
154 176 bcc([recipients, cc].flatten.compact.uniq)
155 177 recipients []
156 178 cc []
157 179 end
158 180 super
159 181 end
160 182
161 183 # Renders a message with the corresponding layout
162 184 def render_message(method_name, body)
163 185 layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
164 186 body[:content_for_layout] = render(:file => method_name, :body => body)
165 187 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}")
166 188 end
167 189
168 190 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
169 191 def self.controller_path
170 192 ''
171 193 end unless respond_to?('controller_path')
172 194 end
General Comments 0
You need to be logged in to leave comments. Login now