diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index fb30374bd..864609ce0 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -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 diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 013da992e..3244d8cd2 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -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(