diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index f6be1f1..4ebaa65 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -158,6 +158,24 @@ class MailHandler < ActionMailer::Base end end + # Receives a reply to a forum message + def receive_message_reply(message_id) + message = Message.find_by_id(message_id) + if message + message = message.root + if user.allowed_to?(:add_messages, message.project) && !message.locked? + reply = Message.new(:subject => email.subject, :content => plain_text_body) + reply.author = user + reply.board = message.board + message.children << reply + add_attachments(reply) + reply + else + raise UnauthorizedAction + end + end + end + def add_attachments(obj) if email.has_attachments? email.attachments.each do |attachment| diff --git a/test/fixtures/mail_handler/message_reply.eml b/test/fixtures/mail_handler/message_reply.eml new file mode 100644 index 0000000..a2ef8ee --- /dev/null +++ b/test/fixtures/mail_handler/message_reply.eml @@ -0,0 +1,15 @@ +Message-ID: <4974C93E.3070005@somenet.foo> +Date: Mon, 19 Jan 2009 19:41:02 +0100 +From: "John Smith" +User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) +MIME-Version: 1.0 +To: redmine@somenet.foo +Subject: Reply via email +References: +In-Reply-To: +Content-Type: text/plain; charset=UTF-8; format=flowed +Content-Transfer-Encoding: 7bit + +This is a reply to a forum message. + + diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 0df6442..6a691a2 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -30,7 +30,9 @@ class MailHandlerTest < Test::Unit::TestCase :enumerations, :issue_categories, :custom_fields, - :custom_fields_trackers + :custom_fields_trackers, + :boards, + :messages FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' @@ -141,6 +143,16 @@ class MailHandlerTest < Test::Unit::TestCase assert_equal IssueStatus.find_by_name("Resolved"), issue.status end + def test_reply_to_a_message + m = submit_email('message_reply.eml') + assert m.is_a?(Message) + assert !m.new_record? + m.reload + assert_equal 'Reply via email', m.subject + # The email replies to message #2 which is part of the thread of message #1 + assert_equal Message.find(1), m.parent + end + def test_should_strip_tags_of_html_only_emails issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'}) assert issue.is_a?(Issue)