summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-09-20 07:51:37 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-09-20 07:51:37 +0000
commit8ae41b4846fc46cb521599c0b10fad8e424069f7 (patch)
tree318731e4cc94522ffcafc13500d13a27a9417b7b
parentb519aba63ee0043ffd60f9002fc236f717d9f172 (diff)
downloadredmine-8ae41b4846fc46cb521599c0b10fad8e424069f7.tar.gz
redmine-8ae41b4846fc46cb521599c0b10fad8e424069f7.zip
Ignore email keywords after truncation line (#8758).
git-svn-id: http://svn.redmine.org/redmine/trunk@13413 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/mail_handler.rb6
-rw-r--r--test/fixtures/mail_handler/ticket_on_given_project.eml18
-rw-r--r--test/fixtures/mail_handler/ticket_with_duplicate_keyword.eml25
-rw-r--r--test/fixtures/mail_handler/ticket_with_keyword_after_delimiter.eml27
-rw-r--r--test/unit/mail_handler_test.rb14
5 files changed, 78 insertions, 12 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 69e70d21d..dab7a1a82 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -319,7 +319,7 @@ class MailHandler < ActionMailer::Base
else
@keywords[attr] = begin
if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) &&
- (v = extract_keyword!(plain_text_body, attr, options[:format]))
+ (v = extract_keyword!(cleaned_up_text_body, attr, options[:format]))
v
elsif !@@handler_options[:issue][attr].blank?
@@handler_options[:issue][attr]
@@ -347,7 +347,7 @@ class MailHandler < ActionMailer::Base
regexp = /^(#{keys.join('|')})[ \t]*:[ \t]*(#{format})\s*$/i
if m = text.match(regexp)
keyword = m[2].strip
- text.gsub!(regexp, '')
+ text.sub!(regexp, '')
end
keyword
end
@@ -436,7 +436,7 @@ class MailHandler < ActionMailer::Base
end
def cleaned_up_text_body
- cleanup_body(plain_text_body)
+ @cleaned_up_text_body ||= cleanup_body(plain_text_body)
end
def cleaned_up_subject
diff --git a/test/fixtures/mail_handler/ticket_on_given_project.eml b/test/fixtures/mail_handler/ticket_on_given_project.eml
index 5e6d9113e..7c0fe3208 100644
--- a/test/fixtures/mail_handler/ticket_on_given_project.eml
+++ b/test/fixtures/mail_handler/ticket_on_given_project.eml
@@ -30,6 +30,15 @@ sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse
platea dictumst.
+Project: onlinestore
+Status: Resolved
+due date: 2010-12-31
+Start Date:2010-01-01
+Assigned to: John Smith
+fixed version: alpha
+estimated hours: 2.5
+done ratio: 30
+
--- This line starts with a delimiter and should not be stripped
This paragraph is before delimiters.
@@ -49,12 +58,3 @@ dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed,
massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo
pulvinar dui, a gravida orci mi eget odio. Nunc a lacus.
-Project: onlinestore
-Status: Resolved
-due date: 2010-12-31
-Start Date:2010-01-01
-Assigned to: John Smith
-fixed version: alpha
-estimated hours: 2.5
-done ratio: 30
-
diff --git a/test/fixtures/mail_handler/ticket_with_duplicate_keyword.eml b/test/fixtures/mail_handler/ticket_with_duplicate_keyword.eml
new file mode 100644
index 000000000..e70c27722
--- /dev/null
+++ b/test/fixtures/mail_handler/ticket_with_duplicate_keyword.eml
@@ -0,0 +1,25 @@
+Return-Path: <JSmith@somenet.foo>
+Received: from osiris ([127.0.0.1])
+ by OSIRIS
+ with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
+Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
+From: "John Smith" <JSmith@somenet.foo>
+To: <redmine@somenet.foo>
+Subject: New ticket on a given project
+Date: Sun, 22 Jun 2008 12:28:07 +0200
+MIME-Version: 1.0
+Content-Type: text/plain;
+ format=flowed;
+ charset="iso-8859-1";
+ reply-type=original
+Content-Transfer-Encoding: 7bit
+X-Priority: 3
+X-MSMail-Priority: Normal
+X-Mailer: Microsoft Outlook Express 6.00.2900.2869
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
+
+Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
+
+Project: ecookbook
+Priority: High
+Priority: Low
diff --git a/test/fixtures/mail_handler/ticket_with_keyword_after_delimiter.eml b/test/fixtures/mail_handler/ticket_with_keyword_after_delimiter.eml
new file mode 100644
index 000000000..736ea5dec
--- /dev/null
+++ b/test/fixtures/mail_handler/ticket_with_keyword_after_delimiter.eml
@@ -0,0 +1,27 @@
+Return-Path: <JSmith@somenet.foo>
+Received: from osiris ([127.0.0.1])
+ by OSIRIS
+ with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
+Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
+From: "John Smith" <JSmith@somenet.foo>
+To: <redmine@somenet.foo>
+Subject: New ticket on a given project
+Date: Sun, 22 Jun 2008 12:28:07 +0200
+MIME-Version: 1.0
+Content-Type: text/plain;
+ format=flowed;
+ charset="iso-8859-1";
+ reply-type=original
+Content-Transfer-Encoding: 7bit
+X-Priority: 3
+X-MSMail-Priority: Normal
+X-Mailer: Microsoft Outlook Express 6.00.2900.2869
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
+
+Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
+
+Project: ecookbook
+
+== DELIMITER ==
+
+Priority: High
diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb
index 6c3aefc41..1a3469031 100644
--- a/test/unit/mail_handler_test.rb
+++ b/test/unit/mail_handler_test.rb
@@ -856,6 +856,20 @@ class MailHandlerTest < ActiveSupport::TestCase
assert_equal issue.subject, 'New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...'[0,255]
end
+ def test_first_keyword_should_be_matched
+ issue = submit_email('ticket_with_duplicate_keyword.eml', :allow_override => 'priority')
+ assert issue.is_a?(Issue)
+ assert_equal 'High', issue.priority.name
+ end
+
+ def test_keyword_after_delimiter_should_be_ignored
+ with_settings :mail_handler_body_delimiters => "== DELIMITER ==" do
+ issue = submit_email('ticket_with_keyword_after_delimiter.eml', :allow_override => 'priority')
+ assert issue.is_a?(Issue)
+ assert_equal 'Normal', issue.priority.name
+ end
+ end
+
def test_new_user_from_attributes_should_return_valid_user
to_test = {
# [address, name] => [login, firstname, lastname]