]> source.dussan.org Git - redmine.git/commitdiff
Use In-Reply-To and References headers to handle replies by email.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 19 Jan 2009 18:29:07 +0000 (18:29 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 19 Jan 2009 18:29:07 +0000 (18:29 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2288 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
test/fixtures/mail_handler/ticket_reply.eml

index 2f9adec7397e2d687970bfdd50be67bc6647c16a..f6be1f12438617cc664011af219f3978b5ec4497 100644 (file)
@@ -53,11 +53,22 @@ class MailHandler < ActionMailer::Base
   
   private
 
+  MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
   ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
   
   def dispatch
-    if m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
-      receive_issue_update(m[1].to_i)
+    headers = [email.in_reply_to, email.references].flatten.compact
+    if headers.detect {|h| h.to_s =~ MESSAGE_ID_RE}
+      klass, object_id = $1, $2.to_i
+      method_name = "receive_#{klass}_reply"
+      if self.class.private_instance_methods.include?(method_name)
+        send method_name, object_id
+      else
+        # ignoring it
+      end
+    elsif m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
+      # for compatibility
+      receive_issue_reply(m[1].to_i)
     else
       receive_issue
     end
@@ -117,7 +128,7 @@ class MailHandler < ActionMailer::Base
   end
   
   # Adds a note to an existing issue
-  def receive_issue_update(issue_id)
+  def receive_issue_reply(issue_id)
     status =  (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
     
     issue = Issue.find_by_id(issue_id)
@@ -139,6 +150,14 @@ class MailHandler < ActionMailer::Base
     journal
   end
   
+  # Reply will be added to the issue
+  def receive_journal_reply(journal_id)
+    journal = Journal.find_by_id(journal_id)
+    if journal && journal.journalized_type == 'Issue'
+      receive_issue_reply(journal.journalized_id)
+    end
+  end
+  
   def add_attachments(obj)
     if email.has_attachments?
       email.attachments.each do |attachment|
index 99fcfa0d18546d2cec8b64479e91645fc1bfa4c8..74724ccf46af89caa96fb032f25d23cc0c0b709c 100644 (file)
@@ -3,10 +3,11 @@ Received: from osiris ([127.0.0.1])
        by OSIRIS\r
        with hMailServer ; Sat, 21 Jun 2008 18:41:39 +0200\r
 Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris>\r
+In-Reply-To: <redmine.issue-2.20060719210421@osiris>\r
 From: "John Smith" <jsmith@somenet.foo>\r
 To: <redmine@somenet.foo>\r
 References: <485d0ad366c88_d7014663a025f@osiris.tmail>\r
-Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories\r
+Subject: Re: Add ingredients categories\r
 Date: Sat, 21 Jun 2008 18:41:39 +0200\r
 MIME-Version: 1.0\r
 Content-Type: multipart/alternative;\r