comparison test/test_mailgw.py @ 4093:1ebab2e397d0

Add some new encoding tests to mailgw: - confirm that non-utf8 encodings work - confirm that non-ASCII headers work (and they didn't but do now) (roundup.rfc2822 is almost entirely gone from Roundup use now)
author Richard Jones <richard@users.sourceforge.net>
date Thu, 12 Mar 2009 06:25:05 +0000
parents 4b0ddce43d08
children 61cf00ca920a
comparison
equal deleted inserted replaced
4092:4b0ddce43d08 4093:1ebab2e397d0
1 # -*- encoding: utf-8 -*-
1 # 2 #
2 # Copyright (c) 2001 Richard Jones, richard@bofh.asn.au. 3 # Copyright (c) 2001 Richard Jones, richard@bofh.asn.au.
3 # This module is free software, and you may redistribute it and/or modify 4 # 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 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form. 6 # disclaimer are retained in their original form.
21 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] 22 SENDMAILDEBUG = os.environ['SENDMAILDEBUG']
22 23
23 from roundup.mailgw import MailGW, Unauthorized, uidFromAddress, \ 24 from roundup.mailgw import MailGW, Unauthorized, uidFromAddress, \
24 parseContent, IgnoreLoop, IgnoreBulk, MailUsageError, MailUsageHelp 25 parseContent, IgnoreLoop, IgnoreBulk, MailUsageError, MailUsageHelp
25 from roundup import init, instance, password, rfc2822, __version__ 26 from roundup import init, instance, password, rfc2822, __version__
27 from roundup.anypy.sets_ import set
26 28
27 import db_test_base 29 import db_test_base
28 30
29 class Message(rfc822.Message): 31 class Message(rfc822.Message):
30 """String-based Message class with equivalence test.""" 32 """String-based Message class with equivalence test."""
1060 self._handle_mail(message) 1062 self._handle_mail(message)
1061 m = self.db.user.list() 1063 m = self.db.user.list()
1062 m.sort() 1064 m.sort()
1063 self.assertNotEqual(l, m) 1065 self.assertNotEqual(l, m)
1064 1066
1067 def testNewUserAuthorHighBit(self):
1068 l = set(self.db.user.list())
1069 # From: name has Euro symbol in it
1070 message = '''Content-Type: text/plain;
1071 charset="iso-8859-1"
1072 From: =?utf8?b?SOKCrGxsbw==?= <fubar@bork.bork.bork>
1073 To: issue_tracker@your.tracker.email.domain.example
1074 Message-Id: <dummy_test_message_id>
1075 Subject: [issue] Testing...
1076
1077 This is a test submission of a new issue.
1078 '''
1079 p = [
1080 self.db.security.getPermission('Create', 'user'),
1081 self.db.security.getPermission('Email Access', None),
1082 ]
1083 self.db.security.role['anonymous'].permissions=p
1084 self._handle_mail(message)
1085 m = set(self.db.user.list())
1086 new = list(m - l)[0]
1087 name = self.db.user.get(new, 'realname')
1088 self.assertEquals(name, 'H€llo')
1089
1065 def testEnc01(self): 1090 def testEnc01(self):
1066 self.doNewIssue() 1091 self.doNewIssue()
1067 self._handle_mail('''Content-Type: text/plain; 1092 self._handle_mail('''Content-Type: text/plain;
1068 charset="iso-8859-1" 1093 charset="iso-8859-1"
1069 From: mary <mary@test.test> 1094 From: mary <mary@test.test>
1096 1121
1097 1122
1098 Contrary, Mary <mary@test.test> added the comment: 1123 Contrary, Mary <mary@test.test> added the comment:
1099 1124
1100 A message with encoding (encoded oe =C3=B6) 1125 A message with encoding (encoded oe =C3=B6)
1126
1127 ----------
1128 status: unread -> chatting
1129
1130 _______________________________________________________________________
1131 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
1132 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
1133 _______________________________________________________________________
1134 ''')
1135
1136 def testEncNonUTF8(self):
1137 self.doNewIssue()
1138 self.instance.config.EMAIL_CHARSET = 'iso-8859-1'
1139 self._handle_mail('''Content-Type: text/plain;
1140 charset="iso-8859-1"
1141 From: mary <mary@test.test>
1142 To: issue_tracker@your.tracker.email.domain.example
1143 Message-Id: <followup_dummy_id>
1144 In-Reply-To: <dummy_test_message_id>
1145 Subject: [issue1] Testing...
1146 Content-Type: text/plain;
1147 charset="iso-8859-1"
1148 Content-Transfer-Encoding: quoted-printable
1149
1150 A message with encoding (encoded oe =F6)
1151
1152 ''')
1153 self.compareMessages(self._get_mail(),
1154 '''FROM: roundup-admin@your.tracker.email.domain.example
1155 TO: chef@bork.bork.bork, richard@test.test
1156 Content-Type: text/plain; charset="iso-8859-1"
1157 Subject: [issue1] Testing...
1158 To: chef@bork.bork.bork, richard@test.test
1159 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
1160 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
1161 MIME-Version: 1.0
1162 Message-Id: <followup_dummy_id>
1163 In-Reply-To: <dummy_test_message_id>
1164 X-Roundup-Name: Roundup issue tracker
1165 X-Roundup-Loop: hello
1166 X-Roundup-Issue-Status: chatting
1167 Content-Transfer-Encoding: quoted-printable
1168
1169
1170 Contrary, Mary <mary@test.test> added the comment:
1171
1172 A message with encoding (encoded oe =F6)
1101 1173
1102 ---------- 1174 ----------
1103 status: unread -> chatting 1175 status: unread -> chatting
1104 1176
1105 _______________________________________________________________________ 1177 _______________________________________________________________________

Roundup Issue Tracker: http://roundup-tracker.org/