]> source.dussan.org Git - redmine.git/commitdiff
Use the default project when receiving an email with an invalid project keyword ...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 29 Jul 2013 16:37:45 +0000 (16:37 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 29 Jul 2013 16:37:45 +0000 (16:37 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12067 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
test/unit/mail_handler_test.rb

index fb30374bd7c9f437d6aeb3b52972bfbe1a56273c..864609ce0addde23710660309fdc0fd2d7de198a 100644 (file)
@@ -28,6 +28,7 @@ class MailHandler < ActionMailer::Base
     @@handler_options = options.dup
 
     @@handler_options[:issue] ||= {}
+    @@handler_options[:issue].symbolize_keys!
 
     if @@handler_options[:allow_override].is_a?(String)
       @@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip)
@@ -333,6 +334,13 @@ class MailHandler < ActionMailer::Base
     # * parse the email To field
     # * specific project (eg. Setting.mail_handler_target_project)
     target = Project.find_by_identifier(get_keyword(:project))
+    if target.nil?
+      # Invalid project keyword, use the project specified as the default one
+      default_project = @@handler_options[:issue][:project]
+      if default_project.present?
+        target = Project.find_by_identifier(default_project)
+      end
+    end
     raise MissingInformation.new('Unable to determine target project') if target.nil?
     target
   end
index 013da992ecebd396cf8a5fadd3865c21c031bebc..3244d8cd23d3bd764f12ebecb3fba1c7bda759c5 100644 (file)
@@ -370,6 +370,15 @@ class MailHandlerTest < ActiveSupport::TestCase
     assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
   end
 
+  def test_add_issue_with_invalid_project_should_be_assigned_to_default_project
+    issue = submit_email('ticket_on_given_project.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'project') do |email|
+      email.gsub!(/^Project:.+$/, 'Project: invalid')
+    end
+    assert issue.is_a?(Issue)
+    assert !issue.new_record?
+    assert_equal 'ecookbook', issue.project.identifier
+  end
+
   def test_add_issue_with_localized_attributes
     User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
     issue = submit_email(