Use In-Reply-To and References headers to handle replies by email.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2288 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-01-19 18:29:07 +00:00
parent 254e224bd7
commit 0c4e40b89c
2 changed files with 24 additions and 4 deletions

View 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|

View File

@ -3,10 +3,11 @@ Received: from osiris ([127.0.0.1])
by OSIRIS
with hMailServer ; Sat, 21 Jun 2008 18:41:39 +0200
Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris>
In-Reply-To: <redmine.issue-2.20060719210421@osiris>
From: "John Smith" <jsmith@somenet.foo>
To: <redmine@somenet.foo>
References: <485d0ad366c88_d7014663a025f@osiris.tmail>
Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories
Subject: Re: Add ingredients categories
Date: Sat, 21 Jun 2008 18:41:39 +0200
MIME-Version: 1.0
Content-Type: multipart/alternative;