def test_get_text_invalid_keyword(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: text/plain Basic text. """)) with self.assertRaises(TypeError): raw_data_manager.get_content(m, foo='ignore')
def test_get_non_text_invalid_keyword(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: image/jpg Content-Transfer-Encoding: base64 Ym9ndXMgZGF0YQ== """)) with self.assertRaises(TypeError): raw_data_manager.get_content(m, errors='ignore')
def test_get_raises_on_multipart(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: multipart/mixed; boundary="===" --=== --===-- """)) with self.assertRaises(KeyError): raw_data_manager.get_content(m)
def test_get_text_plain_latin1(self): m = self._bytes_msg(textwrap.dedent("""\ Content-Type: text/plain; charset=latin1 Basìc tëxt. """).encode('latin1')) self.assertEqual(raw_data_manager.get_content(m), "Basìc tëxt.\n")
def test_get_text_plain(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: text/plain Basic text. """)) self.assertEqual(raw_data_manager.get_content(m), "Basic text.\n")
def test_get_text_plain_latin1_quoted_printable(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: text/plain; charset="latin-1" Content-Transfer-Encoding: quoted-printable Bas=ECc t=EBxt. """)) self.assertEqual(raw_data_manager.get_content(m), "Basìc tëxt.\n")
def test_get_text_html(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: text/html <p>Basic text.</p> """)) self.assertEqual(raw_data_manager.get_content(m), "<p>Basic text.</p>\n")
def test_get_text_plain_utf8_base64_recoverable_bad_CTE_data(self): m = self._bytes_msg(textwrap.dedent("""\ Content-Type: text/plain; charset="utf8" Content-Transfer-Encoding: base64 QmFzw6xjIHTDq3h0Lgo""").encode('ascii') + b'\xFF=\n') self.assertEqual(raw_data_manager.get_content(m, errors='ignore'), "Basìc tëxt.\n")
def test_get_text_plain_utf8_base64(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: text/plain; charset="utf8" Content-Transfer-Encoding: base64 QmFzw6xjIHTDq3h0Lgo= """)) self.assertEqual(raw_data_manager.get_content(m), "Basìc tëxt.\n")
def test_get_text_plain_bad_utf8_quoted_printable(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: text/plain; charset="utf8" Content-Transfer-Encoding: quoted-printable Bas=c3=acc t=c3=abxt=fd. """)) self.assertEqual(raw_data_manager.get_content(m), "Basìc tëxt�.\n")
def test_get_text_plain_utf8_base64_recoverable_bad_CTE_data(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: text/plain; charset="utf8" Content-Transfer-Encoding: base64 QmFzw6xjIHTDq3h0Lgo\xFF= """)) self.assertEqual(raw_data_manager.get_content(m, errors='ignore'), "Basìc tëxt.\n")
def test_get_message_rfc822_and_external_body(self): template = textwrap.dedent("""\ Content-Type: message/{} To: [email protected] From: [email protected] Subject: example an example message """) for subtype in 'rfc822 external-body'.split(): with self.subTest(subtype=subtype): m = self._str_msg(template.format(subtype)) sub_msg = raw_data_manager.get_content(m) self.assertIsInstance(sub_msg, self.message) self.assertEqual(raw_data_manager.get_content(sub_msg), "an example message\n") self.assertEqual(sub_msg['to'], '*****@*****.**') self.assertEqual(sub_msg['from'].addresses[0].username, 'bar')
def test_get_non_text(self): template = textwrap.dedent("""\ Content-Type: {} Content-Transfer-Encoding: base64 Ym9ndXMgZGF0YQ== """) for maintype in 'audio image video application'.split(): with self.subTest(maintype=maintype): m = self._str_msg(template.format(maintype+'/foo')) self.assertEqual(raw_data_manager.get_content(m), b"bogus data")
def test_get_message_non_rfc822_or_external_body_yields_bytes(self): m = self._str_msg(textwrap.dedent("""\ Content-Type: message/partial To: [email protected] From: [email protected] Subject: example The real body is in another message. """)) self.assertEqual(raw_data_manager.get_content(m)[:10], b'To: foo@ex')
def open_browser(ui): body = ui.current_buffer.get_selected_message().get_email().get_body( ('html', )) if not body: ui.notify('no html part', priority='error') return with NamedTemporaryFile('w', prefix='alot.', suffix='.html', delete=False) as file: file.write(raw_data_manager.get_content(body)) url = 'file://' + file.name Popen(['luakit', url], stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)
def get_content(self, msg, *args, **kw): raw_data_manager.get_content(msg, *args, **kw)
def get_content(self, msg, *args, **kw): return raw_data_manager.get_content(msg, *args, **kw)