X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=test%2Ftest_mailgw.py;h=e0789ae2d015f6b2ab51ae3172605e22ea4ff89e;hb=6ba44a7c3806ba5f40562a0e390605a25145a01b;hp=e15e2928585e441f7fc3c6eb08000e3d6e056c6b;hpb=f4d1da34f0662e6ebdd9e097ef1457f0d1db833c;p=roundup.git diff --git a/test/test_mailgw.py b/test/test_mailgw.py index e15e292..e0789ae 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -14,6 +14,14 @@ # TODO: test bcc import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822, time +from email.parser import FeedParser + + +try: + import pyme, pyme.core +except ImportError: + pyme = None + from cStringIO import StringIO @@ -21,6 +29,7 @@ if not os.environ.has_key('SENDMAILDEBUG'): os.environ['SENDMAILDEBUG'] = 'mail-test.log' SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] +from roundup import mailgw, i18n, roundupdb from roundup.mailgw import MailGW, Unauthorized, uidFromAddress, \ parseContent, IgnoreLoop, IgnoreBulk, MailUsageError, MailUsageHelp from roundup import init, instance, password, rfc2822, __version__ @@ -115,11 +124,13 @@ class DiffHelper: return res -class MailgwTestCase(unittest.TestCase, DiffHelper): +class MailgwTestAbstractBase(unittest.TestCase, DiffHelper): count = 0 schema = 'classic' def setUp(self): - MailgwTestCase.count = MailgwTestCase.count + 1 + self.old_translate_ = mailgw._ + roundupdb._ = mailgw._ = i18n.get_translation(language='C').gettext + self.__class__.count = self.__class__.count + 1 # and open the database / "instance" self.db = memorydb.create('admin') @@ -137,15 +148,26 @@ class MailgwTestCase(unittest.TestCase, DiffHelper): self.john_id = self.db.user.create(username='john', address='john@test.test', roles='User', realname='John Doe', alternate_addresses='jondoe@test.test\njohn.doe@test.test') + self.rgg_id = self.db.user.create(username='rgg', + address='rgg@test.test', roles='User') def tearDown(self): + roundupdb._ = mailgw._ = self.old_translate_ if os.path.exists(SENDMAILDEBUG): os.remove(SENDMAILDEBUG) self.db.close() - def _handle_mail(self, message): - handler = self.instance.MailGW(self.instance) - handler.trapExceptions = 0 + def _create_mailgw(self, message, args=()): + class MailGW(self.instance.MailGW): + def handle_message(self, message): + return self._handle_message(message) + handler = MailGW(self.instance, args) + handler.db = self.db + return handler + + def _handle_mail(self, message, args=(), trap_exc=0): + handler = self._create_mailgw(message, args) + handler.trapExceptions = trap_exc return handler.main(StringIO(message)) def _get_mail(self): @@ -155,6 +177,8 @@ class MailgwTestCase(unittest.TestCase, DiffHelper): finally: f.close() + # Normal test-case used for both non-pgp test and a test while pgp + # is enabled, so this test is run in both test suites. def testEmptyMessage(self): nodeid = self._handle_mail('''Content-Type: text/plain; charset="iso-8859-1" @@ -169,6 +193,9 @@ Subject: [issue] Testing... assert not os.path.exists(SENDMAILDEBUG) self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...') + +class MailgwTestCase(MailgwTestAbstractBase): + def testMessageWithFromInIt(self): nodeid = self._handle_mail('''Content-Type: text/plain; charset="iso-8859-1" @@ -182,8 +209,85 @@ Subject: [issue] Testing... From here to there! ''') assert not os.path.exists(SENDMAILDEBUG) - msgid = self.db.issue.get(nodeid, 'msg')[0] - self.assertEqual(self.db.issue.get(msgid, 'content'), 'From here to there!') + msgid = self.db.issue.get(nodeid, 'messages')[0] + self.assertEqual(self.db.msg.get(msgid, 'content'), 'From here to there!') + + def testNoMessageId(self): + self.instance.config['MAIL_DOMAIN'] = 'example.com' + nodeid = self._handle_mail('''Content-Type: text/plain; + charset="iso-8859-1" +From: Chef +To: issue_tracker@your.tracker.email.domain.example +Cc: richard@test.test +Reply-To: chef@bork.bork.bork +Subject: [issue] Testing... + +Hi there! +''') + assert not os.path.exists(SENDMAILDEBUG) + msgid = self.db.issue.get(nodeid, 'messages')[0] + messageid = self.db.msg.get(msgid, 'messageid') + x1, x2 = messageid.split('@') + self.assertEqual(x2, 'example.com>') + x = x1.split('.')[-1] + self.assertEqual(x, 'issueNone') + nodeid = self._handle_mail('''Content-Type: text/plain; + charset="iso-8859-1" +From: Chef +To: issue_tracker@your.tracker.email.domain.example +Subject: [issue%(nodeid)s] Testing... + +Just a test reply +'''%locals()) + msgid = self.db.issue.get(nodeid, 'messages')[-1] + messageid = self.db.msg.get(msgid, 'messageid') + x1, x2 = messageid.split('@') + self.assertEqual(x2, 'example.com>') + x = x1.split('.')[-1] + self.assertEqual(x, "issue%s"%nodeid) + + def testOptions(self): + nodeid = self._handle_mail('''Content-Type: text/plain; + charset="iso-8859-1" +From: Chef +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +Reply-To: chef@bork.bork.bork +Subject: [issue] Testing... + +Hi there! +''', (('-C', 'issue'), ('-S', 'status=chatting;priority=critical'))) + self.assertEqual(self.db.issue.get(nodeid, 'status'), '3') + self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1') + + def testOptionsMulti(self): + nodeid = self._handle_mail('''Content-Type: text/plain; + charset="iso-8859-1" +From: Chef +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +Reply-To: chef@bork.bork.bork +Subject: [issue] Testing... + +Hi there! +''', (('-C', 'issue'), ('-S', 'status=chatting'), ('-S', 'priority=critical'))) + self.assertEqual(self.db.issue.get(nodeid, 'status'), '3') + self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1') + + def testOptionClass(self): + nodeid = self._handle_mail('''Content-Type: text/plain; + charset="iso-8859-1" +From: Chef +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +Reply-To: chef@bork.bork.bork +Subject: [issue] Testing... [status=chatting;priority=critical] + +Hi there! +''', (('-c', 'issue'),)) + self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...') + self.assertEqual(self.db.issue.get(nodeid, 'status'), '3') + self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1') def doNewIssue(self): nodeid = self._handle_mail('''Content-Type: text/plain; @@ -444,6 +548,77 @@ SnVzdCBhIHRlc3QK --bCsyhTFzCvuiizWF-- --bxyzzy-- +''' + + multipart_msg_latin1 = '''From: mary +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +In-Reply-To: +Subject: [issue1] Testing... +Content-Type: multipart/alternative; boundary=001485f339f8f361fb049188dbba + + +--001485f339f8f361fb049188dbba +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: quoted-printable + +umlaut =E4=F6=FC=C4=D6=DC=DF + +--001485f339f8f361fb049188dbba +Content-Type: text/html; charset=ISO-8859-1 +Content-Transfer-Encoding: quoted-printable + +umlaut =E4=F6=FC=C4=D6=DC=DF + +--001485f339f8f361fb049188dbba-- +''' + + multipart_msg_rfc822 = '''From: mary +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +In-Reply-To: +Subject: [issue1] Testing... +Content-Type: multipart/mixed; boundary=001485f339f8f361fb049188dbba + +This is a multi-part message in MIME format. +--001485f339f8f361fb049188dbba +Content-Type: text/plain; charset=ISO-8859-15 +Content-Transfer-Encoding: 7bit + +First part: Text + +--001485f339f8f361fb049188dbba +Content-Type: message/rfc822; name="Fwd: Original email subject.eml" +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; filename="Fwd: Original email subject.eml" + +Message-Id: +In-Reply-To: +MIME-Version: 1.0 +Subject: Fwd: Original email subject +Date: Mon, 23 Aug 2010 08:23:33 +0200 +Content-Type: multipart/alternative; boundary="090500050101020406060002" + +This is a multi-part message in MIME format. +--090500050101020406060002 +Content-Type: text/plain; charset=ISO-8859-15; format=flowed +Content-Transfer-Encoding: 7bit + +some text in inner email +======================== + +--090500050101020406060002 +Content-Type: text/html; charset=ISO-8859-15 +Content-Transfer-Encoding: 7bit + + +some text in inner email +======================== + + +--090500050101020406060002-- + +--001485f339f8f361fb049188dbba-- ''' def testMultipartKeepAlternatives(self): @@ -463,6 +638,68 @@ SnVzdCBhIHRlc3QK self.assertEqual(f.content, content [n]) self.assertEqual(msg.content, 'test attachment second text/plain') + def testMultipartSeveralAttachmentMessages(self): + self.doNewIssue() + self._handle_mail(self.multipart_msg) + messages = self.db.issue.get('1', 'messages') + messages.sort() + self.assertEqual(messages[-1], '2') + msg = self.db.msg.getnode (messages[-1]) + self.assertEqual(len(msg.files), 5) + issue = self.db.issue.getnode ('1') + self.assertEqual(len(issue.files), 5) + names = {0 : 'first.dvi', 4 : 'second.dvi'} + content = {3 : 'test attachment third text/plain\n', + 4 : 'Just a test\n'} + for n, id in enumerate (msg.files): + f = self.db.file.getnode (id) + self.assertEqual(f.name, names.get (n, 'unnamed')) + if n in content : + self.assertEqual(f.content, content [n]) + self.assertEqual(msg.content, 'test attachment second text/plain') + self.assertEqual(msg.files, ['1', '2', '3', '4', '5']) + self.assertEqual(issue.files, ['1', '2', '3', '4', '5']) + + self._handle_mail(self.multipart_msg) + issue = self.db.issue.getnode ('1') + self.assertEqual(len(issue.files), 10) + messages = self.db.issue.get('1', 'messages') + messages.sort() + self.assertEqual(messages[-1], '3') + msg = self.db.msg.getnode (messages[-1]) + self.assertEqual(issue.files, [str(i+1) for i in range(10)]) + self.assertEqual(msg.files, ['6', '7', '8', '9', '10']) + + def testMultipartKeepFiles(self): + self.doNewIssue() + self._handle_mail(self.multipart_msg) + messages = self.db.issue.get('1', 'messages') + messages.sort() + msg = self.db.msg.getnode (messages[-1]) + self.assertEqual(len(msg.files), 5) + issue = self.db.issue.getnode ('1') + self.assertEqual(len(issue.files), 5) + names = {0 : 'first.dvi', 4 : 'second.dvi'} + content = {3 : 'test attachment third text/plain\n', + 4 : 'Just a test\n'} + for n, id in enumerate (msg.files): + f = self.db.file.getnode (id) + self.assertEqual(f.name, names.get (n, 'unnamed')) + if n in content : + self.assertEqual(f.content, content [n]) + self.assertEqual(msg.content, 'test attachment second text/plain') + self._handle_mail('''From: mary +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +In-Reply-To: +Subject: [issue1] Testing... + +This ist a message without attachment +''') + issue = self.db.issue.getnode ('1') + self.assertEqual(len(issue.files), 5) + self.assertEqual(issue.files, ['1', '2', '3', '4', '5']) + def testMultipartDropAlternatives(self): self.doNewIssue() self.db.config.MAILGW_IGNORE_ALTERNATIVES = True @@ -470,7 +707,7 @@ SnVzdCBhIHRlc3QK messages = self.db.issue.get('1', 'messages') messages.sort() msg = self.db.msg.getnode (messages[-1]) - assert(len(msg.files) == 2) + self.assertEqual(len(msg.files), 2) names = {1 : 'second.dvi'} content = {0 : 'test attachment third text/plain\n', 1 : 'Just a test\n'} @@ -481,6 +718,333 @@ SnVzdCBhIHRlc3QK self.assertEqual(f.content, content [n]) self.assertEqual(msg.content, 'test attachment second text/plain') + def testMultipartCharsetUTF8NoAttach(self): + c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' + self.doNewIssue() + self.db.config.NOSY_MAX_ATTACHMENT_SIZE = 0 + self._handle_mail(self.multipart_msg_latin1) + messages = self.db.issue.get('1', 'messages') + messages.sort() + msg = self.db.msg.getnode (messages[-1]) + self.assertEqual(len(msg.files), 1) + name = 'unnamed' + content = '' + c + '\n' + for n, id in enumerate (msg.files): + f = self.db.file.getnode (id) + self.assertEqual(f.name, name) + self.assertEqual(f.content, content) + self.assertEqual(msg.content, c) + self.compareMessages(self._get_mail(), +'''FROM: roundup-admin@your.tracker.email.domain.example +TO: chef@bork.bork.bork, richard@test.test +Content-Type: text/plain; charset="utf-8" +Subject: [issue1] Testing... +To: chef@bork.bork.bork, richard@test.test +From: "Contrary, Mary" +Reply-To: Roundup issue tracker + +MIME-Version: 1.0 +Message-Id: +In-Reply-To: +X-Roundup-Name: Roundup issue tracker +X-Roundup-Loop: hello +X-Roundup-Issue-Status: chatting +X-Roundup-Issue-Files: unnamed +Content-Transfer-Encoding: quoted-printable + + +Contrary, Mary added the comment: + +umlaut =C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F +File 'unnamed' not attached - you can download it from http://tracker.examp= +le/cgi-bin/roundup.cgi/bugs/file1. + +---------- +status: unread -> chatting + +_______________________________________________________________________ +Roundup issue tracker + +_______________________________________________________________________ +''') + + def testMultipartCharsetLatin1NoAttach(self): + c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' + self.doNewIssue() + self.db.config.NOSY_MAX_ATTACHMENT_SIZE = 0 + self.db.config.MAIL_CHARSET = 'iso-8859-1' + self._handle_mail(self.multipart_msg_latin1) + messages = self.db.issue.get('1', 'messages') + messages.sort() + msg = self.db.msg.getnode (messages[-1]) + self.assertEqual(len(msg.files), 1) + name = 'unnamed' + content = '' + c + '\n' + for n, id in enumerate (msg.files): + f = self.db.file.getnode (id) + self.assertEqual(f.name, name) + self.assertEqual(f.content, content) + self.assertEqual(msg.content, c) + self.compareMessages(self._get_mail(), +'''FROM: roundup-admin@your.tracker.email.domain.example +TO: chef@bork.bork.bork, richard@test.test +Content-Type: text/plain; charset="iso-8859-1" +Subject: [issue1] Testing... +To: chef@bork.bork.bork, richard@test.test +From: "Contrary, Mary" +Reply-To: Roundup issue tracker + +MIME-Version: 1.0 +Message-Id: +In-Reply-To: +X-Roundup-Name: Roundup issue tracker +X-Roundup-Loop: hello +X-Roundup-Issue-Status: chatting +X-Roundup-Issue-Files: unnamed +Content-Transfer-Encoding: quoted-printable + + +Contrary, Mary added the comment: + +umlaut =E4=F6=FC=C4=D6=DC=DF +File 'unnamed' not attached - you can download it from http://tracker.examp= +le/cgi-bin/roundup.cgi/bugs/file1. + +---------- +status: unread -> chatting + +_______________________________________________________________________ +Roundup issue tracker + +_______________________________________________________________________ +''') + + def testMultipartCharsetUTF8AttachFile(self): + c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' + self.doNewIssue() + self._handle_mail(self.multipart_msg_latin1) + messages = self.db.issue.get('1', 'messages') + messages.sort() + msg = self.db.msg.getnode (messages[-1]) + self.assertEqual(len(msg.files), 1) + name = 'unnamed' + content = '' + c + '\n' + for n, id in enumerate (msg.files): + f = self.db.file.getnode (id) + self.assertEqual(f.name, name) + self.assertEqual(f.content, content) + self.assertEqual(msg.content, c) + self.compareMessages(self._get_mail(), +'''FROM: roundup-admin@your.tracker.email.domain.example +TO: chef@bork.bork.bork, richard@test.test +Content-Type: multipart/mixed; boundary="utf-8" +Subject: [issue1] Testing... +To: chef@bork.bork.bork, richard@test.test +From: "Contrary, Mary" +Reply-To: Roundup issue tracker + +MIME-Version: 1.0 +Message-Id: +In-Reply-To: +X-Roundup-Name: Roundup issue tracker +X-Roundup-Loop: hello +X-Roundup-Issue-Status: chatting +X-Roundup-Issue-Files: unnamed +Content-Transfer-Encoding: quoted-printable + + +--utf-8 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: quoted-printable + + +Contrary, Mary added the comment: + +umlaut =C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F + +---------- +status: unread -> chatting + +_______________________________________________________________________ +Roundup issue tracker + +_______________________________________________________________________ +--utf-8 +Content-Type: text/html +MIME-Version: 1.0 +Content-Transfer-Encoding: base64 +Content-Disposition: attachment; + filename="unnamed" + +PGh0bWw+dW1sYXV0IMOkw7bDvMOEw5bDnMOfPC9odG1sPgo= + +--utf-8-- +''') + + def testMultipartCharsetLatin1AttachFile(self): + c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' + self.doNewIssue() + self.db.config.MAIL_CHARSET = 'iso-8859-1' + self._handle_mail(self.multipart_msg_latin1) + messages = self.db.issue.get('1', 'messages') + messages.sort() + msg = self.db.msg.getnode (messages[-1]) + self.assertEqual(len(msg.files), 1) + name = 'unnamed' + content = '' + c + '\n' + for n, id in enumerate (msg.files): + f = self.db.file.getnode (id) + self.assertEqual(f.name, name) + self.assertEqual(f.content, content) + self.assertEqual(msg.content, c) + self.compareMessages(self._get_mail(), +'''FROM: roundup-admin@your.tracker.email.domain.example +TO: chef@bork.bork.bork, richard@test.test +Content-Type: multipart/mixed; boundary="utf-8" +Subject: [issue1] Testing... +To: chef@bork.bork.bork, richard@test.test +From: "Contrary, Mary" +Reply-To: Roundup issue tracker + +MIME-Version: 1.0 +Message-Id: +In-Reply-To: +X-Roundup-Name: Roundup issue tracker +X-Roundup-Loop: hello +X-Roundup-Issue-Status: chatting +X-Roundup-Issue-Files: unnamed +Content-Transfer-Encoding: quoted-printable + + +--utf-8 +MIME-Version: 1.0 +Content-Type: text/plain; charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + + +Contrary, Mary added the comment: + +umlaut =E4=F6=FC=C4=D6=DC=DF + +---------- +status: unread -> chatting + +_______________________________________________________________________ +Roundup issue tracker + +_______________________________________________________________________ +--utf-8 +Content-Type: text/html +MIME-Version: 1.0 +Content-Transfer-Encoding: base64 +Content-Disposition: attachment; + filename="unnamed" + +PGh0bWw+dW1sYXV0IMOkw7bDvMOEw5bDnMOfPC9odG1sPgo= + +--utf-8-- +''') + + def testMultipartRFC822(self): + self.doNewIssue() + self._handle_mail(self.multipart_msg_rfc822) + messages = self.db.issue.get('1', 'messages') + messages.sort() + msg = self.db.msg.getnode (messages[-1]) + self.assertEqual(len(msg.files), 1) + name = "Fwd: Original email subject.eml" + for n, id in enumerate (msg.files): + f = self.db.file.getnode (id) + self.assertEqual(f.name, name) + self.assertEqual(msg.content, 'First part: Text') + self.compareMessages(self._get_mail(), +'''TO: chef@bork.bork.bork, richard@test.test +Content-Type: text/plain; charset="utf-8" +Subject: [issue1] Testing... +To: chef@bork.bork.bork, richard@test.test +From: "Contrary, Mary" +Reply-To: Roundup issue tracker + +MIME-Version: 1.0 +Message-Id: +In-Reply-To: +X-Roundup-Name: Roundup issue tracker +X-Roundup-Loop: hello +X-Roundup-Issue-Status: chatting +X-Roundup-Issue-Files: Fwd: Original email subject.eml +Content-Transfer-Encoding: quoted-printable + + +--utf-8 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: quoted-printable + + +Contrary, Mary added the comment: + +First part: Text + +---------- +status: unread -> chatting + +_______________________________________________________________________ +Roundup issue tracker + +_______________________________________________________________________ +--utf-8 +Content-Type: message/rfc822 +MIME-Version: 1.0 +Content-Disposition: attachment; + filename="Fwd: Original email subject.eml" + +Message-Id: +In-Reply-To: +MIME-Version: 1.0 +Subject: Fwd: Original email subject +Date: Mon, 23 Aug 2010 08:23:33 +0200 +Content-Type: multipart/alternative; boundary="090500050101020406060002" + +This is a multi-part message in MIME format. +--090500050101020406060002 +Content-Type: text/plain; charset=ISO-8859-15; format=flowed +Content-Transfer-Encoding: 7bit + +some text in inner email +======================== + +--090500050101020406060002 +Content-Type: text/html; charset=ISO-8859-15 +Content-Transfer-Encoding: 7bit + + +some text in inner email +======================== + + +--090500050101020406060002-- + +--utf-8-- +''') + + def testMultipartRFC822Unpack(self): + self.doNewIssue() + self.db.config.MAILGW_UNPACK_RFC822 = True + self._handle_mail(self.multipart_msg_rfc822) + messages = self.db.issue.get('1', 'messages') + messages.sort() + msg = self.db.msg.getnode (messages[-1]) + self.assertEqual(len(msg.files), 2) + t = 'some text in inner email\n========================\n' + content = {0 : t, 1 : '\n' + t + '\n'} + for n, id in enumerate (msg.files): + f = self.db.file.getnode (id) + self.assertEqual(f.name, 'unnamed') + if n in content : + self.assertEqual(f.content, content [n]) + self.assertEqual(msg.content, 'First part: Text') + def testSimpleFollowup(self): self.doNewIssue() self._handle_mail('''Content-Type: text/plain; @@ -573,6 +1137,154 @@ _______________________________________________________________________ Roundup issue tracker _______________________________________________________________________ +''') + + def testFollowupNoSubjectChange(self): + self.db.config.MAILGW_SUBJECT_UPDATES_TITLE = 'no' + self.doNewIssue() + + self._handle_mail('''Content-Type: text/plain; + charset="iso-8859-1" +From: richard +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +In-Reply-To: +Subject: [issue1] Wrzlbrmft... [assignedto=mary; nosy=+john] + +This is a followup +''') + l = self.db.issue.get('1', 'nosy') + l.sort() + self.assertEqual(l, [self.chef_id, self.richard_id, self.mary_id, + self.john_id]) + + self.compareMessages(self._get_mail(), +'''FROM: roundup-admin@your.tracker.email.domain.example +TO: chef@bork.bork.bork, john@test.test, mary@test.test +Content-Type: text/plain; charset="utf-8" +Subject: [issue1] Testing... +To: chef@bork.bork.bork, john@test.test, mary@test.test +From: richard +Reply-To: Roundup issue tracker + +MIME-Version: 1.0 +Message-Id: +In-Reply-To: +X-Roundup-Name: Roundup issue tracker +X-Roundup-Loop: hello +X-Roundup-Issue-Status: chatting +Content-Transfer-Encoding: quoted-printable + + +richard added the comment: + +This is a followup + +---------- +assignedto: -> mary +nosy: +john, mary +status: unread -> chatting + +_______________________________________________________________________ +Roundup issue tracker + +_______________________________________________________________________ +''') + self.assertEqual(self.db.issue.get('1','title'), 'Testing...') + + def testFollowupExplicitSubjectChange(self): + self.doNewIssue() + + self._handle_mail('''Content-Type: text/plain; + charset="iso-8859-1" +From: richard +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +In-Reply-To: +Subject: [issue1] Wrzlbrmft... [assignedto=mary; nosy=+john; title=new title] + +This is a followup +''') + l = self.db.issue.get('1', 'nosy') + l.sort() + self.assertEqual(l, [self.chef_id, self.richard_id, self.mary_id, + self.john_id]) + + self.compareMessages(self._get_mail(), +'''FROM: roundup-admin@your.tracker.email.domain.example +TO: chef@bork.bork.bork, john@test.test, mary@test.test +Content-Type: text/plain; charset="utf-8" +Subject: [issue1] new title +To: chef@bork.bork.bork, john@test.test, mary@test.test +From: richard +Reply-To: Roundup issue tracker + +MIME-Version: 1.0 +Message-Id: +In-Reply-To: +X-Roundup-Name: Roundup issue tracker +X-Roundup-Loop: hello +X-Roundup-Issue-Status: chatting +Content-Transfer-Encoding: quoted-printable + + +richard added the comment: + +This is a followup + +---------- +assignedto: -> mary +nosy: +john, mary +status: unread -> chatting +title: Testing... -> new title + +_______________________________________________________________________ +Roundup issue tracker + +_______________________________________________________________________ +''') + + def testNosyGeneration(self): + self.db.issue.create(title='test') + + # create a nosy message + msg = self.db.msg.create(content='This is a test', + author=self.richard_id, messageid='') + self.db.journaltag = 'richard' + l = self.db.issue.create(title='test', messages=[msg], + nosy=[self.chef_id, self.mary_id, self.john_id]) + + self.compareMessages(self._get_mail(), +'''FROM: roundup-admin@your.tracker.email.domain.example +TO: chef@bork.bork.bork, john@test.test, mary@test.test +Content-Type: text/plain; charset="utf-8" +Subject: [issue2] test +To: chef@bork.bork.bork, john@test.test, mary@test.test +From: richard +Reply-To: Roundup issue tracker + +MIME-Version: 1.0 +Message-Id: +X-Roundup-Name: Roundup issue tracker +X-Roundup-Loop: hello +X-Roundup-Issue-Status: unread +Content-Transfer-Encoding: quoted-printable + + +New submission from richard : + +This is a test + +---------- +messages: 1 +nosy: Chef, john, mary, richard +status: unread +title: test + +_______________________________________________________________________ +Roundup issue tracker + +_______________________________________________________________________ ''') def testPropertyChangeOnly(self): @@ -582,7 +1294,7 @@ _______________________________________________________________________ # reconstruct old behaviour: This would reuse the # database-handle from the doNewIssue above which has committed # as user "Chef". So we close and reopen the db as that user. - self.db.close() + #self.db.close() actually don't close 'cos this empties memorydb self.db = self.instance.open('Chef') self.db.issue.set('1', assignedto=self.chef_id) self.db.commit() @@ -607,6 +1319,7 @@ X-Roundup-Name: Roundup issue tracker X-Roundup-Loop: hello X-Roundup-Issue-Status: unread X-Roundup-Version: 1.3.3 +In-Reply-To: MIME-Version: 1.0 Reply-To: Roundup issue tracker @@ -1032,6 +1745,7 @@ Subject: [issue1] Testing... [nosy=-richard] assert not os.path.exists(SENDMAILDEBUG) def testNewUserAuthor(self): + self.db.commit() l = self.db.user.list() l.sort() message = '''Content-Type: text/plain; @@ -1079,7 +1793,7 @@ Unknown address: fubar@bork.bork.bork """) assert not body_diff, body_diff else: - raise AssertionError, "Unathorized not raised when handling mail" + raise AssertionError, "Unauthorized not raised when handling mail" # Make sure list of users is the same as before. m = self.db.user.list() @@ -1122,6 +1836,35 @@ This is a test submission of a new issue. name = self.db.user.get(new, 'realname') self.assertEquals(name, 'H€llo') + def testNewUserAuthorMixedEncodedName(self): + l = set(self.db.user.list()) + # From: name has Euro symbol in it + message = '''Content-Type: text/plain; + charset="iso-8859-1" +From: Firstname =?utf-8?b?w6TDtsOf?= Last +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +Subject: [issue] Test =?utf-8?b?w4TDlsOc?= umlauts + X1 + X2 + +This is a test submission of a new issue. +''' + p = [ + self.db.security.getPermission('Register', 'user'), + self.db.security.getPermission('Email Access', None), + self.db.security.getPermission('Create', 'issue'), + self.db.security.getPermission('Create', 'msg'), + ] + self.db.security.role['anonymous'].permissions = p + self._handle_mail(message) + title = self.db.issue.get('1', 'title') + self.assertEquals(title, 'Test \xc3\x84\xc3\x96\xc3\x9c umlauts X1 X2') + m = set(self.db.user.list()) + new = list(m - l)[0] + name = self.db.user.get(new, 'realname') + self.assertEquals(name, 'Firstname \xc3\xa4\xc3\xb6\xc3\x9f Last') + def testUnknownUser(self): l = set(self.db.user.list()) message = '''Content-Type: text/plain; @@ -1133,11 +1876,8 @@ Subject: [issue] Testing nonexisting user... This is a test submission of a new issue. ''' - self.db.close() - handler = self.instance.MailGW(self.instance) - # we want a bounce message: - handler.trapExceptions = 1 - ret = handler.main(StringIO(message)) + # trap_exc=1: we want a bounce message: + ret = self._handle_mail(message, trap_exc=1) self.compareMessages(self._get_mail(), '''FROM: Roundup issue tracker TO: nonexisting@bork.bork.bork @@ -1476,6 +2216,12 @@ This is a followup self.assertEqual(uidFromAddress(self.db, ('', 'user1@bar.com'), 0), i) self.assertEqual(uidFromAddress(self.db, ('', 'USER1@bar.com'), 0), i) + def testUserAlternateSubstringNomatch(self): + i = self.db.user.create(username='user1', address='user1@foo.com', + alternate_addresses='x-user1@bar.com') + self.assertEqual(uidFromAddress(self.db, ('', 'user1@bar.com'), 0), 0) + self.assertEqual(uidFromAddress(self.db, ('', 'USER1@bar.com'), 0), 0) + def testUserCreate(self): i = uidFromAddress(self.db, ('', 'user@foo.com'), 1) self.assertNotEqual(uidFromAddress(self.db, ('', 'user@bar.com'), 1), i) @@ -1898,6 +2644,22 @@ Message-Id: assert not os.path.exists(SENDMAILDEBUG) self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar') + def testOneCharSubject(self): + message = '''Content-Type: text/plain; + charset="iso-8859-1" +From: Chef +To: issue_tracker@your.tracker.email.domain.example +Subject: b +Cc: richard@test.test +Reply-To: chef@bork.bork.bork +Message-Id: + +''' + try: + self._handle_mail(message) + except MailUsageError: + self.fail('MailUsageError raised') + def testIssueidLast(self): nodeid1 = self.doNewIssue() nodeid2 = self._handle_mail('''Content-Type: text/plain; @@ -1927,7 +2689,7 @@ This is a second followup charset="iso-8859-1" From: Chef To: issue_tracker@your.tracker.email.domain.example -Message-Id: +Message-Id: Subject: [issue%(id)s] Testing... [nosy=+mary] Just a test reply @@ -1943,7 +2705,8 @@ From: "Bork, Chef" Reply-To: Roundup issue tracker MIME-Version: 1.0 -Message-Id: +Message-Id: +In-Reply-To: X-Roundup-Name: Roundup issue tracker X-Roundup-Loop: hello X-Roundup-Issue-Status: chatting @@ -1964,10 +2727,571 @@ Roundup issue tracker _______________________________________________________________________ ''') + def testOutlookAttachment(self): + message = '''X-MimeOLE: Produced By Microsoft Exchange V6.5 +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----_=_NextPart_001_01CACA65.40A51CBC" +Subject: Example of a failed outlook attachment e-mail +Date: Tue, 23 Mar 2010 01:43:44 -0700 +Message-ID: +X-MS-Has-Attach: yes +X-MS-TNEF-Correlator: +Thread-Topic: Example of a failed outlook attachment e-mail +Thread-Index: AcrKJo/t3pUBBwTpSwWNE3LE67UBDQ== +From: "Hugh" +To: +X-OriginalArrivalTime: 23 Mar 2010 08:45:57.0350 (UTC) FILETIME=[41893860:01CACA65] + +This is a multi-part message in MIME format. + +------_=_NextPart_001_01CACA65.40A51CBC +Content-Type: multipart/alternative; + boundary="----_=_NextPart_002_01CACA65.40A51CBC" + + +------_=_NextPart_002_01CACA65.40A51CBC +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable + + +Hi Richard, + +I suppose this isn't the exact message that was sent but is a resend of +one of my trial messages that failed. For your benefit I changed the +subject line and am adding these words to the message body. Should +still be as problematic, but if you like I can resend an exact copy of a +failed message changing nothing except putting your address instead of +our tracker. + +Thanks very much for taking time to look into this. Much appreciated. + + <>=20 + +------_=_NextPart_002_01CACA65.40A51CBC +Content-Type: text/html; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable + + + + + + +Example of a failed outlook attachment e-mail + + + +
+ +

Hi Richard, +

+ +

I suppose this isn't the exact message = +that was sent but is a resend of one of my trial messages that = +failed.  For your benefit I changed the subject line and am adding = +these words to the message body.  Should still be as problematic, = +but if you like I can resend an exact copy of a failed message changing = +nothing except putting your address instead of our tracker.

+ +

Thanks very much for taking time to = +look into this.  Much appreciated. +

+
+ +

<<battery = +backup>> +

+ + + +------_=_NextPart_002_01CACA65.40A51CBC-- + +------_=_NextPart_001_01CACA65.40A51CBC +Content-Type: message/rfc822 +Content-Transfer-Encoding: 7bit + +X-MimeOLE: Produced By Microsoft Exchange V6.5 +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----_=_NextPart_003_01CAC15A.29717800" +X-OriginalArrivalTime: 11 Mar 2010 20:33:51.0249 (UTC) FILETIME=[28FEE010:01CAC15A] +Content-class: urn:content-classes:message +Subject: battery backup +Date: Thu, 11 Mar 2010 13:33:43 -0700 +Message-ID: +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: battery backup +Thread-Index: AcrBWimtulTrSvBdQ2CcfZ8lyQdxmQ== +From: "Jerry" +To: "Hugh" + +This is a multi-part message in MIME format. + +------_=_NextPart_003_01CAC15A.29717800 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +Dear Hugh, + A car batter has an energy capacity of ~ 500Wh. A UPS=20 +battery is worse than this. + +if we need to provied 100kW for 30 minutes that will take 100 car=20 +batteries. This seems like an awful lot of batteries. + +Of course I like your idea of making the time 1 minute, so we get to=20 +a more modest number of batteries + +Jerry + + +------_=_NextPart_003_01CAC15A.29717800 +Content-Type: text/html; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + + + + + + +battery backup + + + + +

Dear Hugh, + +
        A car = +batter has an energy capacity of ~ 500Wh.  A UPS + +
battery is worse than this. +

+ +

if we need to provied 100kW for 30 minutes that will = +take 100 car + +
batteries.  This seems like an awful lot of = +batteries. +

+ +

Of course I like your idea of making the time 1 = +minute, so we get to + +
a more modest number of batteries +

+ +

Jerry +

+ + + +------_=_NextPart_003_01CAC15A.29717800-- + +------_=_NextPart_001_01CACA65.40A51CBC-- +''' + nodeid = self._handle_mail(message) + assert not os.path.exists(SENDMAILDEBUG) + msgid = self.db.issue.get(nodeid, 'messages')[0] + self.assert_(self.db.msg.get(msgid, 'content').startswith('Hi Richard')) + self.assertEqual(self.db.msg.get(msgid, 'files'), ['1', '2']) + fileid = self.db.msg.get(msgid, 'files')[0] + self.assertEqual(self.db.file.get(fileid, 'type'), 'text/html') + fileid = self.db.msg.get(msgid, 'files')[1] + self.assertEqual(self.db.file.get(fileid, 'type'), 'message/rfc822') + + def testForwardedMessageAttachment(self): + message = '''Return-Path: +Received: from localhost(127.0.0.1), claiming to be "[115.130.26.69]" +via SMTP by localhost, id smtpdAAApLaWrq; Tue Apr 13 23:10:05 2010 +Message-ID: <4BC4F9C7.50409@test.test> +Date: Wed, 14 Apr 2010 09:09:59 +1000 +From: Rupert Goldie +User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) +MIME-Version: 1.0 +To: ekit issues +Subject: [Fwd: PHP ERROR (fb)] post limit reached +Content-Type: multipart/mixed; boundary="------------000807090608060304010403" + +This is a multi-part message in MIME format. +--------------000807090608060304010403 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit + +Catch this exception and log it without emailing. + +--------------000807090608060304010403 +Content-Type: message/rfc822; name="PHP ERROR (fb).eml" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline; filename="PHP ERROR (fb).eml" + +Return-Path: +X-Sieve: CMU Sieve 2.2 +via SMTP by crown.off.ekorp.com, id smtpdAAA1JaW1o; Tue Apr 13 23:01:04 2010 +X-Virus-Scanned: by amavisd-new at ekit.com +To: facebook-errors@test.test +From: ektravj@test.test +Subject: PHP ERROR (fb) +Message-Id: <20100413230100.D601D27E84@mail2.elax3.ekorp.com> +Date: Tue, 13 Apr 2010 23:01:00 +0000 (UTC) + +[13-Apr-2010 22:49:02] PHP Fatal error: Uncaught exception 'Exception' with message 'Facebook Error Message: Feed action request limit reached' in /app/01/www/virtual/fb.ekit.com/htdocs/includes/functions.php:280 +Stack trace: +#0 /app/01/www/virtual/fb.ekit.com/htdocs/gateway/ekit/feed/index.php(178): fb_exceptions(Object(FacebookRestClientException)) +#1 {main} + thrown in /app/01/www/virtual/fb.ekit.com/htdocs/includes/functions.php on line 280 + + +--------------000807090608060304010403-- +''' + nodeid = self._handle_mail(message) + assert not os.path.exists(SENDMAILDEBUG) + msgid = self.db.issue.get(nodeid, 'messages')[0] + self.assertEqual(self.db.msg.get(msgid, 'content'), + 'Catch this exception and log it without emailing.') + self.assertEqual(self.db.msg.get(msgid, 'files'), ['1']) + fileid = self.db.msg.get(msgid, 'files')[0] + self.assertEqual(self.db.file.get(fileid, 'type'), 'message/rfc822') + +pgp_test_key = """ +-----BEGIN PGP PRIVATE KEY BLOCK----- +Version: GnuPG v1.4.10 (GNU/Linux) + +lQOYBE6NqtsBCADG3UUMYxjwUOpDDVvr0Y8qkvKsgdF79en1zfHtRYlmZc+EJxg8 +53CCFGReQWJwOjyP3/SLJwJqfiPR7MAYAqJsm/4U2lxF7sIlEnlrRpFuvB625KOQ +oedCkI4nLa+4QAXHxVX2qLx7es3r2JAoitZLX7ZtUB7qGSRh98DmdAgCY3CFN7iZ +w6xpvIU+LNbsHSo1sf8VP6z7NHQFacgrVvLyRJ4C5lTPU42iM5E6HKxYFExNV3Rn ++2G0bsuiifHV6nJQD73onjwcC6tU97W779dllHlhG3SSP0KlnwmCCv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EEANEa5rBoN7Ta +ED+R47Rg9w/EW3VDQ6R3Szy1rvIKjC6JlDyKlGgTeWEFjDeTwCB4xU7YtxVpt6bk +b7RBtDkRck2+DwnscutA7Uxn267UxzNUd1IxhUccRFRfRS7OEnmlVmaLUnOeHHwe +OrZyRSiNVnh0QABEJnwNjX4m139v6YD9BADYuM5XCawI63pYa3/l7UX9H5EH95OZ +G9Hw7pXQ/YJYerSxRx+2q0+koRcdoby1TVaRrdDC+kOm3PI7e66S5rnaZ1FZeYQP +nVYzyGqNnsvncs24kYBL8DYaDDfdm7vfzSEqia0VNqZ4TMbwJLk5f5Ys4WOF791G +LPJgrAPG1jgDwQQAovKbw0u6blIUKsUYOLsviaLCyFC9DwaHqIZwjy8omnh7MaKE +7+MXxJpfcVqFifj3CmqMdSmTfkgbKQPAI46Q1OKWvkvUxEvi7WATo4taEXupRFL5 +jnL8c4h46z8UpMX2CMwWU0k1Et/zlBoYy7gNON7tF2/uuN18zWFBlD72HuM9HIkB +HwQYAQIACQUCTo2q2wIbDAAKCRBa3P1WMcOHQYI+CACDXJf1e695LpcsrVxKgiQr +9fTbNJYB+tjbnd9vas92Gz1wZcQV9RjLkYQeEbOpWQud/1UeLRsFECMj7kbgAEqz +7fIO4SeN8hFEvvZ+lI0AoBi4XvuUcCm5kvAodvmF8M9kQiUzF1gm+R9QQeJFDLpW +8Gg7J3V3qM+N0FuXrypYcsEv7n/RJ1n+lhTW5hFzKBlNL4WrAhY/QsXEbmdsa478 +tzuHlETtjMm4g4DgppUdlCMegcpjjC9zKsN5xFOQmNMTO/6rPFUqk3k3T6I0LV4O +zm4xNC+wwAA69ibnbrY1NR019et7RYW+qBudGbpJB1ABzkf/NsaCj6aTaubt7PZP +=3uFZ +-----END PGP PRIVATE KEY BLOCK----- +""" + +john_doe_key = """ +-----BEGIN PGP PRIVATE KEY BLOCK----- +Version: GnuPG v1.4.10 (GNU/Linux) + +lQHYBE6NwvABBACxg7QqV2qHywwM3wae6HAHJVEo7EeYA6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5acXUAEQEAAQAD/R7Jdf98l1scngMYo228ikYUxBqm2eX/fiQNXDWM +ZR2u+TJ9O53MvFejfXX7Pd6lTDQUBwDFncjgXO0YYSrMzabhqpqoKLqOIpZmBuWC +Hh1lvcFoIYoDR2LkiJ9EPBUEVUBDsUO8ajkILEE3G+DDpCaf9Vo82lCVyhDESqyt +v4lxAgDOLpoq1Whv5Ejr6FifTWytCiQjH2P1SmePlQmy6oEJRUYA1t4zYrzCJUX8 +VAvPjh9JXilP6mhDbyQArWllewV9AgDPbVOf75ktRwfhje26tZsukqWYJCc1XvoH +3PTzA7vH1HZZq7dvxa87PiSnkOLEsIAsI+4jpeMxpPlQRxUvHf1ZAf9rK3v3HMJ/ +2xVzwK24Oaj+g2O7D/fdqtLFGe5S5JobnTyp9xArDAhaZ/AKfDMYjUIKMP+bdNAf +y8fQUtuawFltm1GInwQYAQIACQUCTo3C8AIbDAAKCRC/z7qg+FujnDzYA/9EU6Pv +Ci1+DCtxjnq7IOvOjqExhFNGvN9Dw17Tl8HcyW3if9v5RxeSWYKl0DhzVdzMQgH/ +78q4F4W1q2IkB7SCpXizHLIc3eh8iZkbWZE+CGPvTpqyF03Yi16qhxpAbkGs2Yhq +jTx5oJ4CL5fybBOZLg+BTlK4HIee6xEcbNoq+A== +=ZKBW +-----END PGP PRIVATE KEY BLOCK----- +""" + +ownertrust = """ +723762CD5A5FECB76DC72DF85ADCFD5631C38741:6: +2940C247A1FBAD508A1AF24BBFCFBAA0F85BA39C:6: +""" + +class MailgwPGPTestCase(MailgwTestAbstractBase): + pgphome = 'pgp-test-home' + def setUp(self): + MailgwTestAbstractBase.setUp(self) + self.db.security.addRole(name = 'pgp', description = 'PGP Role') + self.instance.config['PGP_HOMEDIR'] = self.pgphome + self.instance.config['PGP_ROLES'] = 'pgp' + self.instance.config['PGP_ENABLE'] = True + self.instance.config['MAIL_DOMAIN'] = 'example.com' + self.instance.config['ADMIN_EMAIL'] = 'roundup-admin@example.com' + self.db.user.set(self.john_id, roles='User,pgp') + os.mkdir(self.pgphome) + os.environ['GNUPGHOME'] = self.pgphome + ctx = pyme.core.Context() + key = pyme.core.Data(pgp_test_key) + ctx.op_import(key) + key = pyme.core.Data(john_doe_key) + ctx.op_import(key) + # trust-modelling with pyme isn't working in 0.8.1 + # based on libgpgme11 1.2.0, also tried in C -- same thing. + otrust = os.popen ('gpg --import-ownertrust 2> /dev/null', 'w') + otrust.write(ownertrust) + otrust.close() + + def tearDown(self): + MailgwTestAbstractBase.tearDown(self) + if os.path.exists(self.pgphome): + shutil.rmtree(self.pgphome) + + def testPGPUnsignedMessage(self): + self.assertRaises(MailUsageError, self._handle_mail, + '''Content-Type: text/plain; + charset="iso-8859-1" +From: John Doe +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +Subject: [issue] Testing non-signed message... + +This is no pgp signed message. +''') + + signed_msg = '''Content-Disposition: inline +From: John Doe +To: issue_tracker@your.tracker.email.domain.example +Subject: [issue] Testing signed message... +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; boundary="cWoXeonUoKmBZSoM" + + +--cWoXeonUoKmBZSoM +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline + +This is a pgp signed message. + +--cWoXeonUoKmBZSoM +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: Digital signature +Content-Disposition: inline + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.10 (GNU/Linux) + +iJwEAQECAAYFAk6N4A4ACgkQv8+6oPhbo5x5nAP/d7R7SxTvLoVESI+1r7eDXp1J +LvBVU2EF3YFYKBHMLcWmjG92fNjnHX6NENTEhTeBynba5IPEwUfITC+7PmgPmQkA +VXnFZnwraHxsYgyFsVFN1kkTSbwRUlWl9+nTEsr0yBLTpZN0QSIDcwu+i/xVcg+t +ZQ4K6R3m3AOw7BLdvZs= +=wpYk +-----END PGP SIGNATURE----- + +--cWoXeonUoKmBZSoM-- +''' + + def testPGPSignedMessage(self): + nodeid = self._handle_mail(self.signed_msg) + m = self.db.issue.get(nodeid, 'messages')[0] + self.assertEqual(self.db.msg.get(m, 'content'), + 'This is a pgp signed message.') + + def testPGPSignedMessageFail(self): + # require both, signing and encryption + self.instance.config['PGP_REQUIRE_INCOMING'] = 'both' + self.assertRaises(MailUsageError, self._handle_mail, self.signed_msg) + + encrypted_msg = '''Content-Disposition: inline +From: John Doe +To: roundup-admin@example.com +Subject: [issue] Testing encrypted message... +Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; + boundary="d6Gm4EdcadzBjdND" + +--d6Gm4EdcadzBjdND +Content-Type: application/pgp-encrypted +Content-Disposition: attachment + +Version: 1 + +--d6Gm4EdcadzBjdND +Content-Type: application/octet-stream +Content-Disposition: inline; filename="msg.asc" + +-----BEGIN PGP MESSAGE----- +Version: GnuPG v1.4.10 (GNU/Linux) + +hQEMAzfeQttq+Q2YAQf9FxCtZVgC7jAy6UkeAJ1imCpnh9DgKA5w40OFtrY4mVAp +cL7kCkvGvJCW7uQZrmSgIiYaZGLI3GS42XutORC6E6PzBEW0fJUMIXYmoSd0OFeY +3H2+854qu37W/uCOWM9OnPFIH8g8q8DgYy88i0goM+Ot9Q96yFfJ7QymanOZJgVa +MNC+oKDiIZKiE3PCwtGr+8CHZN/9J6O4FeJijBlr09C5LXc+Nif5T0R0nt17MAns +9g2UvGxW8U24NAS1mOg868U05hquLPIcFz9jGZGknJu7HBpOkQ9GjKqkzN8pgZVN +VbN8IdDqi0QtRKE44jtWQlyNlESMjv6GtC2V9F6qKNK8AfHtBexDhyv4G9cPFFNO +afQ6e4dPi89RYIQyydtwiqao8fj6jlAy2Z1cbr7YxwBG7BeUZv9yis7ShaAIo78S +82MrCYpSjfHNwKiSfC5yITw22Uv4wWgixVdAsaSdtBqEKXJPG9LNey18ArsBjSM1 +P81iDOWUp/uyIe5ZfvNI38BBxEYslPTUlDk2GB8J2Vun7IWHoj9a4tY3IotC9jBr +5Qnigzqrt7cJZX6OrN0c+wnOjXbMGYXmgSs4jeM= +=XX5Q +-----END PGP MESSAGE----- + +--d6Gm4EdcadzBjdND-- +''' + def testPGPEncryptedUnsignedMessageError(self): + self.assertRaises(MailUsageError, self._handle_mail, self.encrypted_msg) + + def testPGPEncryptedUnsignedMessage(self): + # no error if we don't require a signature: + self.instance.config['PGP_REQUIRE_INCOMING'] = 'encrypted' + nodeid = self._handle_mail (self.encrypted_msg) + m = self.db.issue.get(nodeid, 'messages')[0] + self.assertEqual(self.db.msg.get(m, 'content'), + 'This is the text to be encrypted') + + def testPGPEncryptedUnsignedMessageFromNonPGPUser(self): + msg = self.encrypted_msg.replace('John Doe ', + '"Contrary, Mary" ') + nodeid = self._handle_mail (msg) + m = self.db.issue.get(nodeid, 'messages')[0] + self.assertEqual(self.db.msg.get(m, 'content'), + 'This is the text to be encrypted') + self.assertEqual(self.db.msg.get(m, 'author'), self.mary_id) + + # check that a bounce-message that is triggered *after* + # decrypting is properly encrypted: + def testPGPEncryptedUnsignedMessageCheckBounce(self): + # allow non-signed msg + self.instance.config['PGP_REQUIRE_INCOMING'] = 'encrypted' + # don't allow creation of message, trigger error *after* decrypt + self.db.user.set(self.john_id, roles='pgp') + self.db.security.addPermissionToRole('pgp', 'Email Access') + self.db.security.addPermissionToRole('pgp', 'Create', 'issue') + # trap_exc=1: we want a bounce message: + self._handle_mail(self.encrypted_msg, trap_exc=1) + m = self._get_mail() + fp = FeedParser() + fp.feed(m) + parts = fp.close().get_payload() + self.assertEqual(len(parts),2) + self.assertEqual(parts[0].get_payload().strip(), 'Version: 1') + crypt = pyme.core.Data(parts[1].get_payload()) + plain = pyme.core.Data() + ctx = pyme.core.Context() + res = ctx.op_decrypt(crypt, plain) + self.assertEqual(res, None) + plain.seek(0,0) + fp = FeedParser() + fp.feed(plain.read()) + parts = fp.close().get_payload() + self.assertEqual(len(parts),2) + self.assertEqual(parts[0].get_payload().strip(), + 'You are not permitted to create messages.') + self.assertEqual(parts[1].get_payload().strip(), + '''Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline + +This is the text to be encrypted''') + + + def testPGPEncryptedSignedMessage(self): + # require both, signing and encryption + self.instance.config['PGP_REQUIRE_INCOMING'] = 'both' + nodeid = self._handle_mail('''Content-Disposition: inline +From: John Doe +To: roundup-admin@example.com +Subject: Testing encrypted and signed message +MIME-Version: 1.0 +Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; + boundary="ReaqsoxgOBHFXBhH" + +--ReaqsoxgOBHFXBhH +Content-Type: application/pgp-encrypted +Content-Disposition: attachment + +Version: 1 + +--ReaqsoxgOBHFXBhH +Content-Type: application/octet-stream +Content-Disposition: inline; filename="msg.asc" + +-----BEGIN PGP MESSAGE----- +Version: GnuPG v1.4.10 (GNU/Linux) + +hQEMAzfeQttq+Q2YAQf+NaC3r8qBURQqxHH9IAP4vg0QAP2yj3n0v6guo1lRf5BA +EUfTQ3jc3chxLvzTgoUIuMOvhlNroqR1lgLwhfSTCyuKWDZa+aVNiSgsB2MD44Xd +mAkKKmnmOGLmfbICbPQZxl4xNhCMTHiAy1xQE6mTj/+pEAq5XxjJUwn/gJ3O1Wmd +NyWtJY2N+TRbxUVB2WhG1j9J1D2sjhG26TciE8JeuLDZzaiVNOW9YlX2Lw5KtlkR +Hkgw6Xme06G0XXZUcm9JuBU/7oFP/tSrC1tBsnVlq1pZYf6AygIBdXWb9gD/WmXh +7Eu/xCKrw4RFnXnTgmBz/NHRfVDkfdSscZqexnG1D9LAwQHSuVf8sxDPNesv0W+8 +e49loVjvU+Y0BCFQAbWSW4iOEUYZpW/ITRE4+wIqMXZbAraeBV0KPZ4hAa3qSmf+ +oZBRcbzssL163Odx/OHRuK2J2CHC654+crrlTBnxd/RUKgRbSUKwrZzB2G6OPcGv +wfiqXsY+XvSZtTbWuvUJxePh8vhhhjpuo1JtlrYc3hZ9OYgoCoV1JiLl5c60U5Es +oUT9GDl1Qsgb4dF4TJ1IBj+riYiocYpJxPhxzsy6liSLNy2OA6VEjG0FGk53+Ok9 +7UzOA+WaHJHSXafZzrdP1TWJUFlOMA+dOgTKpH69eL1+IRfywOjEwp1UNSbLnJpc +D0QQLwIFttplKvYkn0DZByJCVnIlGkl4s5LM5rnc8iecX8Jad0iRIlPV6CVM+Nso +WdARUfyJfXAmz8uk4f2sVfeMu1gdMySdjvxwlgHDJdBPIG51r2b8L/NCTiC57YjF +zGhS06FLl3V1xx6gBlpqQHjut3efrAGpXGBVpnTJMOcgYAk= +=jt/n +-----END PGP MESSAGE----- + +--ReaqsoxgOBHFXBhH-- +''') + m = self.db.issue.get(nodeid, 'messages')[0] + self.assertEqual(self.db.msg.get(m, 'content'), + 'This is the text of a signed and encrypted email.') + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(MailgwTestCase)) + if pyme is not None: + suite.addTest(unittest.makeSuite(MailgwPGPTestCase)) + else: + print "Skipping PGP tests" return suite if __name__ == '__main__':