Code

Removed the unnecessary volatiledb and the related complications. Security
[roundup.git] / test / test_mailgw.py
index 58dda70f399fbabc71ddd27110557e01f7816fa6..6d531977479a332e96b65d867b3148df37480f8d 100644 (file)
@@ -8,25 +8,74 @@
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 #
-# $Id: test_mailgw.py,v 1.11 2002-02-14 23:38:12 richard Exp $
+# $Id: test_mailgw.py,v 1.25 2002-07-29 00:56:06 richard Exp $
 
-import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys
+import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
 
-from roundup.mailgw import MailGW
+# Note: Should parse emails according to RFC2822 instead of performing a
+# literal string comparision.  Parsing the messages allows the tests to work for
+# any legal serialization of an email.
+#try :
+#    import email
+#except ImportError :
+#    import rfc822 as email
+
+from roundup.mailgw import MailGW, Unauthorized
 from roundup import init, instance
 
-class MailgwTestCase(unittest.TestCase):
+# TODO: make this output only enough equal lines for context, not all of
+# them
+class DiffHelper:
+    def compareStrings(self, s2, s1):
+        '''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants
+           the first to be the "original" but in the calls in this file,
+           the second arg is the original. Ho hum.
+        '''
+        if s1 == s2:
+            return
+
+        # under python2.[12] we allow a difference of one trailing empty line.
+        if sys.version_info[0:2] == (2,1):
+            if s1+'\n' == s2:
+                return
+        if sys.version_info[0:2] == (2,2):
+            if s1 == s2+'\n':
+                return
+        
+        l1=s1.split('\n')
+        l2=s2.split('\n')
+        s = difflib.SequenceMatcher(None, l1, l2)
+        res = ['Generated message not correct (diff follows):']
+        for value, s1s, s1e, s2s, s2e in s.get_opcodes():
+            if value == 'equal':
+                for i in range(s1s, s1e):
+                    res.append('  %s'%l1[i])
+            elif value == 'delete':
+                for i in range(s1s, s1e):
+                    res.append('- %s'%l1[i])
+            elif value == 'insert':
+                for i in range(s2s, s2e):
+                    res.append('+ %s'%l2[i])
+            elif value == 'replace':
+                for i, j in zip(range(s1s, s1e), range(s2s, s2e)):
+                    res.append('- %s'%l1[i])
+                    res.append('+ %s'%l2[j])
+
+        raise AssertionError, '\n'.join(res)
+
+class MailgwTestCase(unittest.TestCase, DiffHelper):
     count = 0
     schema = 'classic'
     def setUp(self):
         MailgwTestCase.count = MailgwTestCase.count + 1
-        self.dirname = '_test_%s'%self.count
+        self.dirname = '_test_mailgw_%s'%self.count
         try:
             shutil.rmtree(self.dirname)
         except OSError, error:
             if error.errno not in (errno.ENOENT, errno.ESRCH): raise
         # create the instance
-        init.init(self.dirname, self.schema, 'anydbm', 'sekrit')
+        init.install(self.dirname, 'classic', 'anydbm')
+        init.initialise(self.dirname, 'sekrit')
         # check we can load the package
         self.instance = instance.open(self.dirname)
         # and open the database
@@ -34,7 +83,8 @@ class MailgwTestCase(unittest.TestCase):
         self.db.user.create(username='Chef', address='chef@bork.bork.bork')
         self.db.user.create(username='richard', address='richard@test')
         self.db.user.create(username='mary', address='mary@test')
-        self.db.user.create(username='john', address='john@test')
+        self.db.user.create(username='john', address='john@test',
+            alternate_addresses='jondoe@test\njohn.doe@test')
 
     def tearDown(self):
         if os.path.exists(os.environ['SENDMAILDEBUG']):
@@ -44,11 +94,36 @@ class MailgwTestCase(unittest.TestCase):
         except OSError, error:
             if error.errno not in (errno.ENOENT, errno.ESRCH): raise
 
+    def doNewIssue(self):
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: Chef <chef@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
+Cc: richard@test
+Message-Id: <dummy_test_message_id>
+Subject: [issue] Testing...
+
+This is a test submission of a new issue.
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        nodeid = handler.main(message)
+        if os.path.exists(os.environ['SENDMAILDEBUG']):
+            error = open(os.environ['SENDMAILDEBUG']).read()
+            self.assertEqual('no error', error)
+        l = self.db.issue.get(nodeid, 'nosy')
+        l.sort()
+        self.assertEqual(l, ['3', '4'])
+
     def testNewIssue(self):
+        self.doNewIssue()
+
+    def testNewIssueNosy(self):
+        self.instance.ADD_AUTHOR_TO_NOSY = 'yes'
         message = cStringIO.StringIO('''Content-Type: text/plain;
   charset="iso-8859-1"
-From: Chef <chef@bork.bork.bork
-To: issue_tracker@fill.me.in.
+From: Chef <chef@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
 Cc: richard@test
 Message-Id: <dummy_test_message_id>
 Subject: [issue] Testing...
@@ -56,6 +131,48 @@ Subject: [issue] Testing...
 This is a test submission of a new issue.
 ''')
         handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        nodeid = handler.main(message)
+        if os.path.exists(os.environ['SENDMAILDEBUG']):
+            error = open(os.environ['SENDMAILDEBUG']).read()
+            self.assertEqual('no error', error)
+        l = self.db.issue.get(nodeid, 'nosy')
+        l.sort()
+        self.assertEqual(l, ['3', '4'])
+
+    def testAlternateAddress(self):
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: John Doe <john.doe@test>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <dummy_test_message_id>
+Subject: [issue] Testing...
+
+This is a test submission of a new issue.
+''')
+        userlist = self.db.user.list()
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        handler.main(message)
+        if os.path.exists(os.environ['SENDMAILDEBUG']):
+            error = open(os.environ['SENDMAILDEBUG']).read()
+            self.assertEqual('no error', error)
+        self.assertEqual(userlist, self.db.user.list(),
+            "user created when it shouldn't have been")
+
+    def testNewIssueNoClass(self):
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: Chef <chef@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
+Cc: richard@test
+Message-Id: <dummy_test_message_id>
+Subject: Testing...
+
+This is a test submission of a new issue.
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
         handler.main(message)
         if os.path.exists(os.environ['SENDMAILDEBUG']):
             error = open(os.environ['SENDMAILDEBUG']).read()
@@ -64,29 +181,31 @@ This is a test submission of a new issue.
     def testNewIssueAuthMsg(self):
         message = cStringIO.StringIO('''Content-Type: text/plain;
   charset="iso-8859-1"
-From: Chef <chef@bork.bork.bork
-To: issue_tracker@fill.me.in.
+From: Chef <chef@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
 Message-Id: <dummy_test_message_id>
 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
 
 This is a test submission of a new issue.
 ''')
         handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
         # TODO: fix the damn config - this is apalling
         self.db.config.MESSAGES_TO_AUTHOR = 'yes'
         handler.main(message)
 
-        self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
-'''FROM: roundup-admin@fill.me.in.
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
 TO: chef@bork.bork.bork, mary@test, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, mary@test, richard@test
-From: Chef <issue_tracker@fill.me.in.>
-Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
+From: "Chef" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
 MIME-Version: 1.0
 Message-Id: <dummy_test_message_id>
 X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
 
 
 New submission from Chef <chef@bork.bork.bork>:
@@ -97,51 +216,100 @@ This is a test submission of a new issue.
 ----------
 assignedto: richard
 messages: 1
-nosy: mary, Chef, richard
+nosy: Chef, mary, richard
 status: unread
 title: Testing...
-___________________________________________________
-"Roundup issue tracker" <issue_tracker@fill.me.in.>
-http://some.useful.url/issue1
-___________________________________________________
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
 ''')
 
     # BUG
     # def testMultipart(self):
-    #  '''With more than one part'''
-    #  see MultipartEnc tests: but if there is more than one part
-    #  we return a multipart/mixed and the boundary contains
-    #  the ip address of the test machine. 
+    #         '''With more than one part'''
+    #        see MultipartEnc tests: but if there is more than one part
+    #        we return a multipart/mixed and the boundary contains
+    #        the ip address of the test machine. 
 
     # BUG should test some binary attamchent too.
 
+    def testSimpleFollowup(self):
+        self.doNewIssue()
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: mary <mary@test>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing...
+
+This is a second followup
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        handler.main(message)
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
+TO: chef@bork.bork.bork, richard@test
+Content-Type: text/plain
+Subject: [issue1] Testing...
+To: chef@bork.bork.bork, richard@test
+From: "mary" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+MIME-Version: 1.0
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
+
+
+mary <mary@test> added the comment:
+
+This is a second followup
+
+
+----------
+status: unread -> chatting
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+''')
+
     def testFollowup(self):
-        self.testNewIssue()
+        self.doNewIssue()
+
         message = cStringIO.StringIO('''Content-Type: text/plain;
   charset="iso-8859-1"
 From: richard <richard@test>
-To: issue_tracker@fill.me.in.
+To: issue_tracker@your.tracker.email.domain.example
 Message-Id: <followup_dummy_id>
 In-Reply-To: <dummy_test_message_id>
-Subject: [issue1] Testing... [assignedto=mary; nosy=john]
+Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
 
 This is a followup
 ''')
         handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
         handler.main(message)
+        l = self.db.issue.get('1', 'nosy')
+        l.sort()
+        self.assertEqual(l, ['3', '4', '5', '6'])
 
-        self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
-'''FROM: roundup-admin@fill.me.in.
-TO: chef@bork.bork.bork, mary@test, john@test
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
+TO: chef@bork.bork.bork, john@test, mary@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
-To: chef@bork.bork.bork, mary@test, john@test
-From: richard <issue_tracker@fill.me.in.>
-Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
+To: chef@bork.bork.bork, john@test, mary@test
+From: "richard" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
 MIME-Version: 1.0
 Message-Id: <followup_dummy_id>
 In-Reply-To: <dummy_test_message_id>
 X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
 
 
 richard <richard@test> added the comment:
@@ -153,59 +321,360 @@ This is a followup
 assignedto:  -> mary
 nosy: +mary, john
 status: unread -> chatting
-___________________________________________________
-"Roundup issue tracker" <issue_tracker@fill.me.in.>
-http://some.useful.url/issue1
-___________________________________________________
-''', 'Generated message not correct')
-
-    def testFollowup2(self):
-        self.testNewIssue()
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+''')
+
+    def testFollowupTitleMatch(self):
+        self.doNewIssue()
         message = cStringIO.StringIO('''Content-Type: text/plain;
   charset="iso-8859-1"
-From: mary <mary@test>
-To: issue_tracker@fill.me.in.
+From: richard <richard@test>
+To: issue_tracker@your.tracker.email.domain.example
 Message-Id: <followup_dummy_id>
 In-Reply-To: <dummy_test_message_id>
+Subject: Re: Testing... [assignedto=mary; nosy=+john]
+
+This is a followup
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        handler.main(message)
+
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
+TO: chef@bork.bork.bork, john@test, mary@test
+Content-Type: text/plain
 Subject: [issue1] Testing...
+To: chef@bork.bork.bork, john@test, mary@test
+From: "richard" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+MIME-Version: 1.0
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
 
-This is a second followup
+
+richard <richard@test> added the comment:
+
+This is a followup
+
+
+----------
+assignedto:  -> mary
+nosy: +mary, john
+status: unread -> chatting
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+''')
+
+    def testFollowupNosyAuthor(self):
+        self.doNewIssue()
+        self.db.config.ADD_AUTHOR_TO_NOSY = self.instance.ADD_AUTHOR_TO_NOSY = 'yes'
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: john@test
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing...
+
+This is a followup
 ''')
         handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
         handler.main(message)
-        self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
-'''FROM: roundup-admin@fill.me.in.
+
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
 TO: chef@bork.bork.bork, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, richard@test
-From: mary <issue_tracker@fill.me.in.>
-Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
+From: "john" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
 MIME-Version: 1.0
 Message-Id: <followup_dummy_id>
 In-Reply-To: <dummy_test_message_id>
 X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
 
 
-mary <mary@test> added the comment:
+john <john@test> added the comment:
 
-This is a second followup
+This is a followup
 
 
 ----------
+nosy: +john
 status: unread -> chatting
-___________________________________________________
-"Roundup issue tracker" <issue_tracker@fill.me.in.>
-http://some.useful.url/issue1
-___________________________________________________
-''', 'Generated message not correct')
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+
+''')
+
+    def testFollowupNosyRecipients(self):
+        self.doNewIssue()
+        self.db.config.ADD_RECIPIENTS_TO_NOSY = self.instance.ADD_RECIPIENTS_TO_NOSY = 'yes'
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: richard@test
+To: issue_tracker@your.tracker.email.domain.example
+Cc: john@test
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing...
+
+This is a followup
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        handler.main(message)
+
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
+TO: chef@bork.bork.bork
+Content-Type: text/plain
+Subject: [issue1] Testing...
+To: chef@bork.bork.bork
+From: "richard" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+MIME-Version: 1.0
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
+
+
+richard <richard@test> added the comment:
+
+This is a followup
+
+
+----------
+nosy: +john
+status: unread -> chatting
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+
+''')
+
+    def testFollowupNosyAuthorAndCopy(self):
+        self.doNewIssue()
+        self.db.config.ADD_AUTHOR_TO_NOSY = self.instance.ADD_AUTHOR_TO_NOSY = 'yes'
+        self.db.config.MESSAGES_TO_AUTHOR = 'yes'
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: john@test
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing...
+
+This is a followup
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        handler.main(message)
+
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
+TO: chef@bork.bork.bork, john@test, richard@test
+Content-Type: text/plain
+Subject: [issue1] Testing...
+To: chef@bork.bork.bork, john@test, richard@test
+From: "john" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+MIME-Version: 1.0
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
+
+
+john <john@test> added the comment:
+
+This is a followup
+
+
+----------
+nosy: +john
+status: unread -> chatting
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+
+''')
+
+    def testFollowupNoNosyAuthor(self):
+        self.doNewIssue()
+        self.instance.ADD_AUTHOR_TO_NOSY = 'no'
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: john@test
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing...
+
+This is a followup
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        handler.main(message)
+
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
+TO: chef@bork.bork.bork, richard@test
+Content-Type: text/plain
+Subject: [issue1] Testing...
+To: chef@bork.bork.bork, richard@test
+From: "john" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+MIME-Version: 1.0
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
+
+
+john <john@test> added the comment:
+
+This is a followup
+
+
+----------
+status: unread -> chatting
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+
+''')
+
+    def testFollowupNoNosyRecipients(self):
+        self.doNewIssue()
+        self.instance.ADD_RECIPIENTS_TO_NOSY = 'no'
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: richard@test
+To: issue_tracker@your.tracker.email.domain.example
+Cc: john@test
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing...
+
+This is a followup
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        handler.main(message)
+
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
+TO: chef@bork.bork.bork
+Content-Type: text/plain
+Subject: [issue1] Testing...
+To: chef@bork.bork.bork
+From: "richard" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+MIME-Version: 1.0
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
+
+
+richard <richard@test> added the comment:
+
+This is a followup
+
+
+----------
+status: unread -> chatting
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+
+''')
+
+    def testNosyRemove(self):
+        self.doNewIssue()
+
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: richard <richard@test>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing... [nosy=-richard]
+
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        handler.main(message)
+        l = self.db.issue.get('1', 'nosy')
+        l.sort()
+        self.assertEqual(l, ['3'])
+
+        # NO NOSY MESSAGE SHOULD BE SENT!
+        self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG']))
+
+    def testNewUserAuthor(self):
+        # first without the permission
+        # heh... just ignore the API for a second ;)
+        self.db.security.role['Anonymous'].permissions=[]
+        anonid = self.db.user.lookup('anonymous')
+        self.db.user.set(anonid, roles='Anonymous')
+
+        self.db.security.hasPermission('Email Registration', anonid)
+        l = self.db.user.list()
+        l.sort()
+        s = '''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: fubar <fubar@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <dummy_test_message_id>
+Subject: [issue] Testing...
+
+This is a test submission of a new issue.
+'''
+        message = cStringIO.StringIO(s)
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        self.assertRaises(Unauthorized, handler.main, message)
+        m = self.db.user.list()
+        m.sort()
+        self.assertEqual(l, m)
+
+        # now with the permission
+        p = self.db.security.getPermission('Email Registration')
+        self.db.security.role['Anonymous'].permissions=[p]
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
+        message = cStringIO.StringIO(s)
+        handler.main(message)
+        m = self.db.user.list()
+        m.sort()
+        self.assertNotEqual(l, m)
 
     def testEnc01(self):
-        self.testNewIssue()
+        self.doNewIssue()
         message = cStringIO.StringIO('''Content-Type: text/plain;
   charset="iso-8859-1"
 From: mary <mary@test>
-To: issue_tracker@fill.me.in.
+To: issue_tracker@your.tracker.email.domain.example
 Message-Id: <followup_dummy_id>
 In-Reply-To: <dummy_test_message_id>
 Subject: [issue1] Testing...
@@ -217,41 +686,42 @@ A message with encoding (encoded oe =F6)
 
 ''')
         handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
         handler.main(message)
-        message_data = open(os.environ['SENDMAILDEBUG']).read()
-        self.assertEqual(message_data,
-'''FROM: roundup-admin@fill.me.in.
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
 TO: chef@bork.bork.bork, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, richard@test
-From: mary <issue_tracker@fill.me.in.>
-Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
+From: "mary" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
 MIME-Version: 1.0
 Message-Id: <followup_dummy_id>
 In-Reply-To: <dummy_test_message_id>
 X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
 
 
 mary <mary@test> added the comment:
 
-A message with encoding (encoded oe ö)
+A message with encoding (encoded oe =F6)
 
 ----------
 status: unread -> chatting
-___________________________________________________
-"Roundup issue tracker" <issue_tracker@fill.me.in.>
-http://some.useful.url/issue1
-___________________________________________________
-''', 'Generated message not correct')
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+''')
 
 
     def testMultipartEnc01(self):
-        self.testNewIssue()
+        self.doNewIssue()
         message = cStringIO.StringIO('''Content-Type: text/plain;
   charset="iso-8859-1"
 From: mary <mary@test>
-To: issue_tracker@fill.me.in.
+To: issue_tracker@your.tracker.email.domain.example
 Message-Id: <followup_dummy_id>
 In-Reply-To: <dummy_test_message_id>
 Subject: [issue1] Testing...
@@ -270,46 +740,122 @@ A message with first part encoded (encoded oe =F6)
 
 ''')
         handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
         handler.main(message)
-        message_data = open(os.environ['SENDMAILDEBUG']).read()
-        self.assertEqual(message_data,
-'''FROM: roundup-admin@fill.me.in.
+        self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
 TO: chef@bork.bork.bork, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, richard@test
-From: mary <issue_tracker@fill.me.in.>
-Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
+From: "mary" <issue_tracker@your.tracker.email.domain.example>
+Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
 MIME-Version: 1.0
 Message-Id: <followup_dummy_id>
 In-Reply-To: <dummy_test_message_id>
 X-Roundup-Name: Roundup issue tracker
+Content-Transfer-Encoding: quoted-printable
 
 
 mary <mary@test> added the comment:
 
-A message with first part encoded (encoded oe ö)
+A message with first part encoded (encoded oe =F6)
 
 ----------
 status: unread -> chatting
-___________________________________________________
-"Roundup issue tracker" <issue_tracker@fill.me.in.>
-http://some.useful.url/issue1
-___________________________________________________
-''', 'Generated message not correct')
+_________________________________________________________________________
+"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
+http://your.tracker.url.example/issue1
+_________________________________________________________________________
+''')
 
 class ExtMailgwTestCase(MailgwTestCase):
     schema = 'extended'
 
 def suite():
-    l = [unittest.makeSuite(MailgwTestCase, 'test'),
-        unittest.makeSuite(ExtMailgwTestCase, 'test')
+    l = [unittest.makeSuite(MailgwTestCase),
+         unittest.makeSuite(ExtMailgwTestCase, 'test')
     ]
     return unittest.TestSuite(l)
 
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.24  2002/07/26 08:27:00  richard
+# Very close now. The cgi and mailgw now use the new security API. The two
+# templates have been migrated to that setup. Lots of unit tests. Still some
+# issue in the web form for editing Roles assigned to users.
+#
+# Revision 1.23  2002/07/14 02:02:43  richard
+# Fixed the unit tests for the new multilist controls in the mailgw
+#
+# Revision 1.22  2002/07/09 01:21:24  richard
+# Added ability for unit tests to turn off exception handling in mailgw so
+# that exceptions are reported earlier (and hence make sense).
+#
+# Revision 1.21  2002/06/18 03:59:59  dman13
+# Updated message strings to match the RFC822 address quoting performed
+# by the 'email' and 'rfc822' modules.  The verification really should
+# use a RFC2822 message parser rather than literal string comparisions
+# to allow for legal variations in messages.
+#
+# Revision 1.20  2002/05/29 01:16:17  richard
+# Sorry about this huge checkin! It's fixing a lot of related stuff in one go
+# though.
+#
+# . #541941 ] changing multilink properties by mail
+# . #526730 ] search for messages capability
+# . #505180 ] split MailGW.handle_Message
+#   - also changed cgi client since it was duplicating the functionality
+# . build htmlbase if tests are run using CVS checkout (removed note from
+#   installation.txt)
+# . don't create an empty message on email issue creation if the email is empty
+#
+# Revision 1.19  2002/05/23 04:26:05  richard
+# 'I must run unit tests before committing\n' * 100
+#
+# Revision 1.18  2002/05/15 03:27:16  richard
+#  . fixed SCRIPT_NAME in ZRoundup for instances not at top level of Zope
+#    (thanks dman)
+#  . fixed some sorting issues that were breaking some unit tests under py2.2
+#  . mailgw test output dir was confusing the init test (but only on 2.2 *shrug*)
+#
+# fixed bug in the init unit test that meant only the bsddb test ran if it
+# could (it clobbered the anydbm test)
+#
+# Revision 1.17  2002/05/02 07:56:34  richard
+# . added option to automatically add the authors and recipients of messages
+#   to the nosy lists with the options ADD_AUTHOR_TO_NOSY (default 'new') and
+#   ADD_RECIPIENTS_TO_NOSY (default 'new'). These settings emulate the current
+#   behaviour. Setting them to 'yes' will add the author/recipients to the nosy
+#   on messages that create issues and followup messages.
+# . added missing documentation for a few of the config option values
+#
+# Revision 1.16  2002/03/19 21:58:11  grubert
+#  . for python2.1 test_mailgw compareString allows an extra trailing empty line (for quopri.
+#
+# Revision 1.15  2002/03/19 06:37:00  richard
+# Made the email checking spit out a diff - much easier to spot the problem!
+#
+# Revision 1.14  2002/03/18 18:32:00  rochecompaan
+# All messages sent to the nosy list are now encoded as quoted-printable.
+#
+# Revision 1.13  2002/02/15 07:08:45  richard
+#  . Alternate email addresses are now available for users. See the MIGRATION
+#    file for info on how to activate the feature.
+#
+# Revision 1.12  2002/02/15 00:13:38  richard
+#  . #503204 ] mailgw needs a default class
+#     - partially done - the setting of additional properties can wait for a
+#       better configuration system.
+#
+# Revision 1.11  2002/02/14 23:38:12  richard
+# Fixed the unit tests for the mailgw re: the x-roundup-name header.
+# Also made the test runner more user-friendly:
+#   ./run_tests            - detect all tests in test/test_<name>.py and run them
+#   ./run_tests <name>     - run only test/test_<name>.py
+# eg ./run_tests mailgw    - run the mailgw test from test/test_mailgw.py
+#
 # Revision 1.10  2002/02/12 08:08:55  grubert
 #  . Clean up mail handling, multipart handling.
 #