def _raw_message_body(self, message): content_doc = (yield message.get_wrapper().get_body(self.soledad)) parser = BodyParser(content_doc.raw, content_type=content_doc.content_type, content_transfer_encoding=content_doc.content_transfer_encoding) defer.returnValue(parser.parsed_content())
def _raw_message_body(self, message): content_doc = (yield message.get_wrapper().get_body(self.soledad)) parser = BodyParser( content_doc.raw, content_type=content_doc.content_type, content_transfer_encoding=content_doc.content_transfer_encoding) defer.returnValue(parser.parsed_content())
def _raw_message_body(self, message): content_doc = (yield message.get_wrapper().get_body(self.soledad)) parser = BodyParser('', content_type='text/plain', content_transfer_encoding='UTF-8') # It fix the problem when leap doesn'r found body_phash and returns empty string if not isinstance(content_doc, str): parser = BodyParser(content_doc.raw, content_type=content_doc.content_type, content_transfer_encoding=content_doc.content_transfer_encoding) defer.returnValue(parser.parsed_content())
def _raw_message_body(self, message): content_doc = (yield message.get_wrapper().get_body(self.soledad)) parser = BodyParser('', content_type='text/plain', content_transfer_encoding='UTF-8') # It fix the problem when leap doesn'r found body_phash and returns empty string if not isinstance(content_doc, str): parser = BodyParser(content_doc.raw, content_type=content_doc.content_type, content_transfer_encoding=content_doc. content_transfer_encoding) defer.returnValue(parser.parsed_content())
def test_body_parser_logs_problems_and_then_ignores_invalid_chars(self, logger_mock): data = u'unkown char: \ufffd' parser = BodyParser(data, content_type='text/plain; charset=iso-8859-1', content_transfer_encoding='8bit') self.assertEqual(u'unkown char: ', parser.parsed_content()) logger_mock.warn.assert_called_with(u'Failed to encode content for charset iso-8859-1. Ignoring invalid chars: \'latin-1\' codec can\'t encode character u\'\\ufffd\' in position 13: ordinal not in range(256)')
def test_base64_with_default_us_ascii_encoding(self): parser = BodyParser('dGVzdCB0ZXh0\n', content_type='text/plain', content_transfer_encoding='base64') self.assertEqual('test text', parser.parsed_content())
def test_8bit_transfer_encoding_with_iso_8859_1_unicode_input(self): data = u'Hmm, here are \xdcml\xe4\xfcts again!' parser = BodyParser(data, content_type='text/plain; charset=iso-8859-1', content_transfer_encoding='8bit') self.assertEqual(u'Hmm, here are Ümläüts again!', parser.parsed_content())
def test_base64_text(self): parser = BodyParser('dGVzdCB0ZXh0\n', content_type='text/plain; charset="utf-8"', content_transfer_encoding='base64') self.assertEqual('test text', parser.parsed_content())
def test_simple_text(self): parser = BodyParser('simple text') self.assertEqual('simple text', parser.parsed_content())