comparison test/test_mailgw.py @ 4373:18cc4323e2ad

Accept single-character subject lines
author Richard Jones <richard@users.sourceforge.net>
date Fri, 16 Apr 2010 06:52:18 +0000
parents 887a153cedec
children 863ec554525c
comparison
equal deleted inserted replaced
4372:4d2fcbaaf2e5 4373:18cc4323e2ad
135 self.mary_id = self.db.user.create(username='mary', 135 self.mary_id = self.db.user.create(username='mary',
136 address='mary@test.test', roles='User', realname='Contrary, Mary') 136 address='mary@test.test', roles='User', realname='Contrary, Mary')
137 self.john_id = self.db.user.create(username='john', 137 self.john_id = self.db.user.create(username='john',
138 address='john@test.test', roles='User', realname='John Doe', 138 address='john@test.test', roles='User', realname='John Doe',
139 alternate_addresses='jondoe@test.test\njohn.doe@test.test') 139 alternate_addresses='jondoe@test.test\njohn.doe@test.test')
140 self.rgg_id = self.db.user.create(username='rgg',
141 address='rgg@test.test', roles='User')
140 142
141 def tearDown(self): 143 def tearDown(self):
142 if os.path.exists(SENDMAILDEBUG): 144 if os.path.exists(SENDMAILDEBUG):
143 os.remove(SENDMAILDEBUG) 145 os.remove(SENDMAILDEBUG)
144 self.db.close() 146 self.db.close()
1948 ''') 1950 ''')
1949 1951
1950 assert not os.path.exists(SENDMAILDEBUG) 1952 assert not os.path.exists(SENDMAILDEBUG)
1951 self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar') 1953 self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar')
1952 1954
1955 def testOneCharSubject(self):
1956 message = '''Content-Type: text/plain;
1957 charset="iso-8859-1"
1958 From: Chef <chef@bork.bork.bork>
1959 To: issue_tracker@your.tracker.email.domain.example
1960 Subject: b
1961 Cc: richard@test.test
1962 Reply-To: chef@bork.bork.bork
1963 Message-Id: <dummy_test_message_id>
1964
1965 '''
1966 try:
1967 self._handle_mail(message)
1968 except MailUsageError:
1969 self.fail('MailUsageError raised')
1970
1953 def testIssueidLast(self): 1971 def testIssueidLast(self):
1954 nodeid1 = self.doNewIssue() 1972 nodeid1 = self.doNewIssue()
1955 nodeid2 = self._handle_mail('''Content-Type: text/plain; 1973 nodeid2 = self._handle_mail('''Content-Type: text/plain;
1956 charset="iso-8859-1" 1974 charset="iso-8859-1"
1957 From: mary <mary@test.test> 1975 From: mary <mary@test.test>
2015 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example> 2033 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
2016 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> 2034 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
2017 _______________________________________________________________________ 2035 _______________________________________________________________________
2018 ''') 2036 ''')
2019 2037
2038 def testOutlookAttachment(self):
2039 message = '''X-MimeOLE: Produced By Microsoft Exchange V6.5
2040 Content-class: urn:content-classes:message
2041 MIME-Version: 1.0
2042 Content-Type: multipart/mixed;
2043 boundary="----_=_NextPart_001_01CACA65.40A51CBC"
2044 Subject: Example of a failed outlook attachment e-mail
2045 Date: Tue, 23 Mar 2010 01:43:44 -0700
2046 Message-ID: <CA37F17219784343816CA6613D2E339205E7D0F9@nrcwstexb1.nrc.ca>
2047 X-MS-Has-Attach: yes
2048 X-MS-TNEF-Correlator:
2049 Thread-Topic: Example of a failed outlook attachment e-mail
2050 Thread-Index: AcrKJo/t3pUBBwTpSwWNE3LE67UBDQ==
2051 From: "Hugh" <richard@test.test>
2052 To: <richard@test.test>
2053 X-OriginalArrivalTime: 23 Mar 2010 08:45:57.0350 (UTC) FILETIME=[41893860:01CACA65]
2054
2055 This is a multi-part message in MIME format.
2056
2057 ------_=_NextPart_001_01CACA65.40A51CBC
2058 Content-Type: multipart/alternative;
2059 boundary="----_=_NextPart_002_01CACA65.40A51CBC"
2060
2061
2062 ------_=_NextPart_002_01CACA65.40A51CBC
2063 Content-Type: text/plain;
2064 charset="us-ascii"
2065 Content-Transfer-Encoding: quoted-printable
2066
2067
2068 Hi Richard,
2069
2070 I suppose this isn't the exact message that was sent but is a resend of
2071 one of my trial messages that failed. For your benefit I changed the
2072 subject line and am adding these words to the message body. Should
2073 still be as problematic, but if you like I can resend an exact copy of a
2074 failed message changing nothing except putting your address instead of
2075 our tracker.
2076
2077 Thanks very much for taking time to look into this. Much appreciated.
2078
2079 <<battery backup>>=20
2080
2081 ------_=_NextPart_002_01CACA65.40A51CBC
2082 Content-Type: text/html;
2083 charset="us-ascii"
2084 Content-Transfer-Encoding: quoted-printable
2085
2086 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
2087 <HTML>
2088 <HEAD>
2089 <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
2090 charset=3Dus-ascii">
2091 <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
2092 6.5.7654.12">
2093 <TITLE>Example of a failed outlook attachment e-mail</TITLE>
2094 </HEAD>
2095 <BODY>
2096 <!-- Converted from text/rtf format -->
2097 <BR>
2098
2099 <P><FONT SIZE=3D2 FACE=3D"Arial">Hi Richard,</FONT>
2100 </P>
2101
2102 <P><FONT SIZE=3D2 FACE=3D"Arial">I suppose this isn't the exact message =
2103 that was sent but is a resend of one of my trial messages that =
2104 failed.&nbsp; For your benefit I changed the subject line and am adding =
2105 these words to the message body.&nbsp; Should still be as problematic, =
2106 but if you like I can resend an exact copy of a failed message changing =
2107 nothing except putting your address instead of our tracker.</FONT></P>
2108
2109 <P><FONT SIZE=3D2 FACE=3D"Arial">Thanks very much for taking time to =
2110 look into this.&nbsp; Much appreciated.</FONT>
2111 </P>
2112 <BR>
2113
2114 <P><FONT FACE=3D"Arial" SIZE=3D2 COLOR=3D"#000000"> &lt;&lt;battery =
2115 backup&gt;&gt; </FONT>
2116 </P>
2117
2118 </BODY>
2119 </HTML>
2120 ------_=_NextPart_002_01CACA65.40A51CBC--
2121
2122 ------_=_NextPart_001_01CACA65.40A51CBC
2123 Content-Type: message/rfc822
2124 Content-Transfer-Encoding: 7bit
2125
2126 X-MimeOLE: Produced By Microsoft Exchange V6.5
2127 MIME-Version: 1.0
2128 Content-Type: multipart/alternative;
2129 boundary="----_=_NextPart_003_01CAC15A.29717800"
2130 X-OriginalArrivalTime: 11 Mar 2010 20:33:51.0249 (UTC) FILETIME=[28FEE010:01CAC15A]
2131 Content-class: urn:content-classes:message
2132 Subject: battery backup
2133 Date: Thu, 11 Mar 2010 13:33:43 -0700
2134 Message-ID: <p06240809c7bf02f9624c@[128.114.22.203]>
2135 X-MS-Has-Attach:
2136 X-MS-TNEF-Correlator:
2137 Thread-Topic: battery backup
2138 Thread-Index: AcrBWimtulTrSvBdQ2CcfZ8lyQdxmQ==
2139 From: "Jerry" <jerry@test.test>
2140 To: "Hugh" <hugh@test.test>
2141
2142 This is a multi-part message in MIME format.
2143
2144 ------_=_NextPart_003_01CAC15A.29717800
2145 Content-Type: text/plain;
2146 charset="iso-8859-1"
2147 Content-Transfer-Encoding: quoted-printable
2148
2149 Dear Hugh,
2150 A car batter has an energy capacity of ~ 500Wh. A UPS=20
2151 battery is worse than this.
2152
2153 if we need to provied 100kW for 30 minutes that will take 100 car=20
2154 batteries. This seems like an awful lot of batteries.
2155
2156 Of course I like your idea of making the time 1 minute, so we get to=20
2157 a more modest number of batteries
2158
2159 Jerry
2160
2161
2162 ------_=_NextPart_003_01CAC15A.29717800
2163 Content-Type: text/html;
2164 charset="iso-8859-1"
2165 Content-Transfer-Encoding: quoted-printable
2166
2167 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
2168 <HTML>
2169 <HEAD>
2170 <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
2171 charset=3Diso-8859-1">
2172 <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
2173 6.5.7654.12">
2174 <TITLE>battery backup</TITLE>
2175 </HEAD>
2176 <BODY>
2177 <!-- Converted from text/plain format -->
2178
2179 <P><FONT SIZE=3D2>Dear Hugh,</FONT>
2180
2181 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2>A car =
2182 batter has an energy capacity of ~ 500Wh.&nbsp; A UPS </FONT>
2183
2184 <BR><FONT SIZE=3D2>battery is worse than this.</FONT>
2185 </P>
2186
2187 <P><FONT SIZE=3D2>if we need to provied 100kW for 30 minutes that will =
2188 take 100 car </FONT>
2189
2190 <BR><FONT SIZE=3D2>batteries.&nbsp; This seems like an awful lot of =
2191 batteries.</FONT>
2192 </P>
2193
2194 <P><FONT SIZE=3D2>Of course I like your idea of making the time 1 =
2195 minute, so we get to </FONT>
2196
2197 <BR><FONT SIZE=3D2>a more modest number of batteries</FONT>
2198 </P>
2199
2200 <P><FONT SIZE=3D2>Jerry</FONT>
2201 </P>
2202
2203 </BODY>
2204 </HTML>
2205 ------_=_NextPart_003_01CAC15A.29717800--
2206
2207 ------_=_NextPart_001_01CACA65.40A51CBC--
2208 '''
2209 nodeid = self._handle_mail(message)
2210 assert not os.path.exists(SENDMAILDEBUG)
2211 msgid = self.db.issue.get(nodeid, 'messages')[0]
2212 self.assert_(self.db.msg.get(msgid, 'content').startswith('Hi Richard'))
2213 self.assertEqual(self.db.msg.get(msgid, 'files'), ['1', '2'])
2214 fileid = self.db.msg.get(msgid, 'files')[0]
2215 self.assertEqual(self.db.file.get(fileid, 'type'), 'text/html')
2216 fileid = self.db.msg.get(msgid, 'files')[1]
2217 self.assertEqual(self.db.file.get(fileid, 'type'), 'message/rfc822')
2218
2219 def testForwardedMessageAttachment(self):
2220 message = '''Return-Path: <rgg@test.test>
2221 Received: from localhost(127.0.0.1), claiming to be "[115.130.26.69]"
2222 via SMTP by localhost, id smtpdAAApLaWrq; Tue Apr 13 23:10:05 2010
2223 Message-ID: <4BC4F9C7.50409@test.test>
2224 Date: Wed, 14 Apr 2010 09:09:59 +1000
2225 From: Rupert Goldie <rgg@test.test>
2226 User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
2227 MIME-Version: 1.0
2228 To: ekit issues <issues@test.test>
2229 Subject: [Fwd: PHP ERROR (fb)] post limit reached
2230 Content-Type: multipart/mixed; boundary="------------000807090608060304010403"
2231
2232 This is a multi-part message in MIME format.
2233 --------------000807090608060304010403
2234 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
2235 Content-Transfer-Encoding: 7bit
2236
2237 Catch this exception and log it without emailing.
2238
2239 --------------000807090608060304010403
2240 Content-Type: message/rfc822; name="PHP ERROR (fb).eml"
2241 Content-Transfer-Encoding: 7bit
2242 Content-Disposition: inline; filename="PHP ERROR (fb).eml"
2243
2244 Return-Path: <ektravj@test.test>
2245 X-Sieve: CMU Sieve 2.2
2246 via SMTP by crown.off.ekorp.com, id smtpdAAA1JaW1o; Tue Apr 13 23:01:04 2010
2247 X-Virus-Scanned: by amavisd-new at ekit.com
2248 To: facebook-errors@test.test
2249 From: ektravj@test.test
2250 Subject: PHP ERROR (fb)
2251 Message-Id: <20100413230100.D601D27E84@mail2.elax3.ekorp.com>
2252 Date: Tue, 13 Apr 2010 23:01:00 +0000 (UTC)
2253
2254 [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
2255 Stack trace:
2256 #0 /app/01/www/virtual/fb.ekit.com/htdocs/gateway/ekit/feed/index.php(178): fb_exceptions(Object(FacebookRestClientException))
2257 #1 {main}
2258 thrown in /app/01/www/virtual/fb.ekit.com/htdocs/includes/functions.php on line 280
2259
2260
2261 --------------000807090608060304010403--
2262 '''
2263 nodeid = self._handle_mail(message)
2264 assert not os.path.exists(SENDMAILDEBUG)
2265 msgid = self.db.issue.get(nodeid, 'messages')[0]
2266 self.assertEqual(self.db.msg.get(msgid, 'content'),
2267 'Catch this exception and log it without emailing.')
2268 self.assertEqual(self.db.msg.get(msgid, 'files'), ['1'])
2269 fileid = self.db.msg.get(msgid, 'files')[0]
2270 self.assertEqual(self.db.file.get(fileid, 'type'), 'message/rfc822')
2020 2271
2021 def test_suite(): 2272 def test_suite():
2022 suite = unittest.TestSuite() 2273 suite = unittest.TestSuite()
2023 suite.addTest(unittest.makeSuite(MailgwTestCase)) 2274 suite.addTest(unittest.makeSuite(MailgwTestCase))
2024 return suite 2275 return suite
2026 if __name__ == '__main__': 2277 if __name__ == '__main__':
2027 runner = unittest.TextTestRunner() 2278 runner = unittest.TextTestRunner()
2028 unittest.main(testRunner=runner) 2279 unittest.main(testRunner=runner)
2029 2280
2030 # vim: set filetype=python sts=4 sw=4 et si : 2281 # vim: set filetype=python sts=4 sw=4 et si :
2282
2283
2284
2285

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