Code

- updated email package address formatting (deprecation)
[roundup.git] / test / test_mailgw.py
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.33 2002-11-05 22:59:46 richard Exp $
13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
15 # Note: Should parse emails according to RFC2822 instead of performing a
16 # literal string comparision.  Parsing the messages allows the tests to work for
17 # any legal serialization of an email.
18 #try :
19 #    import email
20 #except ImportError :
21 #    import rfc822 as email
23 from roundup.mailgw import MailGW, Unauthorized
24 from roundup import init, instance
26 # TODO: make this output only enough equal lines for context, not all of
27 # them
28 class DiffHelper:
29     def compareStrings(self, s2, s1):
30         '''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants
31            the first to be the "original" but in the calls in this file,
32            the second arg is the original. Ho hum.
33         '''
34         if s1 == s2:
35             return
37         # under python2.[12] we allow a difference of one trailing empty line.
38         if sys.version_info[0:2] == (2,1):
39             if s1+'\n' == s2:
40                 return
41         if sys.version_info[0:2] == (2,2):
42             if s1 == s2+'\n':
43                 return
44         
45         l1=s1.split('\n')
46         l2=s2.split('\n')
47         s = difflib.SequenceMatcher(None, l1, l2)
48         res = ['Generated message not correct (diff follows):']
49         for value, s1s, s1e, s2s, s2e in s.get_opcodes():
50             if value == 'equal':
51                 for i in range(s1s, s1e):
52                     res.append('  %s'%l1[i])
53             elif value == 'delete':
54                 for i in range(s1s, s1e):
55                     res.append('- %s'%l1[i])
56             elif value == 'insert':
57                 for i in range(s2s, s2e):
58                     res.append('+ %s'%l2[i])
59             elif value == 'replace':
60                 for i, j in zip(range(s1s, s1e), range(s2s, s2e)):
61                     res.append('- %s'%l1[i])
62                     res.append('+ %s'%l2[j])
64         raise AssertionError, '\n'.join(res)
66 class MailgwTestCase(unittest.TestCase, DiffHelper):
67     count = 0
68     schema = 'classic'
69     def setUp(self):
70         MailgwTestCase.count = MailgwTestCase.count + 1
71         self.dirname = '_test_mailgw_%s'%self.count
72         try:
73             shutil.rmtree(self.dirname)
74         except OSError, error:
75             if error.errno not in (errno.ENOENT, errno.ESRCH): raise
76         # create the instance
77         init.install(self.dirname, 'classic', 'anydbm')
78         init.initialise(self.dirname, 'sekrit')
79         # check we can load the package
80         self.instance = instance.open(self.dirname)
81         # and open the database
82         self.db = self.instance.open('admin')
83         self.db.user.create(username='Chef', address='chef@bork.bork.bork',
84             realname='Bork, Chef', roles='User')
85         self.db.user.create(username='richard', address='richard@test',
86             roles='User')
87         self.db.user.create(username='mary', address='mary@test',
88             roles='User', realname='Contrary, Mary')
89         self.db.user.create(username='john', address='john@test',
90             alternate_addresses='jondoe@test\njohn.doe@test', roles='User',
91             realname='John Doe')
93     def tearDown(self):
94         if os.path.exists(os.environ['SENDMAILDEBUG']):
95             os.remove(os.environ['SENDMAILDEBUG'])
96         self.db.close()
97         try:
98             shutil.rmtree(self.dirname)
99         except OSError, error:
100             if error.errno not in (errno.ENOENT, errno.ESRCH): raise
102     def doNewIssue(self):
103         message = cStringIO.StringIO('''Content-Type: text/plain;
104   charset="iso-8859-1"
105 From: Chef <chef@bork.bork.bork>
106 To: issue_tracker@your.tracker.email.domain.example
107 Cc: richard@test
108 Message-Id: <dummy_test_message_id>
109 Subject: [issue] Testing...
111 This is a test submission of a new issue.
112 ''')
113         handler = self.instance.MailGW(self.instance, self.db)
114         handler.trapExceptions = 0
115         nodeid = handler.main(message)
116         if os.path.exists(os.environ['SENDMAILDEBUG']):
117             error = open(os.environ['SENDMAILDEBUG']).read()
118             self.assertEqual('no error', error)
119         l = self.db.issue.get(nodeid, 'nosy')
120         l.sort()
121         self.assertEqual(l, ['3', '4'])
123     def testNewIssue(self):
124         self.doNewIssue()
126     def testNewIssueNosy(self):
127         self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
128         message = cStringIO.StringIO('''Content-Type: text/plain;
129   charset="iso-8859-1"
130 From: Chef <chef@bork.bork.bork>
131 To: issue_tracker@your.tracker.email.domain.example
132 Cc: richard@test
133 Message-Id: <dummy_test_message_id>
134 Subject: [issue] Testing...
136 This is a test submission of a new issue.
137 ''')
138         handler = self.instance.MailGW(self.instance, self.db)
139         handler.trapExceptions = 0
140         nodeid = handler.main(message)
141         if os.path.exists(os.environ['SENDMAILDEBUG']):
142             error = open(os.environ['SENDMAILDEBUG']).read()
143             self.assertEqual('no error', error)
144         l = self.db.issue.get(nodeid, 'nosy')
145         l.sort()
146         self.assertEqual(l, ['3', '4'])
148     def testAlternateAddress(self):
149         message = cStringIO.StringIO('''Content-Type: text/plain;
150   charset="iso-8859-1"
151 From: John Doe <john.doe@test>
152 To: issue_tracker@your.tracker.email.domain.example
153 Message-Id: <dummy_test_message_id>
154 Subject: [issue] Testing...
156 This is a test submission of a new issue.
157 ''')
158         userlist = self.db.user.list()
159         handler = self.instance.MailGW(self.instance, self.db)
160         handler.trapExceptions = 0
161         handler.main(message)
162         if os.path.exists(os.environ['SENDMAILDEBUG']):
163             error = open(os.environ['SENDMAILDEBUG']).read()
164             self.assertEqual('no error', error)
165         self.assertEqual(userlist, self.db.user.list(),
166             "user created when it shouldn't have been")
168     def testNewIssueNoClass(self):
169         message = cStringIO.StringIO('''Content-Type: text/plain;
170   charset="iso-8859-1"
171 From: Chef <chef@bork.bork.bork>
172 To: issue_tracker@your.tracker.email.domain.example
173 Cc: richard@test
174 Message-Id: <dummy_test_message_id>
175 Subject: Testing...
177 This is a test submission of a new issue.
178 ''')
179         handler = self.instance.MailGW(self.instance, self.db)
180         handler.trapExceptions = 0
181         handler.main(message)
182         if os.path.exists(os.environ['SENDMAILDEBUG']):
183             error = open(os.environ['SENDMAILDEBUG']).read()
184             self.assertEqual('no error', error)
186     def testNewIssueAuthMsg(self):
187         message = cStringIO.StringIO('''Content-Type: text/plain;
188   charset="iso-8859-1"
189 From: Chef <chef@bork.bork.bork>
190 To: issue_tracker@your.tracker.email.domain.example
191 Message-Id: <dummy_test_message_id>
192 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
194 This is a test submission of a new issue.
195 ''')
196         handler = self.instance.MailGW(self.instance, self.db)
197         handler.trapExceptions = 0
198         # TODO: fix the damn config - this is apalling
199         self.db.config.MESSAGES_TO_AUTHOR = 'yes'
200         handler.main(message)
202         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
203 '''FROM: roundup-admin@your.tracker.email.domain.example
204 TO: chef@bork.bork.bork, mary@test, richard@test
205 Content-Type: text/plain
206 Subject: [issue1] Testing...
207 To: chef@bork.bork.bork, mary@test, richard@test
208 From: "Bork, Chef" <issue_tracker@your.tracker.email.domain.example>
209 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
210 MIME-Version: 1.0
211 Message-Id: <dummy_test_message_id>
212 X-Roundup-Name: Roundup issue tracker
213 Content-Transfer-Encoding: quoted-printable
216 New submission from Bork, Chef <chef@bork.bork.bork>:
218 This is a test submission of a new issue.
221 ----------
222 assignedto: richard
223 messages: 1
224 nosy: Chef, mary, richard
225 status: unread
226 title: Testing...
227 _______________________________________________________________________
228 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
229 http://your.tracker.url.example/issue1
230 _______________________________________________________________________
231 ''')
233     # BUG
234     # def testMultipart(self):
235     #         '''With more than one part'''
236     #        see MultipartEnc tests: but if there is more than one part
237     #        we return a multipart/mixed and the boundary contains
238     #        the ip address of the test machine. 
240     # BUG should test some binary attamchent too.
242     def testSimpleFollowup(self):
243         self.doNewIssue()
244         message = cStringIO.StringIO('''Content-Type: text/plain;
245   charset="iso-8859-1"
246 From: mary <mary@test>
247 To: issue_tracker@your.tracker.email.domain.example
248 Message-Id: <followup_dummy_id>
249 In-Reply-To: <dummy_test_message_id>
250 Subject: [issue1] Testing...
252 This is a second followup
253 ''')
254         handler = self.instance.MailGW(self.instance, self.db)
255         handler.trapExceptions = 0
256         handler.main(message)
257         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
258 '''FROM: roundup-admin@your.tracker.email.domain.example
259 TO: chef@bork.bork.bork, richard@test
260 Content-Type: text/plain
261 Subject: [issue1] Testing...
262 To: chef@bork.bork.bork, richard@test
263 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
264 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
265 MIME-Version: 1.0
266 Message-Id: <followup_dummy_id>
267 In-Reply-To: <dummy_test_message_id>
268 X-Roundup-Name: Roundup issue tracker
269 Content-Transfer-Encoding: quoted-printable
272 Contrary, Mary <mary@test> added the comment:
274 This is a second followup
277 ----------
278 status: unread -> chatting
279 _______________________________________________________________________
280 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
281 http://your.tracker.url.example/issue1
282 _______________________________________________________________________
283 ''')
285     def testFollowup(self):
286         self.doNewIssue()
288         message = cStringIO.StringIO('''Content-Type: text/plain;
289   charset="iso-8859-1"
290 From: richard <richard@test>
291 To: issue_tracker@your.tracker.email.domain.example
292 Message-Id: <followup_dummy_id>
293 In-Reply-To: <dummy_test_message_id>
294 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
296 This is a followup
297 ''')
298         handler = self.instance.MailGW(self.instance, self.db)
299         handler.trapExceptions = 0
300         handler.main(message)
301         l = self.db.issue.get('1', 'nosy')
302         l.sort()
303         self.assertEqual(l, ['3', '4', '5', '6'])
305         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
306 '''FROM: roundup-admin@your.tracker.email.domain.example
307 TO: chef@bork.bork.bork, john@test, mary@test
308 Content-Type: text/plain
309 Subject: [issue1] Testing...
310 To: chef@bork.bork.bork, john@test, mary@test
311 From: richard <issue_tracker@your.tracker.email.domain.example>
312 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
313 MIME-Version: 1.0
314 Message-Id: <followup_dummy_id>
315 In-Reply-To: <dummy_test_message_id>
316 X-Roundup-Name: Roundup issue tracker
317 Content-Transfer-Encoding: quoted-printable
320 richard <richard@test> added the comment:
322 This is a followup
325 ----------
326 assignedto:  -> mary
327 nosy: +john, mary
328 status: unread -> chatting
329 _______________________________________________________________________
330 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
331 http://your.tracker.url.example/issue1
332 _______________________________________________________________________
333 ''')
335     def testFollowupTitleMatch(self):
336         self.doNewIssue()
337         message = cStringIO.StringIO('''Content-Type: text/plain;
338   charset="iso-8859-1"
339 From: richard <richard@test>
340 To: issue_tracker@your.tracker.email.domain.example
341 Message-Id: <followup_dummy_id>
342 In-Reply-To: <dummy_test_message_id>
343 Subject: Re: Testing... [assignedto=mary; nosy=+john]
345 This is a followup
346 ''')
347         handler = self.instance.MailGW(self.instance, self.db)
348         handler.trapExceptions = 0
349         handler.main(message)
351         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
352 '''FROM: roundup-admin@your.tracker.email.domain.example
353 TO: chef@bork.bork.bork, john@test, mary@test
354 Content-Type: text/plain
355 Subject: [issue1] Testing...
356 To: chef@bork.bork.bork, john@test, mary@test
357 From: richard <issue_tracker@your.tracker.email.domain.example>
358 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
359 MIME-Version: 1.0
360 Message-Id: <followup_dummy_id>
361 In-Reply-To: <dummy_test_message_id>
362 X-Roundup-Name: Roundup issue tracker
363 Content-Transfer-Encoding: quoted-printable
366 richard <richard@test> added the comment:
368 This is a followup
371 ----------
372 assignedto:  -> mary
373 nosy: +john, mary
374 status: unread -> chatting
375 _______________________________________________________________________
376 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
377 http://your.tracker.url.example/issue1
378 _______________________________________________________________________
379 ''')
381     def testFollowupNosyAuthor(self):
382         self.doNewIssue()
383         self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
384         message = cStringIO.StringIO('''Content-Type: text/plain;
385   charset="iso-8859-1"
386 From: john@test
387 To: issue_tracker@your.tracker.email.domain.example
388 Message-Id: <followup_dummy_id>
389 In-Reply-To: <dummy_test_message_id>
390 Subject: [issue1] Testing...
392 This is a followup
393 ''')
394         handler = self.instance.MailGW(self.instance, self.db)
395         handler.trapExceptions = 0
396         handler.main(message)
398         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
399 '''FROM: roundup-admin@your.tracker.email.domain.example
400 TO: chef@bork.bork.bork, richard@test
401 Content-Type: text/plain
402 Subject: [issue1] Testing...
403 To: chef@bork.bork.bork, richard@test
404 From: John Doe <issue_tracker@your.tracker.email.domain.example>
405 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
406 MIME-Version: 1.0
407 Message-Id: <followup_dummy_id>
408 In-Reply-To: <dummy_test_message_id>
409 X-Roundup-Name: Roundup issue tracker
410 Content-Transfer-Encoding: quoted-printable
413 John Doe <john@test> added the comment:
415 This is a followup
418 ----------
419 nosy: +john
420 status: unread -> chatting
421 _______________________________________________________________________
422 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
423 http://your.tracker.url.example/issue1
424 _______________________________________________________________________
426 ''')
428     def testFollowupNosyRecipients(self):
429         self.doNewIssue()
430         self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
431         message = cStringIO.StringIO('''Content-Type: text/plain;
432   charset="iso-8859-1"
433 From: richard@test
434 To: issue_tracker@your.tracker.email.domain.example
435 Cc: john@test
436 Message-Id: <followup_dummy_id>
437 In-Reply-To: <dummy_test_message_id>
438 Subject: [issue1] Testing...
440 This is a followup
441 ''')
442         handler = self.instance.MailGW(self.instance, self.db)
443         handler.trapExceptions = 0
444         handler.main(message)
446         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
447 '''FROM: roundup-admin@your.tracker.email.domain.example
448 TO: chef@bork.bork.bork
449 Content-Type: text/plain
450 Subject: [issue1] Testing...
451 To: chef@bork.bork.bork
452 From: richard <issue_tracker@your.tracker.email.domain.example>
453 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
454 MIME-Version: 1.0
455 Message-Id: <followup_dummy_id>
456 In-Reply-To: <dummy_test_message_id>
457 X-Roundup-Name: Roundup issue tracker
458 Content-Transfer-Encoding: quoted-printable
461 richard <richard@test> added the comment:
463 This is a followup
466 ----------
467 nosy: +john
468 status: unread -> chatting
469 _______________________________________________________________________
470 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
471 http://your.tracker.url.example/issue1
472 _______________________________________________________________________
474 ''')
476     def testFollowupNosyAuthorAndCopy(self):
477         self.doNewIssue()
478         self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
479         self.db.config.MESSAGES_TO_AUTHOR = 'yes'
480         message = cStringIO.StringIO('''Content-Type: text/plain;
481   charset="iso-8859-1"
482 From: john@test
483 To: issue_tracker@your.tracker.email.domain.example
484 Message-Id: <followup_dummy_id>
485 In-Reply-To: <dummy_test_message_id>
486 Subject: [issue1] Testing...
488 This is a followup
489 ''')
490         handler = self.instance.MailGW(self.instance, self.db)
491         handler.trapExceptions = 0
492         handler.main(message)
494         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
495 '''FROM: roundup-admin@your.tracker.email.domain.example
496 TO: chef@bork.bork.bork, john@test, richard@test
497 Content-Type: text/plain
498 Subject: [issue1] Testing...
499 To: chef@bork.bork.bork, john@test, richard@test
500 From: John Doe <issue_tracker@your.tracker.email.domain.example>
501 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
502 MIME-Version: 1.0
503 Message-Id: <followup_dummy_id>
504 In-Reply-To: <dummy_test_message_id>
505 X-Roundup-Name: Roundup issue tracker
506 Content-Transfer-Encoding: quoted-printable
509 John Doe <john@test> added the comment:
511 This is a followup
514 ----------
515 nosy: +john
516 status: unread -> chatting
517 _______________________________________________________________________
518 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
519 http://your.tracker.url.example/issue1
520 _______________________________________________________________________
522 ''')
524     def testFollowupNoNosyAuthor(self):
525         self.doNewIssue()
526         self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
527         message = cStringIO.StringIO('''Content-Type: text/plain;
528   charset="iso-8859-1"
529 From: john@test
530 To: issue_tracker@your.tracker.email.domain.example
531 Message-Id: <followup_dummy_id>
532 In-Reply-To: <dummy_test_message_id>
533 Subject: [issue1] Testing...
535 This is a followup
536 ''')
537         handler = self.instance.MailGW(self.instance, self.db)
538         handler.trapExceptions = 0
539         handler.main(message)
541         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
542 '''FROM: roundup-admin@your.tracker.email.domain.example
543 TO: chef@bork.bork.bork, richard@test
544 Content-Type: text/plain
545 Subject: [issue1] Testing...
546 To: chef@bork.bork.bork, richard@test
547 From: John Doe <issue_tracker@your.tracker.email.domain.example>
548 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
549 MIME-Version: 1.0
550 Message-Id: <followup_dummy_id>
551 In-Reply-To: <dummy_test_message_id>
552 X-Roundup-Name: Roundup issue tracker
553 Content-Transfer-Encoding: quoted-printable
556 John Doe <john@test> added the comment:
558 This is a followup
561 ----------
562 status: unread -> chatting
563 _______________________________________________________________________
564 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
565 http://your.tracker.url.example/issue1
566 _______________________________________________________________________
568 ''')
570     def testFollowupNoNosyRecipients(self):
571         self.doNewIssue()
572         self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
573         message = cStringIO.StringIO('''Content-Type: text/plain;
574   charset="iso-8859-1"
575 From: richard@test
576 To: issue_tracker@your.tracker.email.domain.example
577 Cc: john@test
578 Message-Id: <followup_dummy_id>
579 In-Reply-To: <dummy_test_message_id>
580 Subject: [issue1] Testing...
582 This is a followup
583 ''')
584         handler = self.instance.MailGW(self.instance, self.db)
585         handler.trapExceptions = 0
586         handler.main(message)
588         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
589 '''FROM: roundup-admin@your.tracker.email.domain.example
590 TO: chef@bork.bork.bork
591 Content-Type: text/plain
592 Subject: [issue1] Testing...
593 To: chef@bork.bork.bork
594 From: richard <issue_tracker@your.tracker.email.domain.example>
595 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
596 MIME-Version: 1.0
597 Message-Id: <followup_dummy_id>
598 In-Reply-To: <dummy_test_message_id>
599 X-Roundup-Name: Roundup issue tracker
600 Content-Transfer-Encoding: quoted-printable
603 richard <richard@test> added the comment:
605 This is a followup
608 ----------
609 status: unread -> chatting
610 _______________________________________________________________________
611 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
612 http://your.tracker.url.example/issue1
613 _______________________________________________________________________
615 ''')
617     def testNosyRemove(self):
618         self.doNewIssue()
620         message = cStringIO.StringIO('''Content-Type: text/plain;
621   charset="iso-8859-1"
622 From: richard <richard@test>
623 To: issue_tracker@your.tracker.email.domain.example
624 Message-Id: <followup_dummy_id>
625 In-Reply-To: <dummy_test_message_id>
626 Subject: [issue1] Testing... [nosy=-richard]
628 ''')
629         handler = self.instance.MailGW(self.instance, self.db)
630         handler.trapExceptions = 0
631         handler.main(message)
632         l = self.db.issue.get('1', 'nosy')
633         l.sort()
634         self.assertEqual(l, ['3'])
636         # NO NOSY MESSAGE SHOULD BE SENT!
637         self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG']))
639     def testNewUserAuthor(self):
640         # first without the permission
641         # heh... just ignore the API for a second ;)
642         self.db.security.role['Anonymous'].permissions=[]
643         anonid = self.db.user.lookup('anonymous')
644         self.db.user.set(anonid, roles='Anonymous')
646         self.db.security.hasPermission('Email Registration', anonid)
647         l = self.db.user.list()
648         l.sort()
649         s = '''Content-Type: text/plain;
650   charset="iso-8859-1"
651 From: fubar <fubar@bork.bork.bork>
652 To: issue_tracker@your.tracker.email.domain.example
653 Message-Id: <dummy_test_message_id>
654 Subject: [issue] Testing...
656 This is a test submission of a new issue.
657 '''
658         message = cStringIO.StringIO(s)
659         handler = self.instance.MailGW(self.instance, self.db)
660         handler.trapExceptions = 0
661         self.assertRaises(Unauthorized, handler.main, message)
662         m = self.db.user.list()
663         m.sort()
664         self.assertEqual(l, m)
666         # now with the permission
667         p = self.db.security.getPermission('Email Registration')
668         self.db.security.role['Anonymous'].permissions=[p]
669         handler = self.instance.MailGW(self.instance, self.db)
670         handler.trapExceptions = 0
671         message = cStringIO.StringIO(s)
672         handler.main(message)
673         m = self.db.user.list()
674         m.sort()
675         self.assertNotEqual(l, m)
677     def testEnc01(self):
678         self.doNewIssue()
679         message = cStringIO.StringIO('''Content-Type: text/plain;
680   charset="iso-8859-1"
681 From: mary <mary@test>
682 To: issue_tracker@your.tracker.email.domain.example
683 Message-Id: <followup_dummy_id>
684 In-Reply-To: <dummy_test_message_id>
685 Subject: [issue1] Testing...
686 Content-Type: text/plain;
687         charset="iso-8859-1"
688 Content-Transfer-Encoding: quoted-printable
690 A message with encoding (encoded oe =F6)
692 ''')
693         handler = self.instance.MailGW(self.instance, self.db)
694         handler.trapExceptions = 0
695         handler.main(message)
696         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
697 '''FROM: roundup-admin@your.tracker.email.domain.example
698 TO: chef@bork.bork.bork, richard@test
699 Content-Type: text/plain
700 Subject: [issue1] Testing...
701 To: chef@bork.bork.bork, richard@test
702 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
703 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
704 MIME-Version: 1.0
705 Message-Id: <followup_dummy_id>
706 In-Reply-To: <dummy_test_message_id>
707 X-Roundup-Name: Roundup issue tracker
708 Content-Transfer-Encoding: quoted-printable
711 Contrary, Mary <mary@test> added the comment:
713 A message with encoding (encoded oe =F6)
715 ----------
716 status: unread -> chatting
717 _______________________________________________________________________
718 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
719 http://your.tracker.url.example/issue1
720 _______________________________________________________________________
721 ''')
724     def testMultipartEnc01(self):
725         self.doNewIssue()
726         message = cStringIO.StringIO('''Content-Type: text/plain;
727   charset="iso-8859-1"
728 From: mary <mary@test>
729 To: issue_tracker@your.tracker.email.domain.example
730 Message-Id: <followup_dummy_id>
731 In-Reply-To: <dummy_test_message_id>
732 Subject: [issue1] Testing...
733 Content-Type: multipart/mixed;
734         boundary="----_=_NextPart_000_01"
736 This message is in MIME format. Since your mail reader does not understand
737 this format, some or all of this message may not be legible.
739 ------_=_NextPart_000_01
740 Content-Type: text/plain;
741         charset="iso-8859-1"
742 Content-Transfer-Encoding: quoted-printable
744 A message with first part encoded (encoded oe =F6)
746 ''')
747         handler = self.instance.MailGW(self.instance, self.db)
748         handler.trapExceptions = 0
749         handler.main(message)
750         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
751 '''FROM: roundup-admin@your.tracker.email.domain.example
752 TO: chef@bork.bork.bork, richard@test
753 Content-Type: text/plain
754 Subject: [issue1] Testing...
755 To: chef@bork.bork.bork, richard@test
756 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
757 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
758 MIME-Version: 1.0
759 Message-Id: <followup_dummy_id>
760 In-Reply-To: <dummy_test_message_id>
761 X-Roundup-Name: Roundup issue tracker
762 Content-Transfer-Encoding: quoted-printable
765 Contrary, Mary <mary@test> added the comment:
767 A message with first part encoded (encoded oe =F6)
769 ----------
770 status: unread -> chatting
771 _______________________________________________________________________
772 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
773 http://your.tracker.url.example/issue1
774 _______________________________________________________________________
775 ''')
777     def testFollowupStupidQuoting(self):
778         self.doNewIssue()
780         message = cStringIO.StringIO('''Content-Type: text/plain;
781   charset="iso-8859-1"
782 From: richard <richard@test>
783 To: issue_tracker@your.tracker.email.domain.example
784 Message-Id: <followup_dummy_id>
785 In-Reply-To: <dummy_test_message_id>
786 Subject: Re: "[issue1] Testing... "
788 This is a followup
789 ''')
790         handler = self.instance.MailGW(self.instance, self.db)
791         handler.trapExceptions = 0
792         handler.main(message)
794         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
795 '''FROM: roundup-admin@your.tracker.email.domain.example
796 TO: chef@bork.bork.bork
797 Content-Type: text/plain
798 Subject: [issue1] Testing...
799 To: chef@bork.bork.bork
800 From: richard <issue_tracker@your.tracker.email.domain.example>
801 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
802 MIME-Version: 1.0
803 Message-Id: <followup_dummy_id>
804 In-Reply-To: <dummy_test_message_id>
805 X-Roundup-Name: Roundup issue tracker
806 Content-Transfer-Encoding: quoted-printable
809 richard <richard@test> added the comment:
811 This is a followup
814 ----------
815 status: unread -> chatting
816 _______________________________________________________________________
817 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
818 http://your.tracker.url.example/issue1
819 _______________________________________________________________________
820 ''')
822 def suite():
823     l = [unittest.makeSuite(MailgwTestCase),
824     ]
825     return unittest.TestSuite(l)
828 # vim: set filetype=python ts=4 sw=4 et si