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)
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!
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)
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
@plain_text_body
end
+ def cleaned_up_text_body
+ cleanup_body(plain_text_body)
+ end
def self.full_sanitizer
@full_sanitizer ||= HTML::FullSanitizer.new
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>
</div>
<%= submit_tag l(:button_save) %>
+
<% end %>
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
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
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
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
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
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
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
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
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}}."
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
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
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
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}}."
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
default:
- issue_added
- issue_updated
+mail_handler_body_delimiters:
+ default: ''
mail_handler_api_enabled:
default: 0
mail_handler_api_key:
.tabular.settings p{ padding-left: 300px; }
.tabular.settings label{ margin-left: -300px; width: 295px; }
+.tabular.settings textarea { width: 99%; }
fieldset.settings label { display: block; }
sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum \r
id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus \r
eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique \r
-sed, mauris. Pellentesque habitant morbi tristique senectus et netus et \r
+sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et \r
malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse \r
platea dictumst.\r
\r
+--- This line starts with a delimiter and should not be stripped\r
+\r
+This paragraph is before delimiters.\r
+\r
+BREAK\r
+\r
+This paragraph is between delimiters.\r
+\r
+---\r
+\r
+This paragraph is after the delimiter so it shouldn't appear.\r
+\r
Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque \r
sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem. \r
Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et, \r
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