##// END OF EJS Templates
Use In-Reply-To and References headers to handle replies by email....
Jean-Philippe Lang -
r2286:0c4e40b89cfe
parent child
Show More
@@ -53,11 +53,22 class MailHandler < ActionMailer::Base
53
53
54 private
54 private
55
55
56 MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
56 ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
57 ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
57
58
58 def dispatch
59 def dispatch
59 if m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
60 headers = [email.in_reply_to, email.references].flatten.compact
60 receive_issue_update(m[1].to_i)
61 if headers.detect {|h| h.to_s =~ MESSAGE_ID_RE}
62 klass, object_id = $1, $2.to_i
63 method_name = "receive_#{klass}_reply"
64 if self.class.private_instance_methods.include?(method_name)
65 send method_name, object_id
66 else
67 # ignoring it
68 end
69 elsif m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
70 # for compatibility
71 receive_issue_reply(m[1].to_i)
61 else
72 else
62 receive_issue
73 receive_issue
63 end
74 end
@@ -117,7 +128,7 class MailHandler < ActionMailer::Base
117 end
128 end
118
129
119 # Adds a note to an existing issue
130 # Adds a note to an existing issue
120 def receive_issue_update(issue_id)
131 def receive_issue_reply(issue_id)
121 status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
132 status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
122
133
123 issue = Issue.find_by_id(issue_id)
134 issue = Issue.find_by_id(issue_id)
@@ -139,6 +150,14 class MailHandler < ActionMailer::Base
139 journal
150 journal
140 end
151 end
141
152
153 # Reply will be added to the issue
154 def receive_journal_reply(journal_id)
155 journal = Journal.find_by_id(journal_id)
156 if journal && journal.journalized_type == 'Issue'
157 receive_issue_reply(journal.journalized_id)
158 end
159 end
160
142 def add_attachments(obj)
161 def add_attachments(obj)
143 if email.has_attachments?
162 if email.has_attachments?
144 email.attachments.each do |attachment|
163 email.attachments.each do |attachment|
@@ -3,10 +3,11 Received: from osiris ([127.0.0.1])
3 by OSIRIS
3 by OSIRIS
4 with hMailServer ; Sat, 21 Jun 2008 18:41:39 +0200
4 with hMailServer ; Sat, 21 Jun 2008 18:41:39 +0200
5 Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris>
5 Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris>
6 In-Reply-To: <redmine.issue-2.20060719210421@osiris>
6 From: "John Smith" <jsmith@somenet.foo>
7 From: "John Smith" <jsmith@somenet.foo>
7 To: <redmine@somenet.foo>
8 To: <redmine@somenet.foo>
8 References: <485d0ad366c88_d7014663a025f@osiris.tmail>
9 References: <485d0ad366c88_d7014663a025f@osiris.tmail>
9 Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories
10 Subject: Re: Add ingredients categories
10 Date: Sat, 21 Jun 2008 18:41:39 +0200
11 Date: Sat, 21 Jun 2008 18:41:39 +0200
11 MIME-Version: 1.0
12 MIME-Version: 1.0
12 Content-Type: multipart/alternative;
13 Content-Type: multipart/alternative;
General Comments 0
You need to be logged in to leave comments. Login now