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