OSDN Git Service

Removed translated email templates attachments_added and document_added (no longer...
[redminele/redmine.git] / app / models / mailer.rb
1 # redMine - project management software
2 # Copyright (C) 2006-2007  Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 class Mailer < ActionMailer::Base
19   helper ApplicationHelper
20   helper IssuesHelper
21   helper CustomFieldsHelper
22   
23   def account_information(user, password)
24     set_language_if_valid user.language
25     recipients user.mail
26     from Setting.mail_from
27     subject l(:mail_subject_register)
28     body :user => user, :password => password
29   end
30
31   def issue_add(issue)
32     set_language_if_valid(Setting.default_language)
33     # Sends to all project members
34     @recipients     = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
35     # Sends to author and assignee (even if they turned off mail notification)
36     @recipients     << issue.author.mail if issue.author
37     @recipients     << issue.assigned_to.mail if issue.assigned_to
38     @recipients.compact!
39     @recipients.uniq!
40     @from           = Setting.mail_from
41     @subject        = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
42     @body['issue']  = issue
43   end
44
45   def issue_edit(journal)
46     set_language_if_valid(Setting.default_language)
47     # Sends to all project members
48     issue = journal.journalized
49     @recipients     = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
50     # Sends to author and assignee (even if they turned off mail notification)
51     @recipients     << issue.author.mail if issue.author
52     @recipients     << issue.assigned_to.mail if issue.assigned_to
53     @recipients.compact!
54     @recipients.uniq!
55     # Watchers in cc
56     @cc             = issue.watcher_recipients - @recipients
57     @from           = Setting.mail_from
58     @subject        = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
59     @body['issue']  = issue
60     @body['journal']= journal
61   end
62   
63   def document_added(document)
64     set_language_if_valid(Setting.default_language)
65     @recipients     = document.project.users.collect { |u| u.mail if u.mail_notification }.compact
66     @from           = Setting.mail_from
67     @subject        = "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
68     @body['document'] = document
69   end
70   
71   def attachments_added(attachments)
72     set_language_if_valid(Setting.default_language)
73     container = attachments.first.container
74     url = ''
75     added_to = ''
76     case container.class.name
77     when 'Version'
78       url = {:only_path => false, :host => Setting.host_name, :controller => 'projects', :action => 'list_files', :id => container.project_id}
79       added_to = "#{l(:label_version)}: #{container.name}"
80     when 'Document'
81       url = {:only_path => false, :host => Setting.host_name, :controller => 'documents', :action => 'show', :id => container.id}
82       added_to = "#{l(:label_document)}: #{container.title}"
83     end
84     @recipients     = container.project.users.collect { |u| u.mail if u.mail_notification }.compact
85     @from           = Setting.mail_from
86     @subject        = "[#{container.project.name}] #{l(:label_attachment_new)}"
87     @body['attachments'] = attachments
88     @body['url']    = url
89     @body['added_to'] = added_to
90   end
91
92   def news_added(news)
93     set_language_if_valid(Setting.default_language)
94     @recipients     = news.project.users.collect { |u| u.mail if u.mail_notification }.compact
95     @from           = Setting.mail_from
96     @subject        = "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
97     @body['news'] = news
98   end
99   
100   def lost_password(token)
101     set_language_if_valid(token.user.language)
102     @recipients     = token.user.mail
103     @from           = Setting.mail_from
104     @subject        = l(:mail_subject_lost_password)
105     @body['token']  = token
106   end  
107
108   def register(token)
109     set_language_if_valid(token.user.language)
110     @recipients     = token.user.mail
111     @from           = Setting.mail_from
112     @subject        = l(:mail_subject_register)
113     @body['token']  = token
114   end
115   
116   def message_posted(message, recipients)
117     set_language_if_valid(Setting.default_language)
118     @recipients     = recipients
119     @from           = Setting.mail_from
120     @subject        = "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
121     @body['message'] = message
122   end
123   
124   def test(user)
125     set_language_if_valid(user.language)
126     @recipients     = user.mail
127     @from           = Setting.mail_from
128     @subject        = 'Redmine'
129   end
130 end