Commit da3bc45d authored by jplang's avatar jplang
Browse files

Adds a setting to remove incoming emails body after a delimiter (#4409).

git-svn-id: https://svn.redmine.org/redmine/trunk@3226 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 251d1531
......@@ -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
<% form_tag({:action => 'edit', :tab => 'mail_handler'}) do %>
<div class="box tabular settings">
<p>
<%= setting_text_area :mail_handler_body_delimiters, :rows => 5 %>
<br /><em><%= l(:text_line_separated) %></em>
</p>
</div>
<div class="box tabular settings">
<p><%= 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'); }"%></p>
......@@ -12,4 +19,5 @@
</div>
<%= submit_tag l(:button_save) %>
<% end %>
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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}}."
......
......@@ -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
......@@ -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
......@@ -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}}."
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment