##// END OF EJS Templates
Accept replies to forum messages by subject recognition (#1616)....
Jean-Philippe Lang -
r2292:dfab202cdec1
parent child
Show More
@@ -0,0 +1,13
1 Message-ID: <4974C93E.3070005@somenet.foo>
2 Date: Mon, 19 Jan 2009 19:41:02 +0100
3 From: "John Smith" <jsmith@somenet.foo>
4 User-Agent: Thunderbird 2.0.0.19 (Windows/20081209)
5 MIME-Version: 1.0
6 To: redmine@somenet.foo
7 Subject: Re: [eCookbook - Help board - msg2] Reply to the first post
8 Content-Type: text/plain; charset=UTF-8; format=flowed
9 Content-Transfer-Encoding: 7bit
10
11 This is a reply to a forum message.
12
13
@@ -55,6 +55,7 class MailHandler < ActionMailer::Base
55
55
56 MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
56 MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
57 ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
57 ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
58 MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]+msg(\d+)\]}
58
59
59 def dispatch
60 def dispatch
60 headers = [email.in_reply_to, email.references].flatten.compact
61 headers = [email.in_reply_to, email.references].flatten.compact
@@ -67,8 +68,9 class MailHandler < ActionMailer::Base
67 # ignoring it
68 # ignoring it
68 end
69 end
69 elsif m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
70 elsif m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
70 # for compatibility
71 receive_issue_reply(m[1].to_i)
71 receive_issue_reply(m[1].to_i)
72 elsif m = email.subject.match(MESSAGE_REPLY_SUBJECT_RE)
73 receive_message_reply(m[1].to_i)
72 else
74 else
73 receive_issue
75 receive_issue
74 end
76 end
@@ -164,7 +166,8 class MailHandler < ActionMailer::Base
164 if message
166 if message
165 message = message.root
167 message = message.root
166 if user.allowed_to?(:add_messages, message.project) && !message.locked?
168 if user.allowed_to?(:add_messages, message.project) && !message.locked?
167 reply = Message.new(:subject => email.subject, :content => plain_text_body)
169 reply = Message.new(:subject => email.subject.gsub(%r{^.*msg\d+\]}, '').strip,
170 :content => plain_text_body)
168 reply.author = user
171 reply.author = user
169 reply.board = message.board
172 reply.board = message.board
170 message.children << reply
173 message.children << reply
@@ -111,7 +111,7 class Mailer < ActionMailer::Base
111 message_id message
111 message_id message
112 references message.parent unless message.parent.nil?
112 references message.parent unless message.parent.nil?
113 recipients(recipients)
113 recipients(recipients)
114 subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
114 subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
115 body :message => message,
115 body :message => message,
116 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
116 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
117 end
117 end
@@ -153,6 +153,15 class MailHandlerTest < Test::Unit::TestCase
153 assert_equal Message.find(1), m.parent
153 assert_equal Message.find(1), m.parent
154 end
154 end
155
155
156 def test_reply_to_a_message_by_subject
157 m = submit_email('message_reply_by_subject.eml')
158 assert m.is_a?(Message)
159 assert !m.new_record?
160 m.reload
161 assert_equal 'Reply to the first post', m.subject
162 assert_equal Message.find(1), m.parent
163 end
164
156 def test_should_strip_tags_of_html_only_emails
165 def test_should_strip_tags_of_html_only_emails
157 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
166 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
158 assert issue.is_a?(Issue)
167 assert issue.is_a?(Issue)
General Comments 0
You need to be logged in to leave comments. Login now