Adds a setting to remove incoming emails body after a delimiter (#4409).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3226 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e26eeef837
commit
a54fa93b2e
|
@ -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
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<% 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue