diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-04 10:43:39 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-04 10:43:39 +0000 |
commit | bd434427e61edbac03d273a308dcfffe72096ae0 (patch) | |
tree | 73856165e0c0c2d3581492280a5d44f52b5364bd /app/models/mailer.rb | |
parent | 4ded4277c51b8f35dc9eaa031c918e55470a44b5 (diff) | |
download | redmine-bd434427e61edbac03d273a308dcfffe72096ae0.tar.gz redmine-bd434427e61edbac03d273a308dcfffe72096ae0.zip |
Mailer:
* added an application setting to specify the application protocol (http or https) used to generate urls
* added layouts for text and html emails
* no more language specific templates
* urls are now generated using UrlWriter
* the mailer now uses AdvAttrAccessor code style to set email parameters
git-svn-id: http://redmine.rubyforge.org/svn/trunk@877 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/mailer.rb')
-rw-r--r-- | app/models/mailer.rb | 134 |
1 files changed, 73 insertions, 61 deletions
diff --git a/app/models/mailer.rb b/app/models/mailer.rb index da7937404..c17e2aa19 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -20,99 +20,111 @@ class Mailer < ActionMailer::Base helper IssuesHelper helper CustomFieldsHelper - def account_information(user, password) - set_language_if_valid user.language - recipients user.mail - from Setting.mail_from - subject l(:mail_subject_register) - body :user => user, :password => password - end - - def issue_add(issue) - set_language_if_valid(Setting.default_language) - @recipients = issue.recipients - @from = Setting.mail_from - @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}" - @body['issue'] = issue + include ActionController::UrlWriter + + def issue_add(issue) + recipients issue.recipients + subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}" + body :issue => issue, + :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) end def issue_edit(journal) - set_language_if_valid(Setting.default_language) issue = journal.journalized - @recipients = issue.recipients + recipients issue.recipients # Watchers in cc - @cc = issue.watcher_recipients - @recipients - @from = Setting.mail_from - @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}" - @body['issue'] = issue - @body['journal']= journal + cc(issue.watcher_recipients - @recipients) + subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}" + body :issue => issue, + :journal => journal, + :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) end def document_added(document) - set_language_if_valid(Setting.default_language) - @recipients = document.project.recipients - @from = Setting.mail_from - @subject = "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" - @body['document'] = document + recipients document.project.recipients + subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" + body :document => document, + :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) end def attachments_added(attachments) - set_language_if_valid(Setting.default_language) container = attachments.first.container - url = '' added_to = '' + added_to_url = '' case container.class.name when 'Version' - url = {:only_path => false, :host => Setting.host_name, :controller => 'projects', :action => 'list_files', :id => container.project_id} + added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id) added_to = "#{l(:label_version)}: #{container.name}" when 'Document' - url = {:only_path => false, :host => Setting.host_name, :controller => 'documents', :action => 'show', :id => container.id} + added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) added_to = "#{l(:label_document)}: #{container.title}" end - @recipients = container.project.recipients - @from = Setting.mail_from - @subject = "[#{container.project.name}] #{l(:label_attachment_new)}" - @body['attachments'] = attachments - @body['url'] = url - @body['added_to'] = added_to + recipients container.project.recipients + subject "[#{container.project.name}] #{l(:label_attachment_new)}" + body :attachments => attachments, + :added_to => added_to, + :added_to_url => added_to_url end def news_added(news) - set_language_if_valid(Setting.default_language) - @recipients = news.project.recipients - @from = Setting.mail_from - @subject = "[#{news.project.name}] #{l(:label_news)}: #{news.title}" - @body['news'] = news + recipients news.project.recipients + subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" + body :news => news, + :news_url => url_for(:controller => 'news', :action => 'show', :id => news) end - + + def message_posted(message, recipients) + recipients(recipients) + subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}" + body :message => message, + :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root) + end + + def account_information(user, password) + set_language_if_valid user.language + recipients user.mail + subject l(:mail_subject_register) + body :user => user, + :password => password, + :login_url => url_for(:controller => 'account', :action => 'login') + end + def lost_password(token) set_language_if_valid(token.user.language) - @recipients = token.user.mail - @from = Setting.mail_from - @subject = l(:mail_subject_lost_password) - @body['token'] = token + recipients token.user.mail + subject l(:mail_subject_lost_password) + body :token => token, + :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value) end def register(token) set_language_if_valid(token.user.language) - @recipients = token.user.mail - @from = Setting.mail_from - @subject = l(:mail_subject_register) - @body['token'] = token - end - - def message_posted(message, recipients) - set_language_if_valid(Setting.default_language) - @recipients = recipients - @from = Setting.mail_from - @subject = "[#{message.board.project.name} - #{message.board.name}] #{message.subject}" - @body['message'] = message + recipients token.user.mail + subject l(:mail_subject_register) + body :token => token, + :url => url_for(:controller => 'account', :action => 'register', :token => token.value) end def test(user) set_language_if_valid(user.language) - @recipients = user.mail - @from = Setting.mail_from - @subject = 'Redmine' + recipients user.mail + subject 'Redmine test' + body :url => url_for(:controller => 'welcome') + end + + private + def initialize_defaults(method_name) + super + set_language_if_valid Setting.default_language + from Setting.mail_from + default_url_options[:host] = Setting.host_name + default_url_options[:protocol] = Setting.protocol + end + + # Renders a message with the corresponding layout + def render_message(method_name, body) + layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml' + body[:content_for_layout] = render(:file => method_name, :body => body) + ActionView::Base.new(File.join(template_root, 'mailer'), body, self).render(:file => layout) end end |