summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-12-30 14:57:33 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-12-30 14:57:33 +0000
commit421539e3be392d6ecd0e4fc252e8d76662ee2a81 (patch)
treef6a6d6fbffd8b47182d228ca01ee8fd86f1877dc
parent2355324d73e26f224e2b13b21249f181314b289f (diff)
downloadredmine-421539e3be392d6ecd0e4fc252e8d76662ee2a81.tar.gz
redmine-421539e3be392d6ecd0e4fc252e8d76662ee2a81.zip
Import custom fields values from emails (#2413).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2211 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/mail_handler.rb11
-rw-r--r--test/fixtures/mail_handler/ticket_with_custom_fields.eml41
-rw-r--r--test/unit/mail_handler_test.rb13
3 files changed, 62 insertions, 3 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index d7fbfbaf1..2f9adec73 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -90,6 +90,13 @@ class MailHandler < ActionMailer::Base
end
issue.subject = email.subject.chomp.toutf8
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)
+ h[c.id] = value
+ end
+ h
+ end
issue.save!
add_attachments(issue)
logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
@@ -155,8 +162,8 @@ class MailHandler < ActionMailer::Base
end
end
- def get_keyword(attr)
- if @@handler_options[:allow_override].include?(attr.to_s) && plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i
+ def get_keyword(attr, options={})
+ if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i
$1.strip
elsif !@@handler_options[:issue][attr].blank?
@@handler_options[:issue][attr]
diff --git a/test/fixtures/mail_handler/ticket_with_custom_fields.eml b/test/fixtures/mail_handler/ticket_with_custom_fields.eml
new file mode 100644
index 000000000..f3798a4b6
--- /dev/null
+++ b/test/fixtures/mail_handler/ticket_with_custom_fields.eml
@@ -0,0 +1,41 @@
+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 with custom field values
+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. Maecenas imperdiet
+turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus
+blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti
+sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In
+in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras
+sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum
+id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus
+eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique
+sed, mauris. Pellentesque habitant morbi tristique senectus et netus et
+malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse
+platea dictumst.
+
+Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque
+sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem.
+Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et,
+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.
+
+category: Stock management
+searchable field: Value for a custom field
diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb
index 80f70a417..0df64425b 100644
--- a/test/unit/mail_handler_test.rb
+++ b/test/unit/mail_handler_test.rb
@@ -28,7 +28,9 @@ class MailHandlerTest < Test::Unit::TestCase
:trackers,
:projects_trackers,
:enumerations,
- :issue_categories
+ :issue_categories,
+ :custom_fields,
+ :custom_fields_trackers
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
@@ -102,6 +104,15 @@ class MailHandlerTest < Test::Unit::TestCase
assert_equal 10790, issue.attachments.first.filesize
end
+ def test_add_issue_with_custom_fields
+ issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
+ assert issue.is_a?(Issue)
+ assert !issue.new_record?
+ issue.reload
+ assert_equal 'New ticket with custom field values', issue.subject
+ assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
+ end
+
def test_add_issue_with_cc
issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
assert issue.is_a?(Issue)