diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 2ecf3734e..188057573 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -136,7 +136,6 @@ class MailHandler < ActionMailer::Base
if issue.subject.blank?
issue.subject = '(no subject)'
end
- issue.description = plain_text_body
# custom fields
issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c|
if value = get_keyword(c.name, :override => true)
@@ -144,6 +143,7 @@ class MailHandler < ActionMailer::Base
end
h
end
+ issue.description = cleaned_up_text_body
# add To and Cc as watchers before saving so the watchers can reply to Redmine
add_watchers(issue)
issue.save!
@@ -174,7 +174,7 @@ class MailHandler < ActionMailer::Base
end
# add the note
- journal = issue.init_journal(user, plain_text_body)
+ journal = issue.init_journal(user, cleaned_up_text_body)
add_attachments(issue)
# check workflow
if status && issue.new_statuses_allowed_to(user).include?(status)
@@ -205,7 +205,7 @@ class MailHandler < ActionMailer::Base
if !message.locked?
reply = Message.new(:subject => email.subject.gsub(%r{^.*msg\d+\]}, '').strip,
- :content => plain_text_body)
+ :content => cleaned_up_text_body)
reply.author = user
reply.board = message.board
message.children << reply
@@ -276,6 +276,9 @@ class MailHandler < ActionMailer::Base
@plain_text_body
end
+ def cleaned_up_text_body
+ cleanup_body(plain_text_body)
+ end
def self.full_sanitizer
@full_sanitizer ||= HTML::FullSanitizer.new
@@ -299,4 +302,16 @@ class MailHandler < ActionMailer::Base
user.save ? user : nil
end
end
+
+ private
+
+ # Removes the email body of text after the truncation configurations.
+ def cleanup_body(body)
+ delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)}
+ unless delimiters.empty?
+ regex = Regexp.new("^(#{ delimiters.join('|') })\s*$.*", Regexp::MULTILINE)
+ body = body.gsub(regex, '')
+ end
+ body.strip
+ end
end
diff --git a/app/views/settings/_mail_handler.rhtml b/app/views/settings/_mail_handler.rhtml
index 89ea55c5b..f3508ace3 100644
--- a/app/views/settings/_mail_handler.rhtml
+++ b/app/views/settings/_mail_handler.rhtml
@@ -1,5 +1,12 @@
<% form_tag({:action => 'edit', :tab => 'mail_handler'}) do %>
+
+
+ <%= setting_text_area :mail_handler_body_delimiters, :rows => 5 %>
+
<%= l(:text_line_separated) %>
+
+
+
<%= setting_check_box :mail_handler_api_enabled,
:onclick => "if (this.checked) { Form.Element.enable('settings_mail_handler_api_key'); } else { Form.Element.disable('settings_mail_handler_api_key'); }"%>
@@ -12,4 +19,5 @@
<%= submit_tag l(:button_save) %>
+
<% end %>
diff --git a/config/locales/bg.yml b/config/locales/bg.yml
index faf606df3..d70626c9d 100644
--- a/config/locales/bg.yml
+++ b/config/locales/bg.yml
@@ -865,3 +865,5 @@ bg:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/bs.yml b/config/locales/bs.yml
index f8b26d6bf..860d1f254 100644
--- a/config/locales/bs.yml
+++ b/config/locales/bs.yml
@@ -889,3 +889,5 @@ bs:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/ca.yml b/config/locales/ca.yml
index ff857afd0..0f4dbf010 100644
--- a/config/locales/ca.yml
+++ b/config/locales/ca.yml
@@ -868,3 +868,5 @@ ca:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/cs.yml b/config/locales/cs.yml
index ba9386d0d..6165b6d6f 100644
--- a/config/locales/cs.yml
+++ b/config/locales/cs.yml
@@ -871,3 +871,5 @@ cs:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/da.yml b/config/locales/da.yml
index 9c9bc2bb0..7877161e5 100644
--- a/config/locales/da.yml
+++ b/config/locales/da.yml
@@ -891,3 +891,5 @@ da:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/de.yml b/config/locales/de.yml
index b540f3c65..7d1dbcbfe 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -891,3 +891,5 @@ de:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/el.yml b/config/locales/el.yml
index 6674f8187..d4b9616d4 100644
--- a/config/locales/el.yml
+++ b/config/locales/el.yml
@@ -871,3 +871,5 @@ el:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/en.yml b/config/locales/en.yml
index cf42a7b0a..37709072a 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -308,6 +308,7 @@ en:
setting_activity_days_default: Days displayed on project activity
setting_display_subprojects_issues: Display subprojects issues on main projects by default
setting_enabled_scm: Enabled SCM
+ setting_mail_handler_body_delimiters: "Truncate emails after one of these lines"
setting_mail_handler_api_enabled: Enable WS for incoming emails
setting_mail_handler_api_key: API key
setting_sequential_project_identifiers: Generate sequential project identifiers
@@ -812,6 +813,7 @@ en:
text_tracker_no_workflow: No workflow defined for this tracker
text_unallowed_characters: Unallowed characters
text_comma_separated: Multiple values allowed (comma separated).
+ text_line_separated: Multiple values allowed (one line for each value).
text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages
text_issue_added: "Issue {{id}} has been reported by {{author}}."
text_issue_updated: "Issue {{id}} has been updated by {{author}}."
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 79da10c34..4b882884f 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -912,3 +912,5 @@ es:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/fi.yml b/config/locales/fi.yml
index fa03fc5e4..2dcf4574f 100644
--- a/config/locales/fi.yml
+++ b/config/locales/fi.yml
@@ -901,3 +901,5 @@ fi:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index f613b3c30..eb9b382ac 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -330,6 +330,7 @@ fr:
setting_activity_days_default: Nombre de jours affichés sur l'activité des projets
setting_display_subprojects_issues: Afficher par défaut les demandes des sous-projets sur les projets principaux
setting_enabled_scm: SCM activés
+ setting_mail_handler_body_delimiters: "Tronquer les emails après l'une de ces lignes"
setting_mail_handler_api_enabled: "Activer le WS pour la réception d'emails"
setting_mail_handler_api_key: Clé de protection de l'API
setting_sequential_project_identifiers: Générer des identifiants de projet séquentiels
@@ -820,6 +821,7 @@ fr:
text_tracker_no_workflow: Aucun worflow n'est défini pour ce tracker
text_unallowed_characters: Caractères non autorisés
text_comma_separated: Plusieurs valeurs possibles (séparées par des virgules).
+ text_line_separated: Plusieurs valeurs possibles (une valeur par ligne).
text_issues_ref_in_commit_messages: Référencement et résolution des demandes dans les commentaires de commits
text_issue_added: "La demande {{id}} a été soumise par {{author}}."
text_issue_updated: "La demande {{id}} a été mise à jour par {{author}}."
diff --git a/config/locales/gl.yml b/config/locales/gl.yml
index a0d2b0561..90a07f3d9 100644
--- a/config/locales/gl.yml
+++ b/config/locales/gl.yml
@@ -891,3 +891,5 @@ gl:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/he.yml b/config/locales/he.yml
index 1d45621bb..48300414a 100644
--- a/config/locales/he.yml
+++ b/config/locales/he.yml
@@ -875,3 +875,5 @@ he:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/hu.yml b/config/locales/hu.yml
index d4fbb9d0e..bc303fa45 100644
--- a/config/locales/hu.yml
+++ b/config/locales/hu.yml
@@ -896,3 +896,5 @@
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/it.yml b/config/locales/it.yml
index 35b88efb7..b06e00c8f 100644
--- a/config/locales/it.yml
+++ b/config/locales/it.yml
@@ -878,3 +878,5 @@ it:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/ja.yml b/config/locales/ja.yml
index aefb7702a..d2dfb2bee 100644
--- a/config/locales/ja.yml
+++ b/config/locales/ja.yml
@@ -900,3 +900,5 @@ ja:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/ko.yml b/config/locales/ko.yml
index a17bcb65e..78d8a52aa 100644
--- a/config/locales/ko.yml
+++ b/config/locales/ko.yml
@@ -931,3 +931,5 @@ ko:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/lt.yml b/config/locales/lt.yml
index 4c34bf579..9294d2dc5 100644
--- a/config/locales/lt.yml
+++ b/config/locales/lt.yml
@@ -939,3 +939,5 @@ lt:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/nl.yml b/config/locales/nl.yml
index af7c5bdf0..9ee414071 100644
--- a/config/locales/nl.yml
+++ b/config/locales/nl.yml
@@ -853,3 +853,5 @@ nl:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/no.yml b/config/locales/no.yml
index 7eb22a836..f6f9da3a3 100644
--- a/config/locales/no.yml
+++ b/config/locales/no.yml
@@ -866,3 +866,5 @@
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/pl.yml b/config/locales/pl.yml
index 8be9d6fd0..affd8dcee 100644
--- a/config/locales/pl.yml
+++ b/config/locales/pl.yml
@@ -894,3 +894,5 @@ pl:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml
index 63d60d3c4..0fa944c17 100644
--- a/config/locales/pt-BR.yml
+++ b/config/locales/pt-BR.yml
@@ -899,3 +899,5 @@ pt-BR:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/pt.yml b/config/locales/pt.yml
index 0885d323b..0a567a6bc 100644
--- a/config/locales/pt.yml
+++ b/config/locales/pt.yml
@@ -883,3 +883,5 @@ pt:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/ro.yml b/config/locales/ro.yml
index 3cbd65e16..45956a4d8 100644
--- a/config/locales/ro.yml
+++ b/config/locales/ro.yml
@@ -868,3 +868,5 @@ ro:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/ru.yml b/config/locales/ru.yml
index 73196f6ac..51bd8db8e 100644
--- a/config/locales/ru.yml
+++ b/config/locales/ru.yml
@@ -979,3 +979,5 @@ ru:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/sk.yml b/config/locales/sk.yml
index 0289ab86b..e95eefab6 100644
--- a/config/locales/sk.yml
+++ b/config/locales/sk.yml
@@ -870,3 +870,5 @@ sk:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/sl.yml b/config/locales/sl.yml
index 77cea8210..5845ee009 100644
--- a/config/locales/sl.yml
+++ b/config/locales/sl.yml
@@ -867,3 +867,5 @@ sl:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/sr.yml b/config/locales/sr.yml
index d80d05fbd..5cbd59643 100644
--- a/config/locales/sr.yml
+++ b/config/locales/sr.yml
@@ -886,3 +886,5 @@
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/sv.yml b/config/locales/sv.yml
index 7b64b350e..3d7b2e37b 100644
--- a/config/locales/sv.yml
+++ b/config/locales/sv.yml
@@ -920,3 +920,5 @@ sv:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/th.yml b/config/locales/th.yml
index 6bb7e4eaa..07de4c4b6 100644
--- a/config/locales/th.yml
+++ b/config/locales/th.yml
@@ -868,3 +868,5 @@ th:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/tr.yml b/config/locales/tr.yml
index 7c04da805..056cb5656 100644
--- a/config/locales/tr.yml
+++ b/config/locales/tr.yml
@@ -898,3 +898,5 @@ tr:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/uk.yml b/config/locales/uk.yml
index 599099c1a..f5b83b241 100644
--- a/config/locales/uk.yml
+++ b/config/locales/uk.yml
@@ -867,3 +867,5 @@ uk:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/vi.yml b/config/locales/vi.yml
index dc5add3eb..50ac2d8b9 100644
--- a/config/locales/vi.yml
+++ b/config/locales/vi.yml
@@ -930,3 +930,5 @@ vi:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml
index 5fa4f5213..471029cb6 100644
--- a/config/locales/zh-TW.yml
+++ b/config/locales/zh-TW.yml
@@ -964,3 +964,5 @@
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index c909282f2..883c4bb5e 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -895,3 +895,5 @@ zh:
label_missing_api_access_key: Missing an API access key
label_missing_feeds_access_key: Missing a RSS access key
button_show: Show
+ text_line_separated: Multiple values allowed (one line for each value).
+ setting_mail_handler_body_delimiters: Truncate emails after one of these lines
diff --git a/config/settings.yml b/config/settings.yml
index 09bce1f20..cebfbb500 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -116,6 +116,8 @@ notified_events:
default:
- issue_added
- issue_updated
+mail_handler_body_delimiters:
+ default: ''
mail_handler_api_enabled:
default: 0
mail_handler_api_key:
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index f5e4e8278..64741d7ad 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -370,6 +370,7 @@ input#time_entry_comments { width: 90%;}
.tabular.settings p{ padding-left: 300px; }
.tabular.settings label{ margin-left: -300px; width: 295px; }
+.tabular.settings textarea { width: 99%; }
fieldset.settings label { display: block; }
diff --git a/test/fixtures/mail_handler/ticket_on_given_project.eml b/test/fixtures/mail_handler/ticket_on_given_project.eml
index 5dbd0dc2e..372e7302c 100644
--- a/test/fixtures/mail_handler/ticket_on_given_project.eml
+++ b/test/fixtures/mail_handler/ticket_on_given_project.eml
@@ -26,10 +26,22 @@ in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras
sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum
id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus
eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique
-sed, mauris. Pellentesque habitant morbi tristique senectus et netus et
+sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse
platea dictumst.
+--- This line starts with a delimiter and should not be stripped
+
+This paragraph is before delimiters.
+
+BREAK
+
+This paragraph is between delimiters.
+
+---
+
+This paragraph is after the delimiter so it shouldn't appear.
+
Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque
sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem.
Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et,
diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb
index a4ae37345..21d2aedd5 100644
--- a/test/unit/mail_handler_test.rb
+++ b/test/unit/mail_handler_test.rb
@@ -279,10 +279,62 @@ class MailHandlerTest < ActiveSupport::TestCase
assert_equal 'This is a html-only email.', issue.description
end
+ context "truncate emails based on the Setting" do
+ context "with no setting" do
+ setup do
+ Setting.mail_handler_body_delimiters = ''
+ end
+
+ should "add the entire email into the issue" do
+ issue = submit_email('ticket_on_given_project.eml')
+ assert_issue_created(issue)
+ assert issue.description.include?('---')
+ assert issue.description.include?('This paragraph is after the delimiter')
+ end
+ end
+
+ context "with a single string" do
+ setup do
+ Setting.mail_handler_body_delimiters = '---'
+ end
+
+ should "truncate the email at the delimiter for the issue" do
+ issue = submit_email('ticket_on_given_project.eml')
+ assert_issue_created(issue)
+ assert issue.description.include?('This paragraph is before delimiters')
+ assert issue.description.include?('--- This line starts with a delimiter')
+ assert !issue.description.match(/^---$/)
+ assert !issue.description.include?('This paragraph is after the delimiter')
+ end
+ end
+
+ context "with multiple strings" do
+ setup do
+ Setting.mail_handler_body_delimiters = "---\nBREAK"
+ end
+
+ should "truncate the email at the first delimiter found (BREAK)" do
+ issue = submit_email('ticket_on_given_project.eml')
+ assert_issue_created(issue)
+ assert issue.description.include?('This paragraph is before delimiters')
+ assert !issue.description.include?('BREAK')
+ assert !issue.description.include?('This paragraph is between delimiters')
+ assert !issue.description.match(/^---$/)
+ assert !issue.description.include?('This paragraph is after the delimiter')
+ end
+ end
+ end
+
private
def submit_email(filename, options={})
raw = IO.read(File.join(FIXTURES_PATH, filename))
MailHandler.receive(raw, options)
end
+
+ def assert_issue_created(issue)
+ assert issue.is_a?(Issue)
+ assert !issue.new_record?
+ issue.reload
+ end
end