diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-23 18:35:19 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-23 18:35:19 +0000 |
commit | a54fa93b2e28c369fde84b714ac8e20d2fa77b5b (patch) | |
tree | 3503d01e163920b9553becebb8f5c675b5a4521a /app/models/mail_handler.rb | |
parent | e26eeef837f15de2d8f139ca838980eaa9de4da0 (diff) | |
download | redmine-a54fa93b2e28c369fde84b714ac8e20d2fa77b5b.tar.gz redmine-a54fa93b2e28c369fde84b714ac8e20d2fa77b5b.zip |
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
Diffstat (limited to 'app/models/mail_handler.rb')
-rw-r--r-- | app/models/mail_handler.rb | 21 |
1 files changed, 18 insertions, 3 deletions
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 |