Import custom fields values from emails (#2413).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2211 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
2355324d73
commit
421539e3be
|
@ -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]
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue