def testFixtures(self): dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'accepted_upload', '*') for filename in glob(dir): with open(filename, 'r') as f: mail = parse_mail(f) msg = p.parse(*mail) self.assert_(msg)
def parse(number): filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), \ 'fixtures', 'security_announce', '%d.txt' % number) mail = parse_mail(file(filename)) msg = p.parse(*mail) assert msg return msg.__dict__
def testFixtures(self): dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'accepted_upload', '*') for filename in glob(dir): with open(filename, 'rb') as f: mail = parse_mail(f) msg = p.parse(*mail) self.assertTrue(msg)
def testUtf8Header2(self): f = StringIO(""" From: [email protected] (Marc =?ISO-8859-1?Q?Poulhi=E8s?=) Message body"""[1:]) headers, body = parse_mail(f) self.assertEqual(headers['From'], u"[email protected] (Marc Poulhiès)") self.assertEqual(body, ['Message body'])
def _email_callback(self, fileobj): try: email = parse_mail(fileobj) msg = get_message(email, new_queue=self.new_queue) if not msg: return txt = colourise(msg.for_irc()) # Simple flood/duplicate detection if txt in self.last_n_messages: return self.last_n_messages.insert(0, txt) self.last_n_messages = self.last_n_messages[:20] for channel in self.irc.state.channels: package_regex = self.registryValue( 'package_regex', channel, ) or 'a^' # match nothing by default package_match = re.search(package_regex, msg.package) maintainer_match = False maintainer_regex = self.registryValue( 'maintainer_regex', channel) if maintainer_regex: info = Maintainer().get_maintainer(msg.package) if info: maintainer_match = re.search(maintainer_regex, info['email']) if not package_match and not maintainer_match: continue distribution_regex = self.registryValue( 'distribution_regex', channel, ) if distribution_regex: if not hasattr(msg, 'distribution'): # If this channel has a distribution regex, don't # bother continuing unless the message actually has a # distribution. This filters security messages, etc. continue if not re.search(distribution_regex, msg.distribution): # Distribution doesn't match regex; don't send this # message. continue ircmsg = supybot.ircmsgs.privmsg(channel, txt) self.irc.queueMsg(ircmsg) except Exception as e: log.exception('Uncaught exception: %s ' % e)
def testSpaceAtEndOfLine(self): f = BytesIO(b"""\ Subject: Subject Description:=20 """) headers, body = parse_mail(f) self.assertEqual(body, ['Description: '])
def testUtf8Header(self): f = BytesIO(b"""\ From: Sebastian =?UTF-8?Q?Dr=C3=B6ge?= Message body""") headers, body = parse_mail(f) self.assertEqual(headers['From'], "Sebastian Dröge") self.assertEqual(body, ['Message body'])
def testUnicodeBody(self): f = BytesIO(b"""\ Subject: Subject line Gon=C3=A9ri Le Bouder """) headers, body = parse_mail(f) self.assertEqual(headers['Subject'], 'Subject line') self.assertEqual(body, ["Gon=C3=A9ri Le Bouder"])
def testUnicodeBody(self): f = StringIO(""" Subject: Subject line Gon=C3=A9ri Le Bouder """[1:]) headers, body = parse_mail(f) self.assertEqual(headers['Subject'], 'Subject line') self.assertEqual(body, [u"Gon=C3=A9ri Le Bouder"])
def testUtf8Header(self): f = StringIO(""" From: Sebastian =?UTF-8?Q?Dr=C3=B6ge?= Message body"""[1:]) headers, body = parse_mail(f) self.assertEqual(headers['From'], u"Sebastian Dröge") self.assertEqual(body, ['Message body'])
def testSpaceAtEndOfLine(self): f = StringIO(""" Subject: Subject Description:=20 """[1:]) headers, body = parse_mail(f) self.assertEqual(body, ['Description: '])
def testUnicodeHeader(self): f = BytesIO(b"""\ From: Gon=C3=A9ri Le Bouder Message body """) headers, body = parse_mail(f) self.assertEqual(headers['From'], "Gonéri Le Bouder") self.assertEqual(body, ['Message body'])
def testUnicodeHeader(self): f = StringIO(""" From: Gon=C3=A9ri Le Bouder Message body """[1:]) headers, body = parse_mail(f) self.assertEqual(headers['From'], u"Gonéri Le Bouder") self.assertEqual(body, ['Message body'])
def testUtf8Header2(self): f = BytesIO( b"""\ From: [email protected] (Marc =?ISO-8859-1?Q?Poulhi=E8s?=) Message body""" ) headers, body = parse_mail(f) self.assertEqual(headers["From"], "[email protected] (Marc Poulhiès)") self.assertEqual(body, ["Message body"])
def testNotLongLine(self): f = StringIO(""" Subject: Subject AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB= CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC """[1:]) headers, body = parse_mail(f) self.assertNotEqual(body, [('A' * 73) + ('B' * 73) + ('C' * 73)])
def testNotLongLine(self): f = BytesIO(b"""\ Subject: Subject AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB= CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC """) headers, body = parse_mail(f) self.assertNotEqual(body, [('A' * 73) + ('B' * 73) + ('C' * 73)])
def testFixtures(self): dir = os.path.join( os.path.dirname(os.path.abspath(__file__)), "fixtures", "accepted_upload", "*", ) for filename in glob(dir): with open(filename, "rb") as f: mail = parse_mail(f) msg = p.parse(*mail) self.assertTrue(msg)
def testLongSubject(self): f = StringIO(""" From: Chris Lamb <*****@*****.**> Subject: Bug#123456: marked as done (pinafore: Inertial couplings may exceed tolerance when docking) Simple message body"""[1:]) headers, body = parse_mail(f) self.assertEqual(headers['Subject'], u"Bug#123456: marked as done " \ "(pinafore: Inertial couplings may exceed tolerance when docking)")
def parse(number): filename = os.path.join( os.path.dirname(os.path.abspath(__file__)), "fixtures", "security_announce", "%d.txt" % number, ) with open(filename, "rb") as infile: mail = parse_mail(infile) msg = p.parse(*mail) assert msg return msg.__dict__
def testFixtures(self): from glob import glob dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'accepted_upload', '*') for filename in glob(dir): try: mail = parse_mail(file(filename)) msg = p.parse(*mail) self.assert_(msg) except Exception: print "Exception when parsing %s" % filename raise
def testLongLine(self): f = BytesIO( b"""\ Subject: Subject AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB= CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC """ ) headers, body = parse_mail(f) self.assertEqual(body[0], ("A" * 73) + ("B" * 73) + ("C" * 73))
def testMultipart(self): f = BytesIO( b"""\ From: Mohammed Sameer <*****@*****.**> To: Cristian Greco <*****@*****.**> Cc: [email protected] Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="JlJsEFsx9RQyiX4C" Content-Disposition: inline --JlJsEFsx9RQyiX4C Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Apr 19, 2008 at 04:45:42PM +0200, Cristian Greco wrote: > owner 402462 ! > thanks >=20 > I'll work on this package, Mohammed Sameer agree with me because he is to= o busy > now. Acknowledged. --=20 GPG-Key: 0xA3FD0DF7 - 9F73 032E EAC9 F7AD 951F 280E CB66 8E29 A3FD 0DF7 Debian User and Developer. Homepage: www.foolab.org --JlJsEFsx9RQyiX4C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFICoPwy2aOKaP9DfcRAn7xAJ486L4EWnH/nL176FF4yZSoT2xKEACeNZX4 orkuFNMGzF2Qx9fiQRLWemE= =ivv9 -----END PGP SIGNATURE----- --JlJsEFsx9RQyiX4C-- """ ) headers, body = parse_mail(f) self.assertTrue("Acknowledged." in body)
def testFunc(self, filename=filename): try: headers, body = parse_mail(file(filename)) msg = parser.parse(headers, body) except Exception: print "Exception when parsing %s" % filename raise self.assertEqual(type(msg), expected_type, "%s did not match with its parser" % filename) self.assert_(test(msg), "%s did not pass test" % filename) if msg: txt = msg.format() txt = colourise(txt)
def testMultipart(self): f = StringIO(""" From: Mohammed Sameer <*****@*****.**> To: Cristian Greco <*****@*****.**> Cc: [email protected] Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="JlJsEFsx9RQyiX4C" Content-Disposition: inline --JlJsEFsx9RQyiX4C Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Apr 19, 2008 at 04:45:42PM +0200, Cristian Greco wrote: > owner 402462 ! > thanks >=20 > I'll work on this package, Mohammed Sameer agree with me because he is to= o busy > now. Acknowledged. --=20 GPG-Key: 0xA3FD0DF7 - 9F73 032E EAC9 F7AD 951F 280E CB66 8E29 A3FD 0DF7 Debian User and Developer. Homepage: www.foolab.org --JlJsEFsx9RQyiX4C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFICoPwy2aOKaP9DfcRAn7xAJ486L4EWnH/nL176FF4yZSoT2xKEACeNZX4 orkuFNMGzF2Qx9fiQRLWemE= =ivv9 -----END PGP SIGNATURE----- --JlJsEFsx9RQyiX4C-- """[1:]) headers, body = parse_mail(f) self.assert_(u"Acknowledged." in body)
def testSimple(self): f = BytesIO(b"""\ From: Chris Lamb <*****@*****.**> Subject: This is the subject Simple message body""") headers, body = parse_mail(f) self.assertEqual(headers['From'], "Chris Lamb <*****@*****.**>") self.assertEqual(headers['Subject'], "This is the subject") self.assertEqual(len(body), 1) self.assertEqual(body[0], "Simple message body") self.assertEqual(type(headers['From']), str) self.assertEqual(type(headers['Subject']), str) self.assertEqual(type(body[0]), str)
def testFunc(self, filename=filename): try: headers, body = parse_mail(file(filename)) msg = parser.parse(headers, body) except Exception: print "Exception when parsing %s" % filename raise self.assertTrue( isinstance(msg, expected_type), "%s did not match with its parser: expected %s, got %s" % (filename, expected_type, type(msg))) self.assert_(test(msg), "%s did not pass test" % filename) if msg: txt = msg.format() txt = colourise(txt)
def testSimple(self): f = StringIO(""" From: Chris Lamb <*****@*****.**> Subject: This is the subject Simple message body"""[1:]) headers, body = parse_mail(f) self.assertEqual(headers['From'], u"Chris Lamb <*****@*****.**>") self.assertEqual(headers['Subject'], u"This is the subject") self.assertEqual(len(body), 1) self.assertEqual(body[0], u"Simple message body") self.assertEqual(type(headers['From']), unicode) self.assertEqual(type(headers['Subject']), unicode) self.assertEqual(type(body[0]), unicode)
def testLongSubject(self): f = BytesIO( b"""\ From: Chris Lamb <*****@*****.**> Subject: Bug#123456: marked as done (pinafore: Inertial couplings may exceed tolerance when docking) Simple message body""" ) headers, body = parse_mail(f) self.assertEqual( headers["Subject"], "Bug#123456: marked as done " "(pinafore: Inertial couplings may exceed tolerance when docking)", )
def testFunc(self, filename=filename): with open(filename, "rb") as infile: try: headers, body = parse_mail(infile) msg = parser.parse(headers, body) except Exception: print("Exception when parsing %s" % filename) raise self.assertTrue( isinstance(msg, expected_type), "%s did not match with its parser: expected %s, got %s" % (filename, expected_type, type(msg))) self.assertTrue(test(msg), "%s did not pass test" % filename) if msg: txt = msg.format() txt = colourise(txt)
def _email_callback(self, fileobj): try: email = parse_mail(fileobj) msg = get_message(email) if not msg: return txt = colourise(msg.for_irc()) # Simple flood/duplicate detection if txt in self.last_n_messages: return self.last_n_messages.insert(0, txt) self.last_n_messages = self.last_n_messages[:20] for channel in self.irc.state.channels: regex = self.registryValue('package_regex', channel) or 'a^' if re.search(regex, msg.package): ircmsg = supybot.ircmsgs.privmsg(channel, txt) self.irc.queueMsg(ircmsg) except: log.exception('Uncaught exception')
def _email_callback(self, fileobj): try: emailmsg = parse_mail(fileobj) msg = get_message(emailmsg, new_queue=self.new_queue) if not msg: return txt = colourise(msg.for_irc()) # Simple flood/duplicate detection if txt in self.last_n_messages: return self.last_n_messages.insert(0, txt) self.last_n_messages = self.last_n_messages[:20] maintainer_info = None if hasattr(msg, 'maintainer'): maintainer_info = (split_address(msg.maintainer), ) else: maintainer_info = [] for package in msg.package.split(','): package = package.strip() try: maintainer_info.append( self.apt_archive.get_maintainer(package)) except NewDataSource.DataError as e: log.info("Failed to query maintainer for {}.".format( package)) for channel in self.irc.state.channels: package_regex = self.registryValue( 'package_regex', channel, ) or 'a^' # match nothing by default package_match = re.search(package_regex, msg.package) maintainer_match = False maintainer_regex = self.registryValue('maintainer_regex', channel) if maintainer_regex and maintainer_info is not None and len( maintainer_info) >= 0: for mi in maintainer_info: maintainer_match = re.search(maintainer_regex, mi['email']) if maintainer_match: break if not package_match and not maintainer_match: continue distribution_regex = self.registryValue( 'distribution_regex', channel, ) if distribution_regex: if not hasattr(msg, 'distribution'): # If this channel has a distribution regex, don't # bother continuing unless the message actually has a # distribution. This filters security messages, etc. continue if not re.search(distribution_regex, msg.distribution): # Distribution doesn't match regex; don't send this # message. continue send_privmsg = self.registryValue('send_privmsg', channel) # Send NOTICE per default and if 'send_privmsg' is set for the # channel, send PRIVMSG instead. if send_privmsg: ircmsg = supybot.ircmsgs.privmsg(channel, txt) else: ircmsg = supybot.ircmsgs.notice(channel, txt) self.irc.queueMsg(ircmsg) except Exception as e: log.exception('Uncaught exception: %s ' % e)
def _email_callback(self, fileobj): try: emailmsg = parse_mail(fileobj) msg = get_message(emailmsg, new_queue=self.new_queue) if not msg: return txt = colourise(msg.for_irc()) # Simple flood/duplicate detection if txt in self.last_n_messages: return self.last_n_messages.insert(0, txt) self.last_n_messages = self.last_n_messages[:20] maintainer_info = None if hasattr(msg, 'maintainer'): maintainer_info = (split_address(msg.maintainer), ) else: maintainer_info = [] for package in msg.package.split(','): package = package.strip() try: maintainer_info.append(self.apt_archive.get_maintainer(package)) except NewDataSource.DataError as e: log.info("Failed to query maintainer for {}.".format(package)) for channel in self.irc.state.channels: package_regex = self.registryValue( 'package_regex', channel, ) or 'a^' # match nothing by default package_match = re.search(package_regex, msg.package) maintainer_match = False maintainer_regex = self.registryValue( 'maintainer_regex', channel) if maintainer_regex and maintainer_info is not None and len(maintainer_info) >= 0: for mi in maintainer_info: maintainer_match = re.search(maintainer_regex, mi['email']) if maintainer_match: break if not package_match and not maintainer_match: continue distribution_regex = self.registryValue( 'distribution_regex', channel, ) if distribution_regex: if not hasattr(msg, 'distribution'): # If this channel has a distribution regex, don't # bother continuing unless the message actually has a # distribution. This filters security messages, etc. continue if not re.search(distribution_regex, msg.distribution): # Distribution doesn't match regex; don't send this # message. continue send_privmsg = self.registryValue('send_privmsg', channel) # Send NOTICE per default and if 'send_privmsg' is set for the # channel, send PRIVMSG instead. if send_privmsg: ircmsg = supybot.ircmsgs.privmsg(channel, txt) else: ircmsg = supybot.ircmsgs.notice(channel, txt) self.irc.queueMsg(ircmsg) except Exception as e: log.exception('Uncaught exception: %s ' % e)