diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-12-13 18:46:29 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-12-13 18:46:29 +0000 |
commit | f30462595e83f512cd5f29246a4542773595a224 (patch) | |
tree | 56eb7ce08ea5a8c6e0c21806e067c8c652e652b9 /test | |
parent | 3186130966cea85d842faf5c038006f8fb40bb61 (diff) | |
download | redmine-f30462595e83f512cd5f29246a4542773595a224.tar.gz redmine-f30462595e83f512cd5f29246a4542773595a224.zip |
Optional Regex delimiters to truncate incoming emails (#5864).
git-svn-id: http://svn.redmine.org/redmine/trunk@16065 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/mail_handler/ticket_reply_from_mail.eml | 35 | ||||
-rw-r--r-- | test/functional/settings_controller_test.rb | 29 | ||||
-rw-r--r-- | test/unit/mail_handler_test.rb | 19 |
3 files changed, 83 insertions, 0 deletions
diff --git a/test/fixtures/mail_handler/ticket_reply_from_mail.eml b/test/fixtures/mail_handler/ticket_reply_from_mail.eml new file mode 100644 index 000000000..016b189f1 --- /dev/null +++ b/test/fixtures/mail_handler/ticket_reply_from_mail.eml @@ -0,0 +1,35 @@ +Return-Path: <jsmith@somenet.foo> +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer; Wed, 12 Oct 2016 03:05:50 -0700 +Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> +From: "John Smith" <JSmith@somenet.foo> +To: <redmine@somenet.foo> +Subject: New ticket on a given project +Date: Wed, 12 Oct 2016 13:05:38 +0300 +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 + +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 +remaining hours: 1 +done ratio: 30 + +This paragraph is before delimiter + +On Wed, 11 Oct at 1:05 PM, Jon Smith <jsmith@somenet.foo<mailto:jsmith@somenet.foo>> wrote: + +This paragraph is after the delimiter diff --git a/test/functional/settings_controller_test.rb b/test/functional/settings_controller_test.rb index 38e569569..d7dacc0ee 100644 --- a/test/functional/settings_controller_test.rb +++ b/test/functional/settings_controller_test.rb @@ -254,4 +254,33 @@ class SettingsControllerTest < Redmine::ControllerTest ensure Redmine::Plugin.unregister(:foo) end + + def test_post_mail_handler_delimiters_should_not_save_invalid_regex_delimiters + post :edit, :params => { + :settings => { + :mail_handler_enable_regex_delimiters => '1', + :mail_handler_body_delimiters => 'Abc[', + } + } + + assert_response :success + assert_equal '0', Setting.mail_handler_enable_regex_delimiters + assert_equal '', Setting.mail_handler_body_delimiters + + assert_select_error /is not a valid regular expression/ + assert_select 'textarea[name=?]', 'settings[mail_handler_body_delimiters]', :text => 'Abc[' + end + + def test_post_mail_handler_delimiters_should_save_valid_regex_delimiters + post :edit, :params => { + :settings => { + :mail_handler_enable_regex_delimiters => '1', + :mail_handler_body_delimiters => 'On .*, .* at .*, .* <.*<mailto:.*>> wrote:', + } + } + + assert_redirected_to '/settings' + assert_equal '1', Setting.mail_handler_enable_regex_delimiters + assert_equal 'On .*, .* at .*, .* <.*<mailto:.*>> wrote:', Setting.mail_handler_body_delimiters + end end diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index c1afdaebd..898ccc918 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -977,6 +977,25 @@ class MailHandlerTest < ActiveSupport::TestCase end end + test "truncate emails using a regex delimiter" do + delimiter = "On .*, .* at .*, .* <.*<mailto:.*>> wrote:" + with_settings :mail_handler_enable_regex_delimiters => '1', :mail_handler_body_delimiters => delimiter do + issue = submit_email('ticket_reply_from_mail.eml') + assert_issue_created(issue) + assert issue.description.include?('This paragraph is before delimiter') + assert !issue.description.include?('On Wed, 11 Oct at 1:05 PM, Jon Smith <jsmith@somenet.foo<mailto:jsmith@somenet.foo>> wrote:') + assert !issue.description.include?('This paragraph is after the delimiter') + end + + with_settings :mail_handler_enable_regex_delimiters => '0', :mail_handler_body_delimiters => delimiter do + issue = submit_email('ticket_reply_from_mail.eml') + assert_issue_created(issue) + assert issue.description.include?('This paragraph is before delimiter') + assert issue.description.include?('On Wed, 11 Oct at 1:05 PM, Jon Smith <jsmith@somenet.foo<mailto:jsmith@somenet.foo>> wrote:') + assert issue.description.include?('This paragraph is after the delimiter') + end + end + def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored with_settings :mail_handler_excluded_filenames => '*.vcf, *.jpg' do issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) |