def test_prefer_html(self): expected = ( '<!DOCTYPE html><html><body>This is an html email</body></html>') mail = self._make_mixed_plain_html() actual = utils.extract_body(mail) self.assertEqual(actual, expected)
def test_types_provided(self): # This should not return html, even though html is set to preferred # since a types variable is passed expected = 'This is an email' mail = self._make_mixed_plain_html() actual = utils.extract_body(mail, types=['text/plain']) self.assertEqual(actual, expected)
def test_single_text_plain(self): mail = email.mime.text.MIMEText('This is an email') self._set_basic_headers(mail) actual = utils.extract_body(mail) expected = 'This is an email' self.assertEqual(actual, expected)
def _get_body(self): if self._bodytree is None: bodytxt = extract_body(self._message.get_email()) if bodytxt: att = settings.get_theming_attribute('thread', 'body') att_focus = settings.get_theming_attribute( 'thread', 'body_focus') self._bodytree = TextlinesList(bodytxt, att, att_focus) return self._bodytree
def test_require_mailcap_file(self): mail = email.mime.multipart.MIMEMultipart() self._set_basic_headers(mail) mail.attach(email.mime.text.MIMEText( '<!DOCTYPE html><html><body>This is an html email</body></html>', 'html')) actual = utils.extract_body(mail) expected = '<!DOCTYPE html><html><body>This is an html email</body></html>' self.assertEqual(actual, expected)
def test_two_text_plain(self): mail = email.mime.multipart.MIMEMultipart() self._set_basic_headers(mail) mail.attach(email.mime.text.MIMEText('This is an email')) mail.attach(email.mime.text.MIMEText('This is a second part')) actual = utils.extract_body(mail) expected = 'This is an email\n\nThis is a second part' self.assertEqual(actual, expected)
def test_text_plain_and_other(self): mail = email.mime.multipart.MIMEMultipart() self._set_basic_headers(mail) mail.attach(email.mime.text.MIMEText('This is an email')) mail.attach(email.mime.application.MIMEApplication(b'1')) actual = utils.extract_body(mail) expected = 'This is an email' self.assertEqual(actual, expected)
def test_require_mailcap_file(self): mail = email.mime.multipart.MIMEMultipart() self._set_basic_headers(mail) mail.attach(email.mime.text.MIMEText( '<!DOCTYPE html><html><body>This is an html email</body></html>', 'html')) actual = utils.extract_body(mail) expected = ( '<!DOCTYPE html><html><body>This is an html email</body></html>') self.assertEqual(actual, expected)
def test_text_plain_with_attachment_text(self): mail = email.mime.multipart.MIMEMultipart() self._set_basic_headers(mail) mail.attach(email.mime.text.MIMEText('This is an email')) attachment = email.mime.text.MIMEText('this shouldnt be displayed') attachment['Content-Disposition'] = 'attachment' mail.attach(attachment) actual = utils.extract_body(mail) expected = 'This is an email' self.assertEqual(actual, expected)
def __init__(self, message): self._message = message bodytxt = extract_body(message.get_email()) att = settings.get_theming_attribute('thread', 'body') urwid.AttrMap.__init__(self, urwid.Text(bodytxt), att)
def test_simple_utf8_file(self): mail = email.message_from_binary_file( open('tests/static/mail/utf8.eml', 'rb')) actual = utils.extract_body(mail) expected = "Liebe Grüße!\n" self.assertEqual(actual, expected)
def apply(self, ui): # abort if command unset if not self.cmd: ui.notify(self.noop_msg, priority='error') return # get messages to pipe if self.whole_thread: thread = ui.current_buffer.get_selected_thread() if not thread: return to_print = thread.get_messages().keys() else: to_print = [ui.current_buffer.get_selected_message()] # ask for confirmation if needed if self.confirm_msg: if (yield ui.choice(self.confirm_msg, select='yes', cancel='no')) == 'no': return # prepare message sources pipestrings = [] separator = '\n\n' logging.debug('PIPETO format') logging.debug(self.output_format) if self.output_format == 'id': pipestrings = [e.get_message_id() for e in to_print] separator = '\n' elif self.output_format == 'filepath': pipestrings = [e.get_filename() for e in to_print] separator = '\n' else: for msg in to_print: mail = msg.get_email() if self.add_tags: mail['Tags'] = encode_header('Tags', ' '.join(msg.get_tags())) if self.output_format == 'raw': pipestrings.append(mail.as_string()) elif self.output_format == 'decoded': headertext = extract_headers(mail) bodytext = extract_body(mail) msgtext = '%s\n\n%s' % (headertext, bodytext) pipestrings.append(msgtext.encode('utf-8')) if not self.separately: pipestrings = [separator.join(pipestrings)] if self.shell: self.cmd = [' '.join(self.cmd)] # do teh monkey for mail in pipestrings: if self.background: logging.debug('call in background: %s' % str(self.cmd)) proc = subprocess.Popen(self.cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate(mail) else: logging.debug('stop urwid screen') ui.mainloop.screen.stop() logging.debug('call: %s' % str(self.cmd)) proc = subprocess.Popen(self.cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate(mail) logging.debug('start urwid screen') ui.mainloop.screen.start() if err: ui.notify(err, priority='error') return if self.notify_stdout: ui.notify(out) # display 'done' message if self.done_msg: ui.notify(self.done_msg)
def test_prefer_plaintext(self): expected = 'This is an email' mail = self._make_mixed_plain_html() actual = utils.extract_body(mail) self.assertEqual(actual, expected)