OSDN Git Service

Accept replies to forum messages by subject recognition (#1616).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 21 Jan 2009 18:22:30 +0000 (18:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 21 Jan 2009 18:22:30 +0000 (18:22 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2294 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
app/models/mailer.rb
test/fixtures/mail_handler/message_reply_by_subject.eml [new file with mode: 0644]
test/unit/mail_handler_test.rb

index 4ebaa65..ea9671f 100644 (file)
@@ -55,6 +55,7 @@ class MailHandler < ActionMailer::Base
 
   MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
   ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
+  MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]+msg(\d+)\]}
   
   def dispatch
     headers = [email.in_reply_to, email.references].flatten.compact
@@ -67,8 +68,9 @@ class MailHandler < ActionMailer::Base
         # ignoring it
       end
     elsif m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
-      # for compatibility
       receive_issue_reply(m[1].to_i)
+    elsif m = email.subject.match(MESSAGE_REPLY_SUBJECT_RE)
+      receive_message_reply(m[1].to_i)
     else
       receive_issue
     end
@@ -164,7 +166,8 @@ class MailHandler < ActionMailer::Base
     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 = Message.new(:subject => email.subject.gsub(%r{^.*msg\d+\]}, '').strip,
+                            :content => plain_text_body)
         reply.author = user
         reply.board = message.board
         message.children << reply
index 0fd7088..c0ff7a8 100644 (file)
@@ -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 (file)
index 0000000..985aaa0
--- /dev/null
@@ -0,0 +1,13 @@
+Message-ID: <4974C93E.3070005@somenet.foo>
+Date: Mon, 19 Jan 2009 19:41:02 +0100
+From: "John Smith" <jsmith@somenet.foo>
+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.
+
+
index 6a691a2..678ba52 100644 (file)
@@ -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)