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