From dfab202cdec1e4cba0c10281142090c74ccabaf8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 21 Jan 2009 18:22:30 +0000 Subject: [PATCH] Accept replies to forum messages by subject recognition (#1616). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2294 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mail_handler.rb | 7 +++++-- app/models/mailer.rb | 2 +- .../mail_handler/message_reply_by_subject.eml | 13 +++++++++++++ test/unit/mail_handler_test.rb | 9 +++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/mail_handler/message_reply_by_subject.eml diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 4ebaa6505..ea9671ff6 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -55,6 +55,7 @@ class MailHandler < ActionMailer::Base MESSAGE_ID_RE = %r{^ email.subject, :content => plain_text_body) + reply = Message.new(:subject => email.subject.gsub(%r{^.*msg\d+\]}, '').strip, + :content => plain_text_body) reply.author = user reply.board = message.board message.children << reply diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 0fd708879..c0ff7a8c8 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -111,7 +111,7 @@ class Mailer < ActionMailer::Base message_id message references message.parent unless message.parent.nil? recipients(recipients) - subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}" + subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" body :message => message, :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root) end diff --git a/test/fixtures/mail_handler/message_reply_by_subject.eml b/test/fixtures/mail_handler/message_reply_by_subject.eml new file mode 100644 index 000000000..985aaa0e4 --- /dev/null +++ b/test/fixtures/mail_handler/message_reply_by_subject.eml @@ -0,0 +1,13 @@ +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: Re: [eCookbook - Help board - msg2] Reply to the first post +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 6a691a237..678ba520f 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -153,6 +153,15 @@ class MailHandlerTest < Test::Unit::TestCase assert_equal Message.find(1), m.parent end + def test_reply_to_a_message_by_subject + m = submit_email('message_reply_by_subject.eml') + assert m.is_a?(Message) + assert !m.new_record? + m.reload + assert_equal 'Reply to the first post', m.subject + 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)