OSDN Git Service

Allow email to reply to a forum message (#1616).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 19 Jan 2009 19:03:53 +0000 (19:03 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 19 Jan 2009 19:03:53 +0000 (19:03 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2289 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index f6be1f1..4ebaa65 100644 (file)
@@ -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 (file)
index 0000000..a2ef8ee
--- /dev/null
@@ -0,0 +1,15 @@
+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: Reply via email
+References: <redmine.message-2.20070512171800@somenet.foo>
+In-Reply-To: <redmine.message-2.20070512171800@somenet.foo>
+Content-Type: text/plain; charset=UTF-8; format=flowed
+Content-Transfer-Encoding: 7bit
+
+This is a reply to a forum message.
+
+
index 0df6442..6a691a2 100644 (file)
@@ -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)