示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
文件: thread.py 项目: tlevine/alot
 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
示例#8
0
 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
示例#9
0
    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)
示例#10
0
    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)
示例#11
0
    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)
示例#12
0
    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)
示例#13
0
    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)
示例#14
0
    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)
示例#15
0
    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)
示例#16
0
    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)
示例#17
0
 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)
示例#18
0
 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)
示例#19
0
文件: thread.py 项目: foobacca/alot
 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)
示例#20
0
文件: thread.py 项目: t-8ch/alot
    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)
示例#21
0
    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)
示例#22
0
    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)
示例#23
0
 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)
示例#24
0
文件: thread.py 项目: laarmen/alot
    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)