1 #
2 # Copyright (c) 2001 Richard Jones, richard@bofh.asn.au.
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # This module is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 #
11 # $Id: test_mailgw.py,v 1.46 2003-05-06 21:49:20 kedder Exp $
13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
14 import rfc822
16 # Note: Should parse emails according to RFC2822 instead of performing a
17 # literal string comparision. Parsing the messages allows the tests to work for
18 # any legal serialization of an email.
19 #try :
20 # import email
21 #except ImportError :
22 # import rfc822 as email
24 from roundup.mailgw import MailGW, Unauthorized, uidFromAddress
25 from roundup import init, instance, rfc2822
27 # TODO: make this output only enough equal lines for context, not all of
28 # them
29 class DiffHelper:
30 def compareStrings(self, s2, s1):
31 '''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants
32 the first to be the "original" but in the calls in this file,
33 the second arg is the original. Ho hum.
34 '''
35 # we have to special-case the Date: header here 'cos we can't test
36 # for it properly
37 l1=s1.strip().split('\n')
38 l2=[x for x in s2.strip().split('\n') if not x.startswith('Date: ')]
39 if l1 == l2:
40 return
42 s = difflib.SequenceMatcher(None, l1, l2)
43 res = ['Generated message not correct (diff follows):']
44 for value, s1s, s1e, s2s, s2e in s.get_opcodes():
45 if value == 'equal':
46 for i in range(s1s, s1e):
47 res.append(' %s'%l1[i])
48 elif value == 'delete':
49 for i in range(s1s, s1e):
50 res.append('- %s'%l1[i])
51 elif value == 'insert':
52 for i in range(s2s, s2e):
53 res.append('+ %s'%l2[i])
54 elif value == 'replace':
55 for i, j in zip(range(s1s, s1e), range(s2s, s2e)):
56 res.append('- %s'%l1[i])
57 res.append('+ %s'%l2[j])
59 raise AssertionError, '\n'.join(res)
61 class MailgwTestCase(unittest.TestCase, DiffHelper):
62 count = 0
63 schema = 'classic'
64 def setUp(self):
65 MailgwTestCase.count = MailgwTestCase.count + 1
66 self.dirname = '_test_mailgw_%s'%self.count
67 try:
68 shutil.rmtree(self.dirname)
69 except OSError, error:
70 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
71 # create the instance
72 init.install(self.dirname, 'templates/classic')
73 init.write_select_db(self.dirname, 'anydbm')
74 init.initialise(self.dirname, 'sekrit')
75 # check we can load the package
76 self.instance = instance.open(self.dirname)
77 # and open the database
78 self.db = self.instance.open('admin')
79 self.db.user.create(username='Chef', address='chef@bork.bork.bork',
80 realname='Bork, Chef', roles='User')
81 self.db.user.create(username='richard', address='richard@test',
82 roles='User')
83 self.db.user.create(username='mary', address='mary@test',
84 roles='User', realname='Contrary, Mary')
85 self.db.user.create(username='john', address='john@test',
86 alternate_addresses='jondoe@test\njohn.doe@test', roles='User',
87 realname='John Doe')
89 def tearDown(self):
90 if os.path.exists(os.environ['SENDMAILDEBUG']):
91 os.remove(os.environ['SENDMAILDEBUG'])
92 self.db.close()
93 try:
94 shutil.rmtree(self.dirname)
95 except OSError, error:
96 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
98 def testEmptyMessage(self):
99 message = cStringIO.StringIO('''Content-Type: text/plain;
100 charset="iso-8859-1"
101 From: Chef <chef@bork.bork.bork>
102 To: issue_tracker@your.tracker.email.domain.example
103 Cc: richard@test
104 Message-Id: <dummy_test_message_id>
105 Subject: [issue] Testing...
107 ''')
108 handler = self.instance.MailGW(self.instance, self.db)
109 handler.trapExceptions = 0
110 nodeid = handler.main(message)
111 if os.path.exists(os.environ['SENDMAILDEBUG']):
112 error = open(os.environ['SENDMAILDEBUG']).read()
113 self.assertEqual('no error', error)
114 self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...')
116 def doNewIssue(self):
117 message = cStringIO.StringIO('''Content-Type: text/plain;
118 charset="iso-8859-1"
119 From: Chef <chef@bork.bork.bork>
120 To: issue_tracker@your.tracker.email.domain.example
121 Cc: richard@test
122 Message-Id: <dummy_test_message_id>
123 Subject: [issue] Testing...
125 This is a test submission of a new issue.
126 ''')
127 handler = self.instance.MailGW(self.instance, self.db)
128 handler.trapExceptions = 0
129 nodeid = handler.main(message)
130 if os.path.exists(os.environ['SENDMAILDEBUG']):
131 error = open(os.environ['SENDMAILDEBUG']).read()
132 self.assertEqual('no error', error)
133 l = self.db.issue.get(nodeid, 'nosy')
134 l.sort()
135 self.assertEqual(l, ['3', '4'])
136 return nodeid
138 def testNewIssue(self):
139 self.doNewIssue()
141 def testNewIssueNosy(self):
142 self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
143 message = cStringIO.StringIO('''Content-Type: text/plain;
144 charset="iso-8859-1"
145 From: Chef <chef@bork.bork.bork>
146 To: issue_tracker@your.tracker.email.domain.example
147 Cc: richard@test
148 Message-Id: <dummy_test_message_id>
149 Subject: [issue] Testing...
151 This is a test submission of a new issue.
152 ''')
153 handler = self.instance.MailGW(self.instance, self.db)
154 handler.trapExceptions = 0
155 nodeid = handler.main(message)
156 if os.path.exists(os.environ['SENDMAILDEBUG']):
157 error = open(os.environ['SENDMAILDEBUG']).read()
158 self.assertEqual('no error', error)
159 l = self.db.issue.get(nodeid, 'nosy')
160 l.sort()
161 self.assertEqual(l, ['3', '4'])
163 def testAlternateAddress(self):
164 message = cStringIO.StringIO('''Content-Type: text/plain;
165 charset="iso-8859-1"
166 From: John Doe <john.doe@test>
167 To: issue_tracker@your.tracker.email.domain.example
168 Message-Id: <dummy_test_message_id>
169 Subject: [issue] Testing...
171 This is a test submission of a new issue.
172 ''')
173 userlist = self.db.user.list()
174 handler = self.instance.MailGW(self.instance, self.db)
175 handler.trapExceptions = 0
176 handler.main(message)
177 if os.path.exists(os.environ['SENDMAILDEBUG']):
178 error = open(os.environ['SENDMAILDEBUG']).read()
179 self.assertEqual('no error', error)
180 self.assertEqual(userlist, self.db.user.list(),
181 "user created when it shouldn't have been")
183 def testNewIssueNoClass(self):
184 message = cStringIO.StringIO('''Content-Type: text/plain;
185 charset="iso-8859-1"
186 From: Chef <chef@bork.bork.bork>
187 To: issue_tracker@your.tracker.email.domain.example
188 Cc: richard@test
189 Message-Id: <dummy_test_message_id>
190 Subject: Testing...
192 This is a test submission of a new issue.
193 ''')
194 handler = self.instance.MailGW(self.instance, self.db)
195 handler.trapExceptions = 0
196 handler.main(message)
197 if os.path.exists(os.environ['SENDMAILDEBUG']):
198 error = open(os.environ['SENDMAILDEBUG']).read()
199 self.assertEqual('no error', error)
201 def testNewIssueAuthMsg(self):
202 message = cStringIO.StringIO('''Content-Type: text/plain;
203 charset="iso-8859-1"
204 From: Chef <chef@bork.bork.bork>
205 To: issue_tracker@your.tracker.email.domain.example
206 Message-Id: <dummy_test_message_id>
207 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
209 This is a test submission of a new issue.
210 ''')
211 handler = self.instance.MailGW(self.instance, self.db)
212 handler.trapExceptions = 0
213 # TODO: fix the damn config - this is apalling
214 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
215 handler.main(message)
217 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
218 '''FROM: roundup-admin@your.tracker.email.domain.example
219 TO: chef@bork.bork.bork, mary@test, richard@test
220 Content-Type: text/plain; charset=utf-8
221 Subject: [issue1] Testing...
222 To: chef@bork.bork.bork, mary@test, richard@test
223 From: "Bork, Chef" <issue_tracker@your.tracker.email.domain.example>
224 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
225 MIME-Version: 1.0
226 Message-Id: <dummy_test_message_id>
227 X-Roundup-Name: Roundup issue tracker
228 X-Roundup-Loop: hello
229 Content-Transfer-Encoding: quoted-printable
232 New submission from Bork, Chef <chef@bork.bork.bork>:
234 This is a test submission of a new issue.
236 ----------
237 assignedto: richard
238 messages: 1
239 nosy: Chef, mary, richard
240 status: unread
241 title: Testing...
242 _______________________________________________________________________
243 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
244 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
245 _______________________________________________________________________
246 ''')
248 # BUG
249 # def testMultipart(self):
250 # '''With more than one part'''
251 # see MultipartEnc tests: but if there is more than one part
252 # we return a multipart/mixed and the boundary contains
253 # the ip address of the test machine.
255 # BUG should test some binary attamchent too.
257 def testSimpleFollowup(self):
258 self.doNewIssue()
259 message = cStringIO.StringIO('''Content-Type: text/plain;
260 charset="iso-8859-1"
261 From: mary <mary@test>
262 To: issue_tracker@your.tracker.email.domain.example
263 Message-Id: <followup_dummy_id>
264 In-Reply-To: <dummy_test_message_id>
265 Subject: [issue1] Testing...
267 This is a second followup
268 ''')
269 handler = self.instance.MailGW(self.instance, self.db)
270 handler.trapExceptions = 0
271 handler.main(message)
272 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
273 '''FROM: roundup-admin@your.tracker.email.domain.example
274 TO: chef@bork.bork.bork, richard@test
275 Content-Type: text/plain; charset=utf-8
276 Subject: [issue1] Testing...
277 To: chef@bork.bork.bork, richard@test
278 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
279 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
280 MIME-Version: 1.0
281 Message-Id: <followup_dummy_id>
282 In-Reply-To: <dummy_test_message_id>
283 X-Roundup-Name: Roundup issue tracker
284 X-Roundup-Loop: hello
285 Content-Transfer-Encoding: quoted-printable
288 Contrary, Mary <mary@test> added the comment:
290 This is a second followup
292 ----------
293 status: unread -> chatting
294 _______________________________________________________________________
295 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
296 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
297 _______________________________________________________________________
298 ''')
300 def testFollowup(self):
301 self.doNewIssue()
303 message = cStringIO.StringIO('''Content-Type: text/plain;
304 charset="iso-8859-1"
305 From: richard <richard@test>
306 To: issue_tracker@your.tracker.email.domain.example
307 Message-Id: <followup_dummy_id>
308 In-Reply-To: <dummy_test_message_id>
309 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
311 This is a followup
312 ''')
313 handler = self.instance.MailGW(self.instance, self.db)
314 handler.trapExceptions = 0
315 handler.main(message)
316 l = self.db.issue.get('1', 'nosy')
317 l.sort()
318 self.assertEqual(l, ['3', '4', '5', '6'])
320 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
321 '''FROM: roundup-admin@your.tracker.email.domain.example
322 TO: chef@bork.bork.bork, john@test, mary@test
323 Content-Type: text/plain; charset=utf-8
324 Subject: [issue1] Testing...
325 To: chef@bork.bork.bork, john@test, mary@test
326 From: richard <issue_tracker@your.tracker.email.domain.example>
327 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
328 MIME-Version: 1.0
329 Message-Id: <followup_dummy_id>
330 In-Reply-To: <dummy_test_message_id>
331 X-Roundup-Name: Roundup issue tracker
332 X-Roundup-Loop: hello
333 Content-Transfer-Encoding: quoted-printable
336 richard <richard@test> added the comment:
338 This is a followup
340 ----------
341 assignedto: -> mary
342 nosy: +john, mary
343 status: unread -> chatting
344 _______________________________________________________________________
345 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
346 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
347 _______________________________________________________________________
348 ''')
350 def testFollowupTitleMatch(self):
351 self.doNewIssue()
352 message = cStringIO.StringIO('''Content-Type: text/plain;
353 charset="iso-8859-1"
354 From: richard <richard@test>
355 To: issue_tracker@your.tracker.email.domain.example
356 Message-Id: <followup_dummy_id>
357 In-Reply-To: <dummy_test_message_id>
358 Subject: Re: Testing... [assignedto=mary; nosy=+john]
360 This is a followup
361 ''')
362 handler = self.instance.MailGW(self.instance, self.db)
363 handler.trapExceptions = 0
364 handler.main(message)
366 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
367 '''FROM: roundup-admin@your.tracker.email.domain.example
368 TO: chef@bork.bork.bork, john@test, mary@test
369 Content-Type: text/plain; charset=utf-8
370 Subject: [issue1] Testing...
371 To: chef@bork.bork.bork, john@test, mary@test
372 From: richard <issue_tracker@your.tracker.email.domain.example>
373 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
374 MIME-Version: 1.0
375 Message-Id: <followup_dummy_id>
376 In-Reply-To: <dummy_test_message_id>
377 X-Roundup-Name: Roundup issue tracker
378 X-Roundup-Loop: hello
379 Content-Transfer-Encoding: quoted-printable
382 richard <richard@test> added the comment:
384 This is a followup
386 ----------
387 assignedto: -> mary
388 nosy: +john, mary
389 status: unread -> chatting
390 _______________________________________________________________________
391 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
392 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
393 _______________________________________________________________________
394 ''')
396 def testFollowupNosyAuthor(self):
397 self.doNewIssue()
398 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
399 message = cStringIO.StringIO('''Content-Type: text/plain;
400 charset="iso-8859-1"
401 From: john@test
402 To: issue_tracker@your.tracker.email.domain.example
403 Message-Id: <followup_dummy_id>
404 In-Reply-To: <dummy_test_message_id>
405 Subject: [issue1] Testing...
407 This is a followup
408 ''')
409 handler = self.instance.MailGW(self.instance, self.db)
410 handler.trapExceptions = 0
411 handler.main(message)
413 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
414 '''FROM: roundup-admin@your.tracker.email.domain.example
415 TO: chef@bork.bork.bork, richard@test
416 Content-Type: text/plain; charset=utf-8
417 Subject: [issue1] Testing...
418 To: chef@bork.bork.bork, richard@test
419 From: John Doe <issue_tracker@your.tracker.email.domain.example>
420 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
421 MIME-Version: 1.0
422 Message-Id: <followup_dummy_id>
423 In-Reply-To: <dummy_test_message_id>
424 X-Roundup-Name: Roundup issue tracker
425 X-Roundup-Loop: hello
426 Content-Transfer-Encoding: quoted-printable
429 John Doe <john@test> added the comment:
431 This is a followup
433 ----------
434 nosy: +john
435 status: unread -> chatting
436 _______________________________________________________________________
437 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
438 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
439 _______________________________________________________________________
441 ''')
443 def testFollowupNosyRecipients(self):
444 self.doNewIssue()
445 self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
446 message = cStringIO.StringIO('''Content-Type: text/plain;
447 charset="iso-8859-1"
448 From: richard@test
449 To: issue_tracker@your.tracker.email.domain.example
450 Cc: john@test
451 Message-Id: <followup_dummy_id>
452 In-Reply-To: <dummy_test_message_id>
453 Subject: [issue1] Testing...
455 This is a followup
456 ''')
457 handler = self.instance.MailGW(self.instance, self.db)
458 handler.trapExceptions = 0
459 handler.main(message)
461 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
462 '''FROM: roundup-admin@your.tracker.email.domain.example
463 TO: chef@bork.bork.bork
464 Content-Type: text/plain; charset=utf-8
465 Subject: [issue1] Testing...
466 To: chef@bork.bork.bork
467 From: richard <issue_tracker@your.tracker.email.domain.example>
468 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
469 MIME-Version: 1.0
470 Message-Id: <followup_dummy_id>
471 In-Reply-To: <dummy_test_message_id>
472 X-Roundup-Name: Roundup issue tracker
473 X-Roundup-Loop: hello
474 Content-Transfer-Encoding: quoted-printable
477 richard <richard@test> added the comment:
479 This is a followup
481 ----------
482 nosy: +john
483 status: unread -> chatting
484 _______________________________________________________________________
485 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
486 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
487 _______________________________________________________________________
489 ''')
491 def testFollowupNosyAuthorAndCopy(self):
492 self.doNewIssue()
493 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
494 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
495 message = cStringIO.StringIO('''Content-Type: text/plain;
496 charset="iso-8859-1"
497 From: john@test
498 To: issue_tracker@your.tracker.email.domain.example
499 Message-Id: <followup_dummy_id>
500 In-Reply-To: <dummy_test_message_id>
501 Subject: [issue1] Testing...
503 This is a followup
504 ''')
505 handler = self.instance.MailGW(self.instance, self.db)
506 handler.trapExceptions = 0
507 handler.main(message)
509 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
510 '''FROM: roundup-admin@your.tracker.email.domain.example
511 TO: chef@bork.bork.bork, john@test, richard@test
512 Content-Type: text/plain; charset=utf-8
513 Subject: [issue1] Testing...
514 To: chef@bork.bork.bork, john@test, richard@test
515 From: John Doe <issue_tracker@your.tracker.email.domain.example>
516 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
517 MIME-Version: 1.0
518 Message-Id: <followup_dummy_id>
519 In-Reply-To: <dummy_test_message_id>
520 X-Roundup-Name: Roundup issue tracker
521 X-Roundup-Loop: hello
522 Content-Transfer-Encoding: quoted-printable
525 John Doe <john@test> added the comment:
527 This is a followup
529 ----------
530 nosy: +john
531 status: unread -> chatting
532 _______________________________________________________________________
533 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
534 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
535 _______________________________________________________________________
537 ''')
539 def testFollowupNoNosyAuthor(self):
540 self.doNewIssue()
541 self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
542 message = cStringIO.StringIO('''Content-Type: text/plain;
543 charset="iso-8859-1"
544 From: john@test
545 To: issue_tracker@your.tracker.email.domain.example
546 Message-Id: <followup_dummy_id>
547 In-Reply-To: <dummy_test_message_id>
548 Subject: [issue1] Testing...
550 This is a followup
551 ''')
552 handler = self.instance.MailGW(self.instance, self.db)
553 handler.trapExceptions = 0
554 handler.main(message)
556 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
557 '''FROM: roundup-admin@your.tracker.email.domain.example
558 TO: chef@bork.bork.bork, richard@test
559 Content-Type: text/plain; charset=utf-8
560 Subject: [issue1] Testing...
561 To: chef@bork.bork.bork, richard@test
562 From: John Doe <issue_tracker@your.tracker.email.domain.example>
563 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
564 MIME-Version: 1.0
565 Message-Id: <followup_dummy_id>
566 In-Reply-To: <dummy_test_message_id>
567 X-Roundup-Name: Roundup issue tracker
568 X-Roundup-Loop: hello
569 Content-Transfer-Encoding: quoted-printable
572 John Doe <john@test> added the comment:
574 This is a followup
576 ----------
577 status: unread -> chatting
578 _______________________________________________________________________
579 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
580 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
581 _______________________________________________________________________
583 ''')
585 def testFollowupNoNosyRecipients(self):
586 self.doNewIssue()
587 self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
588 message = cStringIO.StringIO('''Content-Type: text/plain;
589 charset="iso-8859-1"
590 From: richard@test
591 To: issue_tracker@your.tracker.email.domain.example
592 Cc: john@test
593 Message-Id: <followup_dummy_id>
594 In-Reply-To: <dummy_test_message_id>
595 Subject: [issue1] Testing...
597 This is a followup
598 ''')
599 handler = self.instance.MailGW(self.instance, self.db)
600 handler.trapExceptions = 0
601 handler.main(message)
603 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
604 '''FROM: roundup-admin@your.tracker.email.domain.example
605 TO: chef@bork.bork.bork
606 Content-Type: text/plain; charset=utf-8
607 Subject: [issue1] Testing...
608 To: chef@bork.bork.bork
609 From: richard <issue_tracker@your.tracker.email.domain.example>
610 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
611 MIME-Version: 1.0
612 Message-Id: <followup_dummy_id>
613 In-Reply-To: <dummy_test_message_id>
614 X-Roundup-Name: Roundup issue tracker
615 X-Roundup-Loop: hello
616 Content-Transfer-Encoding: quoted-printable
619 richard <richard@test> added the comment:
621 This is a followup
623 ----------
624 status: unread -> chatting
625 _______________________________________________________________________
626 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
627 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
628 _______________________________________________________________________
630 ''')
632 def testFollowupEmptyMessage(self):
633 self.doNewIssue()
635 message = cStringIO.StringIO('''Content-Type: text/plain;
636 charset="iso-8859-1"
637 From: richard <richard@test>
638 To: issue_tracker@your.tracker.email.domain.example
639 Message-Id: <followup_dummy_id>
640 In-Reply-To: <dummy_test_message_id>
641 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
643 ''')
644 handler = self.instance.MailGW(self.instance, self.db)
645 handler.trapExceptions = 0
646 handler.main(message)
647 l = self.db.issue.get('1', 'nosy')
648 l.sort()
649 self.assertEqual(l, ['3', '4', '5', '6'])
651 # should be no file created (ie. no message)
652 assert not os.path.exists(os.environ['SENDMAILDEBUG'])
654 def testNosyRemove(self):
655 self.doNewIssue()
657 message = cStringIO.StringIO('''Content-Type: text/plain;
658 charset="iso-8859-1"
659 From: richard <richard@test>
660 To: issue_tracker@your.tracker.email.domain.example
661 Message-Id: <followup_dummy_id>
662 In-Reply-To: <dummy_test_message_id>
663 Subject: [issue1] Testing... [nosy=-richard]
665 ''')
666 handler = self.instance.MailGW(self.instance, self.db)
667 handler.trapExceptions = 0
668 handler.main(message)
669 l = self.db.issue.get('1', 'nosy')
670 l.sort()
671 self.assertEqual(l, ['3'])
673 # NO NOSY MESSAGE SHOULD BE SENT!
674 self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG']))
676 def testNewUserAuthor(self):
677 # first without the permission
678 # heh... just ignore the API for a second ;)
679 self.db.security.role['anonymous'].permissions=[]
680 anonid = self.db.user.lookup('anonymous')
681 self.db.user.set(anonid, roles='Anonymous')
683 self.db.security.hasPermission('Email Registration', anonid)
684 l = self.db.user.list()
685 l.sort()
686 s = '''Content-Type: text/plain;
687 charset="iso-8859-1"
688 From: fubar <fubar@bork.bork.bork>
689 To: issue_tracker@your.tracker.email.domain.example
690 Message-Id: <dummy_test_message_id>
691 Subject: [issue] Testing...
693 This is a test submission of a new issue.
694 '''
695 message = cStringIO.StringIO(s)
696 handler = self.instance.MailGW(self.instance, self.db)
697 handler.trapExceptions = 0
698 self.assertRaises(Unauthorized, handler.main, message)
699 m = self.db.user.list()
700 m.sort()
701 self.assertEqual(l, m)
703 # now with the permission
704 p = self.db.security.getPermission('Email Registration')
705 self.db.security.role['anonymous'].permissions=[p]
706 handler = self.instance.MailGW(self.instance, self.db)
707 handler.trapExceptions = 0
708 message = cStringIO.StringIO(s)
709 handler.main(message)
710 m = self.db.user.list()
711 m.sort()
712 self.assertNotEqual(l, m)
714 def testEnc01(self):
715 self.doNewIssue()
716 message = cStringIO.StringIO('''Content-Type: text/plain;
717 charset="iso-8859-1"
718 From: mary <mary@test>
719 To: issue_tracker@your.tracker.email.domain.example
720 Message-Id: <followup_dummy_id>
721 In-Reply-To: <dummy_test_message_id>
722 Subject: [issue1] Testing...
723 Content-Type: text/plain;
724 charset="iso-8859-1"
725 Content-Transfer-Encoding: quoted-printable
727 A message with encoding (encoded oe =F6)
729 ''')
730 handler = self.instance.MailGW(self.instance, self.db)
731 handler.trapExceptions = 0
732 handler.main(message)
733 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
734 '''FROM: roundup-admin@your.tracker.email.domain.example
735 TO: chef@bork.bork.bork, richard@test
736 Content-Type: text/plain; charset=utf-8
737 Subject: [issue1] Testing...
738 To: chef@bork.bork.bork, richard@test
739 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
740 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
741 MIME-Version: 1.0
742 Message-Id: <followup_dummy_id>
743 In-Reply-To: <dummy_test_message_id>
744 X-Roundup-Name: Roundup issue tracker
745 X-Roundup-Loop: hello
746 Content-Transfer-Encoding: quoted-printable
749 Contrary, Mary <mary@test> added the comment:
751 A message with encoding (encoded oe =C3=B6)
753 ----------
754 status: unread -> chatting
755 _______________________________________________________________________
756 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
757 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
758 _______________________________________________________________________
759 ''')
762 def testMultipartEnc01(self):
763 self.doNewIssue()
764 message = cStringIO.StringIO('''Content-Type: text/plain;
765 charset="iso-8859-1"
766 From: mary <mary@test>
767 To: issue_tracker@your.tracker.email.domain.example
768 Message-Id: <followup_dummy_id>
769 In-Reply-To: <dummy_test_message_id>
770 Subject: [issue1] Testing...
771 Content-Type: multipart/mixed;
772 boundary="----_=_NextPart_000_01"
774 This message is in MIME format. Since your mail reader does not understand
775 this format, some or all of this message may not be legible.
777 ------_=_NextPart_000_01
778 Content-Type: text/plain;
779 charset="iso-8859-1"
780 Content-Transfer-Encoding: quoted-printable
782 A message with first part encoded (encoded oe =F6)
784 ''')
785 handler = self.instance.MailGW(self.instance, self.db)
786 handler.trapExceptions = 0
787 handler.main(message)
788 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
789 '''FROM: roundup-admin@your.tracker.email.domain.example
790 TO: chef@bork.bork.bork, richard@test
791 Content-Type: text/plain; charset=utf-8
792 Subject: [issue1] Testing...
793 To: chef@bork.bork.bork, richard@test
794 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
795 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
796 MIME-Version: 1.0
797 Message-Id: <followup_dummy_id>
798 In-Reply-To: <dummy_test_message_id>
799 X-Roundup-Name: Roundup issue tracker
800 X-Roundup-Loop: hello
801 Content-Transfer-Encoding: quoted-printable
804 Contrary, Mary <mary@test> added the comment:
806 A message with first part encoded (encoded oe =C3=B6)
808 ----------
809 status: unread -> chatting
810 _______________________________________________________________________
811 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
812 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
813 _______________________________________________________________________
814 ''')
816 def testContentDisposition(self):
817 self.doNewIssue()
818 message = cStringIO.StringIO('''Content-Type: text/plain;
819 charset="iso-8859-1"
820 From: mary <mary@test>
821 To: issue_tracker@your.tracker.email.domain.example
822 Message-Id: <followup_dummy_id>
823 In-Reply-To: <dummy_test_message_id>
824 Subject: [issue1] Testing...
825 Content-Type: multipart/mixed; boundary="bCsyhTFzCvuiizWE"
826 Content-Disposition: inline
829 --bCsyhTFzCvuiizWE
830 Content-Type: text/plain; charset=us-ascii
831 Content-Disposition: inline
833 test attachment binary
835 --bCsyhTFzCvuiizWE
836 Content-Type: application/octet-stream
837 Content-Disposition: attachment; filename="main.dvi"
839 xxxxxx
841 --bCsyhTFzCvuiizWE--
842 ''')
843 handler = self.instance.MailGW(self.instance, self.db)
844 handler.trapExceptions = 0
845 handler.main(message)
846 messages = self.db.issue.get('1', 'messages')
847 messages.sort()
848 file = self.db.msg.get(messages[-1], 'files')[0]
849 self.assertEqual(self.db.file.get(file, 'name'), 'main.dvi')
851 def testFollowupStupidQuoting(self):
852 self.doNewIssue()
854 message = cStringIO.StringIO('''Content-Type: text/plain;
855 charset="iso-8859-1"
856 From: richard <richard@test>
857 To: issue_tracker@your.tracker.email.domain.example
858 Message-Id: <followup_dummy_id>
859 In-Reply-To: <dummy_test_message_id>
860 Subject: Re: "[issue1] Testing... "
862 This is a followup
863 ''')
864 handler = self.instance.MailGW(self.instance, self.db)
865 handler.trapExceptions = 0
866 handler.main(message)
868 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
869 '''FROM: roundup-admin@your.tracker.email.domain.example
870 TO: chef@bork.bork.bork
871 Content-Type: text/plain; charset=utf-8
872 Subject: [issue1] Testing...
873 To: chef@bork.bork.bork
874 From: richard <issue_tracker@your.tracker.email.domain.example>
875 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
876 MIME-Version: 1.0
877 Message-Id: <followup_dummy_id>
878 In-Reply-To: <dummy_test_message_id>
879 X-Roundup-Name: Roundup issue tracker
880 X-Roundup-Loop: hello
881 Content-Transfer-Encoding: quoted-printable
884 richard <richard@test> added the comment:
886 This is a followup
888 ----------
889 status: unread -> chatting
890 _______________________________________________________________________
891 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
892 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
893 _______________________________________________________________________
894 ''')
896 def testEmailQuoting(self):
897 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'no'
898 self.innerTestQuoting('''This is a followup
899 ''')
901 def testEmailQuotingRemove(self):
902 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'yes'
903 self.innerTestQuoting('''Blah blah wrote:
904 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
905 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
906 >
908 This is a followup
909 ''')
911 def innerTestQuoting(self, expect):
912 nodeid = self.doNewIssue()
914 messages = self.db.issue.get(nodeid, 'messages')
916 message = cStringIO.StringIO('''Content-Type: text/plain;
917 charset="iso-8859-1"
918 From: richard <richard@test>
919 To: issue_tracker@your.tracker.email.domain.example
920 Message-Id: <followup_dummy_id>
921 In-Reply-To: <dummy_test_message_id>
922 Subject: Re: [issue1] Testing...
924 Blah blah wrote:
925 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
926 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
927 >
929 This is a followup
930 ''')
931 handler = self.instance.MailGW(self.instance, self.db)
932 handler.trapExceptions = 0
933 handler.main(message)
935 # figure the new message id
936 newmessages = self.db.issue.get(nodeid, 'messages')
937 for msg in messages:
938 newmessages.remove(msg)
939 messageid = newmessages[0]
941 self.compareStrings(self.db.msg.get(messageid, 'content'), expect)
943 def testUserLookup(self):
944 i = self.db.user.create(username='user1', address='user1@foo.com')
945 self.assertEqual(uidFromAddress(self.db, ('', 'user1@foo.com'), 0), i)
946 self.assertEqual(uidFromAddress(self.db, ('', 'USER1@foo.com'), 0), i)
947 i = self.db.user.create(username='user2', address='USER2@foo.com')
948 self.assertEqual(uidFromAddress(self.db, ('', 'USER2@foo.com'), 0), i)
949 self.assertEqual(uidFromAddress(self.db, ('', 'user2@foo.com'), 0), i)
951 def testUserCreate(self):
952 i = uidFromAddress(self.db, ('', 'user@foo.com'), 1)
953 self.assertNotEqual(uidFromAddress(self.db, ('', 'user@bar.com'), 1), i)
955 def testRFC2822(self):
956 ascii_header = "[issue243] This is a \"test\" - with 'quotation' marks"
957 unicode_header = '[issue244] \xd0\xb0\xd0\xbd\xd0\xb4\xd1\x80\xd0\xb5\xd0\xb9'
958 unicode_encoded = '=?utf-8?q?[issue244]_=D0=B0=D0=BD=D0=B4=D1=80=D0=B5=D0=B9?='
959 self.assertEqual(rfc2822.encode_header(ascii_header), ascii_header)
960 self.assertEqual(rfc2822.encode_header(unicode_header), unicode_encoded)
962 def suite():
963 l = [unittest.makeSuite(MailgwTestCase),
964 ]
965 return unittest.TestSuite(l)
968 # vim: set filetype=python ts=4 sw=4 et si