##// END OF EJS Templates
Adds a test with Japanese keywords in a ISO-2002-JP encoded email (#4576)....
Jean-Philippe Lang -
r3208:bddf3b5c2c61
parent child
Show More
@@ -0,0 +1,60
1 Message-ID: <001101ca9762$293d68c0$0600a8c0@osiris>
2 From: "jsmith" <jsmith@somenet.foo>
3 To: <redmine@somenet.foo>
4 Subject: Japanese Character pattern matching
5 Date: Sun, 17 Jan 2010 11:45:18 +0100
6 MIME-Version: 1.0
7 Content-Type: multipart/alternative;
8 boundary="----=_NextPart_000_000E_01CA976A.8AF5E9E0"
9 X-Priority: 3
10 X-MSMail-Priority: Normal
11 X-Mailer: Microsoft Outlook Express 6.00.2900.2869
12 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
13
14 This is a multi-part message in MIME format.
15
16 ------=_NextPart_000_000E_01CA976A.8AF5E9E0
17 Content-Type: text/plain;
18 charset="iso-2022-jp"
19 Content-Transfer-Encoding: quoted-printable
20
21 It should be noted that I am receiving emails using pop and the patch in =
22 Issue #2420 but I don't think the problem lies with this.
23
24 When I try and send emails to the redmine server with Japanese =
25 characters in them it appears to work apart from the pattern matching.
26
27 For example if I send an email with the following keywords.
28
29 Tracker: =1B$B3+H/=1B(B
30
31 ------=_NextPart_000_000E_01CA976A.8AF5E9E0
32 Content-Type: text/html;
33 charset="iso-2022-jp"
34 Content-Transfer-Encoding: quoted-printable
35
36 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
37 <HTML><HEAD>
38 <META content=3D"text/html; charset=3Diso-2022-jp" =
39 http-equiv=3DContent-Type>
40 <META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18702">
41 <STYLE></STYLE>
42 </HEAD>
43 <BODY bgColor=3D#ffffff>
44 <DIV><FONT size=3D2 face=3DArial>
45 <P>It should be noted that I am receiving emails using pop and the patch =
46 in=20
47 Issue <A class=3D"issue status-1 priority-2"=20
48 title=3D"Fetching emails from an POP server (New)"=20
49 href=3D"http://www.redmine.org/issues/2420">#2420</A> but I don't think =
50 the=20
51 problem lies with this.</P>
52 <P>When I try and send emails to the redmine server with Japanese =
53 characters in=20
54 them it appears to work apart from the pattern matching.</P>
55 <P>For example if I send an email with the following keywords.</P>
56 <P>Tracker: =
57 =1B$B3+H/=1B(B</P></FONT></DIV></BODY></HTML>
58
59 ------=_NextPart_000_000E_01CA976A.8AF5E9E0--
60
@@ -1,340 +1,348
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class MailHandlerTest < ActiveSupport::TestCase
20 class MailHandlerTest < ActiveSupport::TestCase
21 fixtures :users, :projects,
21 fixtures :users, :projects,
22 :enabled_modules,
22 :enabled_modules,
23 :roles,
23 :roles,
24 :members,
24 :members,
25 :member_roles,
25 :member_roles,
26 :issues,
26 :issues,
27 :issue_statuses,
27 :issue_statuses,
28 :workflows,
28 :workflows,
29 :trackers,
29 :trackers,
30 :projects_trackers,
30 :projects_trackers,
31 :enumerations,
31 :enumerations,
32 :issue_categories,
32 :issue_categories,
33 :custom_fields,
33 :custom_fields,
34 :custom_fields_trackers,
34 :custom_fields_trackers,
35 :boards,
35 :boards,
36 :messages
36 :messages
37
37
38 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
38 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
39
39
40 def setup
40 def setup
41 ActionMailer::Base.deliveries.clear
41 ActionMailer::Base.deliveries.clear
42 end
42 end
43
43
44 def test_add_issue
44 def test_add_issue
45 ActionMailer::Base.deliveries.clear
45 ActionMailer::Base.deliveries.clear
46 # This email contains: 'Project: onlinestore'
46 # This email contains: 'Project: onlinestore'
47 issue = submit_email('ticket_on_given_project.eml')
47 issue = submit_email('ticket_on_given_project.eml')
48 assert issue.is_a?(Issue)
48 assert issue.is_a?(Issue)
49 assert !issue.new_record?
49 assert !issue.new_record?
50 issue.reload
50 issue.reload
51 assert_equal 'New ticket on a given project', issue.subject
51 assert_equal 'New ticket on a given project', issue.subject
52 assert_equal User.find_by_login('jsmith'), issue.author
52 assert_equal User.find_by_login('jsmith'), issue.author
53 assert_equal Project.find(2), issue.project
53 assert_equal Project.find(2), issue.project
54 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
54 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
55 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
55 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
56 # keywords should be removed from the email body
56 # keywords should be removed from the email body
57 assert !issue.description.match(/^Project:/i)
57 assert !issue.description.match(/^Project:/i)
58 assert !issue.description.match(/^Status:/i)
58 assert !issue.description.match(/^Status:/i)
59 # Email notification should be sent
59 # Email notification should be sent
60 mail = ActionMailer::Base.deliveries.last
60 mail = ActionMailer::Base.deliveries.last
61 assert_not_nil mail
61 assert_not_nil mail
62 assert mail.subject.include?('New ticket on a given project')
62 assert mail.subject.include?('New ticket on a given project')
63 end
63 end
64
64
65 def test_add_issue_with_status
65 def test_add_issue_with_status
66 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
66 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
67 issue = submit_email('ticket_on_given_project.eml')
67 issue = submit_email('ticket_on_given_project.eml')
68 assert issue.is_a?(Issue)
68 assert issue.is_a?(Issue)
69 assert !issue.new_record?
69 assert !issue.new_record?
70 issue.reload
70 issue.reload
71 assert_equal Project.find(2), issue.project
71 assert_equal Project.find(2), issue.project
72 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
72 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
73 end
73 end
74
74
75 def test_add_issue_with_attributes_override
75 def test_add_issue_with_attributes_override
76 issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority')
76 issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority')
77 assert issue.is_a?(Issue)
77 assert issue.is_a?(Issue)
78 assert !issue.new_record?
78 assert !issue.new_record?
79 issue.reload
79 issue.reload
80 assert_equal 'New ticket on a given project', issue.subject
80 assert_equal 'New ticket on a given project', issue.subject
81 assert_equal User.find_by_login('jsmith'), issue.author
81 assert_equal User.find_by_login('jsmith'), issue.author
82 assert_equal Project.find(2), issue.project
82 assert_equal Project.find(2), issue.project
83 assert_equal 'Feature request', issue.tracker.to_s
83 assert_equal 'Feature request', issue.tracker.to_s
84 assert_equal 'Stock management', issue.category.to_s
84 assert_equal 'Stock management', issue.category.to_s
85 assert_equal 'Urgent', issue.priority.to_s
85 assert_equal 'Urgent', issue.priority.to_s
86 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
86 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
87 end
87 end
88
88
89 def test_add_issue_with_partial_attributes_override
89 def test_add_issue_with_partial_attributes_override
90 issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker'])
90 issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker'])
91 assert issue.is_a?(Issue)
91 assert issue.is_a?(Issue)
92 assert !issue.new_record?
92 assert !issue.new_record?
93 issue.reload
93 issue.reload
94 assert_equal 'New ticket on a given project', issue.subject
94 assert_equal 'New ticket on a given project', issue.subject
95 assert_equal User.find_by_login('jsmith'), issue.author
95 assert_equal User.find_by_login('jsmith'), issue.author
96 assert_equal Project.find(2), issue.project
96 assert_equal Project.find(2), issue.project
97 assert_equal 'Feature request', issue.tracker.to_s
97 assert_equal 'Feature request', issue.tracker.to_s
98 assert_nil issue.category
98 assert_nil issue.category
99 assert_equal 'High', issue.priority.to_s
99 assert_equal 'High', issue.priority.to_s
100 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
100 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
101 end
101 end
102
102
103 def test_add_issue_with_spaces_between_attribute_and_separator
103 def test_add_issue_with_spaces_between_attribute_and_separator
104 issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority')
104 issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority')
105 assert issue.is_a?(Issue)
105 assert issue.is_a?(Issue)
106 assert !issue.new_record?
106 assert !issue.new_record?
107 issue.reload
107 issue.reload
108 assert_equal 'New ticket on a given project', issue.subject
108 assert_equal 'New ticket on a given project', issue.subject
109 assert_equal User.find_by_login('jsmith'), issue.author
109 assert_equal User.find_by_login('jsmith'), issue.author
110 assert_equal Project.find(2), issue.project
110 assert_equal Project.find(2), issue.project
111 assert_equal 'Feature request', issue.tracker.to_s
111 assert_equal 'Feature request', issue.tracker.to_s
112 assert_equal 'Stock management', issue.category.to_s
112 assert_equal 'Stock management', issue.category.to_s
113 assert_equal 'Urgent', issue.priority.to_s
113 assert_equal 'Urgent', issue.priority.to_s
114 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
114 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
115 end
115 end
116
116
117
117
118 def test_add_issue_with_attachment_to_specific_project
118 def test_add_issue_with_attachment_to_specific_project
119 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
119 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
120 assert issue.is_a?(Issue)
120 assert issue.is_a?(Issue)
121 assert !issue.new_record?
121 assert !issue.new_record?
122 issue.reload
122 issue.reload
123 assert_equal 'Ticket created by email with attachment', issue.subject
123 assert_equal 'Ticket created by email with attachment', issue.subject
124 assert_equal User.find_by_login('jsmith'), issue.author
124 assert_equal User.find_by_login('jsmith'), issue.author
125 assert_equal Project.find(2), issue.project
125 assert_equal Project.find(2), issue.project
126 assert_equal 'This is a new ticket with attachments', issue.description
126 assert_equal 'This is a new ticket with attachments', issue.description
127 # Attachment properties
127 # Attachment properties
128 assert_equal 1, issue.attachments.size
128 assert_equal 1, issue.attachments.size
129 assert_equal 'Paella.jpg', issue.attachments.first.filename
129 assert_equal 'Paella.jpg', issue.attachments.first.filename
130 assert_equal 'image/jpeg', issue.attachments.first.content_type
130 assert_equal 'image/jpeg', issue.attachments.first.content_type
131 assert_equal 10790, issue.attachments.first.filesize
131 assert_equal 10790, issue.attachments.first.filesize
132 end
132 end
133
133
134 def test_add_issue_with_custom_fields
134 def test_add_issue_with_custom_fields
135 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
135 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
136 assert issue.is_a?(Issue)
136 assert issue.is_a?(Issue)
137 assert !issue.new_record?
137 assert !issue.new_record?
138 issue.reload
138 issue.reload
139 assert_equal 'New ticket with custom field values', issue.subject
139 assert_equal 'New ticket with custom field values', issue.subject
140 assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
140 assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
141 assert !issue.description.match(/^searchable field:/i)
141 assert !issue.description.match(/^searchable field:/i)
142 end
142 end
143
143
144 def test_add_issue_with_cc
144 def test_add_issue_with_cc
145 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
145 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
146 assert issue.is_a?(Issue)
146 assert issue.is_a?(Issue)
147 assert !issue.new_record?
147 assert !issue.new_record?
148 issue.reload
148 issue.reload
149 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
149 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
150 assert_equal 1, issue.watchers.size
150 assert_equal 1, issue.watchers.size
151 end
151 end
152
152
153 def test_add_issue_by_unknown_user
153 def test_add_issue_by_unknown_user
154 assert_no_difference 'User.count' do
154 assert_no_difference 'User.count' do
155 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'})
155 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'})
156 end
156 end
157 end
157 end
158
158
159 def test_add_issue_by_anonymous_user
159 def test_add_issue_by_anonymous_user
160 Role.anonymous.add_permission!(:add_issues)
160 Role.anonymous.add_permission!(:add_issues)
161 assert_no_difference 'User.count' do
161 assert_no_difference 'User.count' do
162 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept')
162 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept')
163 assert issue.is_a?(Issue)
163 assert issue.is_a?(Issue)
164 assert issue.author.anonymous?
164 assert issue.author.anonymous?
165 end
165 end
166 end
166 end
167
167
168 def test_add_issue_by_anonymous_user_on_private_project
168 def test_add_issue_by_anonymous_user_on_private_project
169 Role.anonymous.add_permission!(:add_issues)
169 Role.anonymous.add_permission!(:add_issues)
170 assert_no_difference 'User.count' do
170 assert_no_difference 'User.count' do
171 assert_no_difference 'Issue.count' do
171 assert_no_difference 'Issue.count' do
172 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :unknown_user => 'accept')
172 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :unknown_user => 'accept')
173 end
173 end
174 end
174 end
175 end
175 end
176
176
177 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
177 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
178 assert_no_difference 'User.count' do
178 assert_no_difference 'User.count' do
179 assert_difference 'Issue.count' do
179 assert_difference 'Issue.count' do
180 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :no_permission_check => '1', :unknown_user => 'accept')
180 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :no_permission_check => '1', :unknown_user => 'accept')
181 assert issue.is_a?(Issue)
181 assert issue.is_a?(Issue)
182 assert issue.author.anonymous?
182 assert issue.author.anonymous?
183 assert !issue.project.is_public?
183 assert !issue.project.is_public?
184 end
184 end
185 end
185 end
186 end
186 end
187
187
188 def test_add_issue_by_created_user
188 def test_add_issue_by_created_user
189 Setting.default_language = 'en'
189 Setting.default_language = 'en'
190 assert_difference 'User.count' do
190 assert_difference 'User.count' do
191 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
191 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
192 assert issue.is_a?(Issue)
192 assert issue.is_a?(Issue)
193 assert issue.author.active?
193 assert issue.author.active?
194 assert_equal 'john.doe@somenet.foo', issue.author.mail
194 assert_equal 'john.doe@somenet.foo', issue.author.mail
195 assert_equal 'John', issue.author.firstname
195 assert_equal 'John', issue.author.firstname
196 assert_equal 'Doe', issue.author.lastname
196 assert_equal 'Doe', issue.author.lastname
197
197
198 # account information
198 # account information
199 email = ActionMailer::Base.deliveries.first
199 email = ActionMailer::Base.deliveries.first
200 assert_not_nil email
200 assert_not_nil email
201 assert email.subject.include?('account activation')
201 assert email.subject.include?('account activation')
202 login = email.body.match(/\* Login: (.*)$/)[1]
202 login = email.body.match(/\* Login: (.*)$/)[1]
203 password = email.body.match(/\* Password: (.*)$/)[1]
203 password = email.body.match(/\* Password: (.*)$/)[1]
204 assert_equal issue.author, User.try_to_login(login, password)
204 assert_equal issue.author, User.try_to_login(login, password)
205 end
205 end
206 end
206 end
207
207
208 def test_add_issue_without_from_header
208 def test_add_issue_without_from_header
209 Role.anonymous.add_permission!(:add_issues)
209 Role.anonymous.add_permission!(:add_issues)
210 assert_equal false, submit_email('ticket_without_from_header.eml')
210 assert_equal false, submit_email('ticket_without_from_header.eml')
211 end
211 end
212
213 def test_add_issue_with_japanese_keywords
214 tracker = Tracker.create!(:name => 'ι–‹η™Ί')
215 Project.find(1).trackers << tracker
216 issue = submit_email('japanese_keywords_iso_2022_jp.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'tracker')
217 assert_kind_of Issue, issue
218 assert_equal tracker, issue.tracker
219 end
212
220
213 def test_should_ignore_emails_from_emission_address
221 def test_should_ignore_emails_from_emission_address
214 Role.anonymous.add_permission!(:add_issues)
222 Role.anonymous.add_permission!(:add_issues)
215 assert_no_difference 'User.count' do
223 assert_no_difference 'User.count' do
216 assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
224 assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
217 end
225 end
218 end
226 end
219
227
220 def test_add_issue_should_send_email_notification
228 def test_add_issue_should_send_email_notification
221 ActionMailer::Base.deliveries.clear
229 ActionMailer::Base.deliveries.clear
222 # This email contains: 'Project: onlinestore'
230 # This email contains: 'Project: onlinestore'
223 issue = submit_email('ticket_on_given_project.eml')
231 issue = submit_email('ticket_on_given_project.eml')
224 assert issue.is_a?(Issue)
232 assert issue.is_a?(Issue)
225 assert_equal 1, ActionMailer::Base.deliveries.size
233 assert_equal 1, ActionMailer::Base.deliveries.size
226 end
234 end
227
235
228 def test_add_issue_note
236 def test_add_issue_note
229 journal = submit_email('ticket_reply.eml')
237 journal = submit_email('ticket_reply.eml')
230 assert journal.is_a?(Journal)
238 assert journal.is_a?(Journal)
231 assert_equal User.find_by_login('jsmith'), journal.user
239 assert_equal User.find_by_login('jsmith'), journal.user
232 assert_equal Issue.find(2), journal.journalized
240 assert_equal Issue.find(2), journal.journalized
233 assert_match /This is reply/, journal.notes
241 assert_match /This is reply/, journal.notes
234 end
242 end
235
243
236 def test_add_issue_note_with_status_change
244 def test_add_issue_note_with_status_change
237 # This email contains: 'Status: Resolved'
245 # This email contains: 'Status: Resolved'
238 journal = submit_email('ticket_reply_with_status.eml')
246 journal = submit_email('ticket_reply_with_status.eml')
239 assert journal.is_a?(Journal)
247 assert journal.is_a?(Journal)
240 issue = Issue.find(journal.issue.id)
248 issue = Issue.find(journal.issue.id)
241 assert_equal User.find_by_login('jsmith'), journal.user
249 assert_equal User.find_by_login('jsmith'), journal.user
242 assert_equal Issue.find(2), journal.journalized
250 assert_equal Issue.find(2), journal.journalized
243 assert_match /This is reply/, journal.notes
251 assert_match /This is reply/, journal.notes
244 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
252 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
245 end
253 end
246
254
247 def test_add_issue_note_should_send_email_notification
255 def test_add_issue_note_should_send_email_notification
248 ActionMailer::Base.deliveries.clear
256 ActionMailer::Base.deliveries.clear
249 journal = submit_email('ticket_reply.eml')
257 journal = submit_email('ticket_reply.eml')
250 assert journal.is_a?(Journal)
258 assert journal.is_a?(Journal)
251 assert_equal 1, ActionMailer::Base.deliveries.size
259 assert_equal 1, ActionMailer::Base.deliveries.size
252 end
260 end
253
261
254 def test_reply_to_a_message
262 def test_reply_to_a_message
255 m = submit_email('message_reply.eml')
263 m = submit_email('message_reply.eml')
256 assert m.is_a?(Message)
264 assert m.is_a?(Message)
257 assert !m.new_record?
265 assert !m.new_record?
258 m.reload
266 m.reload
259 assert_equal 'Reply via email', m.subject
267 assert_equal 'Reply via email', m.subject
260 # The email replies to message #2 which is part of the thread of message #1
268 # The email replies to message #2 which is part of the thread of message #1
261 assert_equal Message.find(1), m.parent
269 assert_equal Message.find(1), m.parent
262 end
270 end
263
271
264 def test_reply_to_a_message_by_subject
272 def test_reply_to_a_message_by_subject
265 m = submit_email('message_reply_by_subject.eml')
273 m = submit_email('message_reply_by_subject.eml')
266 assert m.is_a?(Message)
274 assert m.is_a?(Message)
267 assert !m.new_record?
275 assert !m.new_record?
268 m.reload
276 m.reload
269 assert_equal 'Reply to the first post', m.subject
277 assert_equal 'Reply to the first post', m.subject
270 assert_equal Message.find(1), m.parent
278 assert_equal Message.find(1), m.parent
271 end
279 end
272
280
273 def test_should_strip_tags_of_html_only_emails
281 def test_should_strip_tags_of_html_only_emails
274 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
282 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
275 assert issue.is_a?(Issue)
283 assert issue.is_a?(Issue)
276 assert !issue.new_record?
284 assert !issue.new_record?
277 issue.reload
285 issue.reload
278 assert_equal 'HTML email', issue.subject
286 assert_equal 'HTML email', issue.subject
279 assert_equal 'This is a html-only email.', issue.description
287 assert_equal 'This is a html-only email.', issue.description
280 end
288 end
281
289
282 context "truncate emails based on the Setting" do
290 context "truncate emails based on the Setting" do
283 context "with no setting" do
291 context "with no setting" do
284 setup do
292 setup do
285 Setting.mail_handler_body_delimiters = ''
293 Setting.mail_handler_body_delimiters = ''
286 end
294 end
287
295
288 should "add the entire email into the issue" do
296 should "add the entire email into the issue" do
289 issue = submit_email('ticket_on_given_project.eml')
297 issue = submit_email('ticket_on_given_project.eml')
290 assert_issue_created(issue)
298 assert_issue_created(issue)
291 assert issue.description.include?('---')
299 assert issue.description.include?('---')
292 assert issue.description.include?('This paragraph is after the delimiter')
300 assert issue.description.include?('This paragraph is after the delimiter')
293 end
301 end
294 end
302 end
295
303
296 context "with a single string" do
304 context "with a single string" do
297 setup do
305 setup do
298 Setting.mail_handler_body_delimiters = '---'
306 Setting.mail_handler_body_delimiters = '---'
299 end
307 end
300
308
301 should "truncate the email at the delimiter for the issue" do
309 should "truncate the email at the delimiter for the issue" do
302 issue = submit_email('ticket_on_given_project.eml')
310 issue = submit_email('ticket_on_given_project.eml')
303 assert_issue_created(issue)
311 assert_issue_created(issue)
304 assert issue.description.include?('This paragraph is before delimiters')
312 assert issue.description.include?('This paragraph is before delimiters')
305 assert issue.description.include?('--- This line starts with a delimiter')
313 assert issue.description.include?('--- This line starts with a delimiter')
306 assert !issue.description.match(/^---$/)
314 assert !issue.description.match(/^---$/)
307 assert !issue.description.include?('This paragraph is after the delimiter')
315 assert !issue.description.include?('This paragraph is after the delimiter')
308 end
316 end
309 end
317 end
310
318
311 context "with multiple strings" do
319 context "with multiple strings" do
312 setup do
320 setup do
313 Setting.mail_handler_body_delimiters = "---\nBREAK"
321 Setting.mail_handler_body_delimiters = "---\nBREAK"
314 end
322 end
315
323
316 should "truncate the email at the first delimiter found (BREAK)" do
324 should "truncate the email at the first delimiter found (BREAK)" do
317 issue = submit_email('ticket_on_given_project.eml')
325 issue = submit_email('ticket_on_given_project.eml')
318 assert_issue_created(issue)
326 assert_issue_created(issue)
319 assert issue.description.include?('This paragraph is before delimiters')
327 assert issue.description.include?('This paragraph is before delimiters')
320 assert !issue.description.include?('BREAK')
328 assert !issue.description.include?('BREAK')
321 assert !issue.description.include?('This paragraph is between delimiters')
329 assert !issue.description.include?('This paragraph is between delimiters')
322 assert !issue.description.match(/^---$/)
330 assert !issue.description.match(/^---$/)
323 assert !issue.description.include?('This paragraph is after the delimiter')
331 assert !issue.description.include?('This paragraph is after the delimiter')
324 end
332 end
325 end
333 end
326 end
334 end
327
335
328 private
336 private
329
337
330 def submit_email(filename, options={})
338 def submit_email(filename, options={})
331 raw = IO.read(File.join(FIXTURES_PATH, filename))
339 raw = IO.read(File.join(FIXTURES_PATH, filename))
332 MailHandler.receive(raw, options)
340 MailHandler.receive(raw, options)
333 end
341 end
334
342
335 def assert_issue_created(issue)
343 def assert_issue_created(issue)
336 assert issue.is_a?(Issue)
344 assert issue.is_a?(Issue)
337 assert !issue.new_record?
345 assert !issue.new_record?
338 issue.reload
346 issue.reload
339 end
347 end
340 end
348 end
General Comments 0
You need to be logged in to leave comments. Login now