From a4b07a36edb567948739324b515abc5b7c28b241 Mon Sep 17 00:00:00 2001 From: Nicolas Chuche Date: Wed, 15 Oct 2008 23:50:33 +0000 Subject: [PATCH] add plain text option for mail #2029 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@1932 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mailer.rb | 15 +++++++++++++++ app/views/settings/_notifications.rhtml | 4 ++++ config/settings.yml | 2 ++ lang/bg.yml | 1 + lang/ca.yml | 1 + lang/cs.yml | 1 + lang/da.yml | 1 + lang/de.yml | 1 + lang/en.yml | 1 + lang/es.yml | 1 + lang/fi.yml | 1 + lang/fr.yml | 1 + lang/he.yml | 1 + lang/hu.yml | 1 + lang/it.yml | 1 + lang/ja.yml | 1 + lang/ko.yml | 1 + lang/lt.yml | 1 + lang/nl.yml | 3 ++- lang/no.yml | 1 + lang/pl.yml | 1 + lang/pt-br.yml | 1 + lang/pt.yml | 1 + lang/ro.yml | 1 + lang/ru.yml | 1 + lang/sr.yml | 1 + lang/sv.yml | 1 + lang/th.yml | 1 + lang/tr.yml | 1 + lang/uk.yml | 1 + lang/zh-tw.yml | 1 + lang/zh.yml | 1 + test/unit/mailer_test.rb | 12 +++++++++++- 33 files changed, 62 insertions(+), 2 deletions(-) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index a2d9ddba5..60a5a827d 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -219,6 +219,21 @@ class Mailer < ActionMailer::Base body[:content_for_layout] = render(:file => method_name, :body => body) ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true) end + + # for the case of plain text only + def body(*params) + value = super(*params) + if Setting.plain_text_mail? + templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}") + unless String === @body or templates.empty? + template = File.basename(templates.first) + @body[:content_for_layout] = render(:file => template, :body => @body) + @body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true) + return @body + end + end + return value + end # Makes partial rendering work with Rails 1.2 (retro-compatibility) def self.controller_path diff --git a/app/views/settings/_notifications.rhtml b/app/views/settings/_notifications.rhtml index 36701463a..a9a5f4742 100644 --- a/app/views/settings/_notifications.rhtml +++ b/app/views/settings/_notifications.rhtml @@ -8,6 +8,10 @@

<%= check_box_tag 'settings[bcc_recipients]', 1, Setting.bcc_recipients? %> <%= hidden_field_tag 'settings[bcc_recipients]', 0 %>

+ +

+<%= check_box_tag 'settings[plain_text_mail]', 1, Setting.plain_text_mail? %> +<%= hidden_field_tag 'settings[plain_text_mail]', 0 %>

<%=l(:text_select_mail_notifications)%> diff --git a/config/settings.yml b/config/settings.yml index e1ad341de..7d6a9d1df 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -46,6 +46,8 @@ mail_from: default: redmine@example.net bcc_recipients: default: 1 +plain_text_mail: + default: 0 text_formatting: default: textile wiki_compression: diff --git a/lang/bg.yml b/lang/bg.yml index f8d2e5e2c..b6aa4774b 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -640,3 +640,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/ca.yml b/lang/ca.yml index 40ba5feae..f4d185c5d 100644 --- a/lang/ca.yml +++ b/lang/ca.yml @@ -641,3 +641,4 @@ default_activity_development: Desenvolupament enumeration_issue_priorities: Prioritat dels assumptes enumeration_doc_categories: Categories del document enumeration_activities: Activitats (seguidor de temps) +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/cs.yml b/lang/cs.yml index cf2cb0992..dcf778f01 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -645,3 +645,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/da.yml b/lang/da.yml index 0ee1b2512..21bfb3a01 100644 --- a/lang/da.yml +++ b/lang/da.yml @@ -641,3 +641,4 @@ default_activity_development: Udvikling enumeration_issue_priorities: Sagsprioriteter enumeration_doc_categories: Dokumentkategorier enumeration_activities: Aktiviteter (tidsregistrering) +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/de.yml b/lang/de.yml index 7aa2d971b..5041a31b4 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -641,3 +641,4 @@ default_activity_development: Entwicklung enumeration_issue_priorities: Ticket-Prioritäten enumeration_doc_categories: Dokumentenkategorien enumeration_activities: Aktivitäten (Zeiterfassung) +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/en.yml b/lang/en.yml index 8a73a3992..5c7e30c21 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -195,6 +195,7 @@ setting_attachment_max_size: Attachment max. size setting_issues_export_limit: Issues export limit setting_mail_from: Emission email address setting_bcc_recipients: Blind carbon copy recipients (bcc) +setting_plain_text_mail: plain text mail (no HTML) setting_host_name: Host name setting_text_formatting: Text formatting setting_wiki_compression: Wiki history compression diff --git a/lang/es.yml b/lang/es.yml index ae367d842..70b09f769 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -643,3 +643,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/fi.yml b/lang/fi.yml index 225563b37..ce7a3e068 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -640,3 +640,4 @@ setting_commit_logs_encoding: Commit messages encoding notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/fr.yml b/lang/fr.yml index b64078068..b81c6d3cc 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -641,3 +641,4 @@ enumeration_issue_priorities: Priorités des demandes enumeration_doc_categories: Catégories des documents enumeration_activities: Activités (suivi du temps) notice_unable_delete_version: Unable to delete version +setting_plain_text_mail: mail texte brut (non HTML) diff --git a/lang/he.yml b/lang/he.yml index 07962d2de..e43733651 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -640,3 +640,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/hu.yml b/lang/hu.yml index 3a3d18a12..c1fcdd2b8 100644 --- a/lang/hu.yml +++ b/lang/hu.yml @@ -641,3 +641,4 @@ setting_sequential_project_identifiers: Szekvenciális projekt azonosítók gene notice_unable_delete_version: A verziót nem lehet törölni label_renamed: átnevezve label_copied: lemásolva +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/it.yml b/lang/it.yml index bca755605..4e40fa085 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -640,3 +640,4 @@ setting_sequential_project_identifiers: Genera progetti con identificativi in se notice_unable_delete_version: Impossibile cancellare la versione label_renamed: rinominato label_copied: copiato +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/ja.yml b/lang/ja.yml index 4e46212b2..165aabd3d 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -552,6 +552,7 @@ notice_account_pending: アカウントは作成済みで、管理者の承認 field_time_zone: タイムゾーン text_caracters_minimum: 最低%d文字の長さが必要です setting_bcc_recipients: ブラインドカーボンコピーで受信(bcc) +setting_plain_text_mail: プレインテキストのみ(HTMLなし) button_annotate: 注釈 label_issues_by: %s別のチケット field_searchable: Searchable diff --git a/lang/ko.yml b/lang/ko.yml index 95aa8716d..fae3345a1 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -640,3 +640,4 @@ setting_sequential_project_identifiers: 프로젝트 실별자를 순자적으 notice_unable_delete_version: 삭제 할 수 없는 버전 입니다. label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/lt.yml b/lang/lt.yml index f29c28c4f..a92b2f007 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -642,3 +642,4 @@ button_quote: Cituoti notice_unable_delete_version: Neimanoma panaikinti versiją label_renamed: pervardintas label_copied: nukopijuotas +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/nl.yml b/lang/nl.yml index 19d845002..ee96aa7f7 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -641,4 +641,5 @@ button_quote: Citaat setting_sequential_project_identifiers: Genereer sequentiële projectidentiteiten notice_unable_delete_version: Niet mogelijk om deze versie te verwijderen. label_renamed: hernoemd -label_copied: gekopieerd \ No newline at end of file +label_copied: gekopieerd +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/no.yml b/lang/no.yml index 8cd6952c6..4005f0683 100644 --- a/lang/no.yml +++ b/lang/no.yml @@ -641,3 +641,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/pl.yml b/lang/pl.yml index ee9bbaaaf..45624771e 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -646,3 +646,4 @@ label_renamed: przemianowano label_copied: skopiowano field_vf_watcher: Obserwator field_vf_personnel: Personel +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 7c07729fe..5dea29a20 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -641,3 +641,4 @@ enumeration_activities: Atividades (time tracking) notice_unable_delete_version: Não foi possível excluir a versão label_renamed: renomeado label_copied: copiado +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/pt.yml b/lang/pt.yml index 1cf9f3a10..e9f91b7fa 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -642,3 +642,4 @@ default_activity_development: Desenvolvimento enumeration_issue_priorities: Prioridade de tarefas enumeration_doc_categories: Categorias de documentos enumeration_activities: Actividades (Contagem de tempo) +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/ro.yml b/lang/ro.yml index 94278256e..2aabe6715 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -640,3 +640,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/ru.yml b/lang/ru.yml index ce5e43b7d..70149283f 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -673,3 +673,4 @@ text_user_wrote: '%s написал(а):' text_wiki_destroy_confirmation: Вы уверены, что хотите удалить данную Wiki и все содержимое? text_workflow_edit: Выберите роль и трекер для редактирования последовательности состояний +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/sr.yml b/lang/sr.yml index 720dfcdff..5de1c6953 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -641,3 +641,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/sv.yml b/lang/sv.yml index 393ade818..8cd2eb7e5 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -641,3 +641,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/th.yml b/lang/th.yml index 362e44756..b0f51e8ef 100644 --- a/lang/th.yml +++ b/lang/th.yml @@ -643,3 +643,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/tr.yml b/lang/tr.yml index ba9c0b41b..7661e24ff 100644 --- a/lang/tr.yml +++ b/lang/tr.yml @@ -641,3 +641,4 @@ general_csv_decimal_separator: '.' notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/uk.yml b/lang/uk.yml index de5f65eb0..074aa9a82 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -642,3 +642,4 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index 6feb0a0e8..749433637 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -641,3 +641,4 @@ default_activity_development: 開發 enumeration_issue_priorities: 項目優先權 enumeration_doc_categories: 文件分類 enumeration_activities: 活動 (時間追蹤) +setting_plain_text_mail: plain text only (no HTML) diff --git a/lang/zh.yml b/lang/zh.yml index d2e571b4d..fd752eec7 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -641,3 +641,4 @@ default_activity_development: 开发 enumeration_issue_priorities: 问题优先级 enumeration_doc_categories: 文档类别 enumeration_activities: 活动(时间跟踪) +setting_plain_text_mail: plain text only (no HTML) diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 1c03bafb3..e3a21a576 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -32,12 +32,22 @@ class MailerTest < Test::Unit::TestCase assert_kind_of TMail::Mail, mail # link to the main ticket assert mail.body.include?('Bug #1: Can\'t print recipes') - + # link to a referenced ticket assert mail.body.include?('#2') # link to a changeset assert mail.body.include?('r2') end + + def test_plain_text_mail + Setting.plain_text_mail = 1 + journal = Journal.find(2) + Mailer.deliver_issue_edit(journal) + mail = ActionMailer::Base.deliveries.last + assert !mail.body.include?('Bug #1: Can\'t print recipes') + end + + # test mailer methods for each language def test_issue_add -- 2.39.5