示例#1
0
    def test_crackPayload_multiple_w_text(self):
        from karl.testing import registerUtility
        from karl.utilities.interfaces import IMailinTextScrubber
        _called_with = []

        def _fooScrubber(text, text_mimetype=None, is_reply=False):
            _called_with.append((text, text_mimetype, is_reply))
            return text.upper()

        registerUtility(_fooScrubber, IMailinTextScrubber, 'foo')
        mailin = self._makeOne()
        mailin.text_scrubber = 'foo'
        message = DummyMessage()
        filepart = DummyMessage()
        filepart.filename = 'file1.bin'
        filepart.payload = '0123456789ABCDEF'
        filepart.content_type = 'application/octet-stream'
        textpart = DummyMessage()
        textpart.payload = 'payload'
        textpart.charset = 'rot13'
        textpart.content_type = 'text/plain'
        message.payload = (filepart, textpart)

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'CNLYBNQ')
        self.assertEqual(len(attachments), 1)
        filename, mimetype, data = attachments[0]
        self.assertEqual(filename, 'file1.bin')
        self.assertEqual(mimetype, 'application/octet-stream')
        self.assertEqual(data, '0123456789ABCDEF')
        self.assertEqual(len(_called_with), 1)
        self.assertEqual(_called_with[0][0], 'cnlybnq')
        self.assertEqual(_called_with[0][1], 'text/plain')
        self.assertEqual(_called_with[0][2], False)
示例#2
0
    def test_crackPayload_multiple_no_text(self):
        mailin = self._makeOne()
        message = DummyMessage()
        file1part = DummyMessage()
        file1part.filename = 'file1.bin'
        file1part.payload = '0123456789ABCDEF'
        file1part.content_type = 'application/octet-stream'
        file2part = DummyMessage()
        file2part.filename = 'file2.png'
        file2part.payload = '0123456789abcdef'
        file2part.content_type = 'image/png'
        message.payload = (file1part, file2part)

        text, attachments = mailin.crackPayload(message)

        self.failUnless('not found' in text)
        self.assertEqual(len(attachments), 2)
        filename, mimetype, data = attachments[0]
        self.assertEqual(filename, 'file1.bin')
        self.assertEqual(mimetype, 'application/octet-stream')
        self.assertEqual(data, '0123456789ABCDEF')
        filename, mimetype, data = attachments[1]
        self.assertEqual(filename, 'file2.png')
        self.assertEqual(mimetype, 'image/png')
        self.assertEqual(data, '0123456789abcdef')
示例#3
0
    def test_crackPayload_multiple_no_text(self):
        mailin = self._makeOne()
        message = DummyMessage()
        file1part = DummyMessage()
        file1part.filename = 'file1.bin'
        file1part.payload = '0123456789ABCDEF'
        file1part.content_type = 'application/octet-stream'
        file2part = DummyMessage()
        file2part.filename = 'file2.png'
        file2part.payload = '0123456789abcdef'
        file2part.content_type = 'image/png'
        message.payload = (file1part, file2part)

        text, attachments = mailin.crackPayload(message)

        self.failUnless('not found' in text)
        self.assertEqual(len(attachments), 2)
        filename, mimetype, data = attachments[0]
        self.assertEqual(filename, 'file1.bin')
        self.assertEqual(mimetype, 'application/octet-stream')
        self.assertEqual(data, '0123456789ABCDEF')
        filename, mimetype, data = attachments[1]
        self.assertEqual(filename, 'file2.png')
        self.assertEqual(mimetype, 'image/png')
        self.assertEqual(data, '0123456789abcdef')
示例#4
0
    def test_crackPayload_multiple_w_text(self):
        from karl.testing import registerUtility
        from karl.utilities.interfaces import IMailinTextScrubber
        _called_with = []
        def _fooScrubber(text, text_mimetype=None, is_reply=False):
            _called_with.append((text, text_mimetype, is_reply))
            return text.upper()
        registerUtility(_fooScrubber, IMailinTextScrubber, 'foo')
        mailin = self._makeOne()
        mailin.text_scrubber = 'foo'
        message = DummyMessage()
        filepart = DummyMessage()
        filepart.filename = 'file1.bin'
        filepart.payload = '0123456789ABCDEF'
        filepart.content_type = 'application/octet-stream'
        textpart = DummyMessage()
        textpart.payload = 'payload'
        textpart.charset = 'rot13'
        textpart.content_type = 'text/plain'
        message.payload = (filepart, textpart)

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'CNLYBNQ')
        self.assertEqual(len(attachments), 1)
        filename, mimetype, data = attachments[0]
        self.assertEqual(filename, 'file1.bin')
        self.assertEqual(mimetype, 'application/octet-stream')
        self.assertEqual(data, '0123456789ABCDEF')
        self.assertEqual(len(_called_with), 1)
        self.assertEqual(_called_with[0][0], 'cnlybnq')
        self.assertEqual(_called_with[0][1], 'text/plain')
        self.assertEqual(_called_with[0][2], False)
示例#5
0
    def test_crackPayload_single_with_scrubber_is_reply(self):
        from karl.testing import registerUtility
        from karl.utilities.interfaces import IMailinTextScrubber
        _called_with = []

        def _fooScrubber(text, text_mimetype=None, is_reply=False):
            _called_with.append((text, text_mimetype, is_reply))
            return text.upper()

        registerUtility(_fooScrubber, IMailinTextScrubber, 'foo')
        mailin = self._makeOne()
        mailin.text_scrubber = 'foo'
        message = DummyMessage()
        message.payload = 'payload'
        message.content_type = 'text/plain'
        setattr(message, 'in-reply-to', 'foo')

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'PAYLOAD')
        self.assertEqual(len(attachments), 0)
        self.assertEqual(len(_called_with), 1)
        self.assertEqual(_called_with[0][0], 'payload')
        self.assertEqual(_called_with[0][1], 'text/plain')
        self.assertEqual(_called_with[0][2], True)
示例#6
0
    def test_crackPayload_empty(self):
        mailin = self._makeOne()
        message = DummyMessage()

        text, attachments = mailin.crackPayload(message)

        self.failUnless('not found' in text)
        self.assertEqual(len(attachments), 0)
示例#7
0
    def test_crackPayload_empty(self):
        mailin = self._makeOne()
        message = DummyMessage()

        text, attachments = mailin.crackPayload(message)

        self.failUnless('not found' in text)
        self.assertEqual(len(attachments), 0)
示例#8
0
    def test_crackPayload_single(self):
        mailin = self._makeOne()
        message = DummyMessage()
        message.payload = 'payload'
        message.content_type = 'text/plain'

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'payload')
        self.assertEqual(len(attachments), 0)
示例#9
0
    def test_crackPayload_single(self):
        mailin = self._makeOne()
        message = DummyMessage()
        message.payload = 'payload'
        message.content_type = 'text/plain'

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'payload')
        self.assertEqual(len(attachments), 0)
示例#10
0
    def test_crackPayload_single_says_ascii_but_is_really_utf8(self):
        mailin = self._makeOne()
        message = DummyMessage()
        message.payload = 'p\xc3\xa0yload'
        message.content_type = 'text/plain'
        message.charset = 'ASCII'

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'p\xe0yload')
        self.assertEqual(len(attachments), 0)
示例#11
0
    def test_crackPayload_single_bad_encoding(self):
        mailin = self._makeOne()
        message = DummyMessage()
        message.payload = 'Atbild\xe7\xf0u jums p\xe7c atgrie\xf0an\xe2s'
        message.content_type = 'text/plain'
        message.charset = 'windows-foo'

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'Atbild\xe7\xf0u jums p\xe7c atgrie\xf0an\xe2s')
        self.assertEqual(len(attachments), 0)
示例#12
0
    def test_crackPayload_single_says_ascii_but_is_really_utf8(self):
        mailin = self._makeOne()
        message = DummyMessage()
        message.payload = 'p\xc3\xa0yload'
        message.content_type = 'text/plain'
        message.charset = 'ASCII'

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'p\xe0yload')
        self.assertEqual(len(attachments), 0)
示例#13
0
    def test_crackPayload_single_encoded_windows_874(self):
        mailin = self._makeOne()
        message = DummyMessage()
        message.payload = 'payload'
        message.content_type = 'text/plain'
        message.charset = 'windows-874'

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'payload')
        self.assertEqual(len(attachments), 0)
示例#14
0
    def test_crackPayload_single_encoded_windows_874(self):
        mailin = self._makeOne()
        message = DummyMessage()
        message.payload = 'payload'
        message.content_type = 'text/plain'
        message.charset = 'windows-874'

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'payload')
        self.assertEqual(len(attachments), 0)
示例#15
0
    def test_crackPayload_multiple_no_attachments(self):
        mailin = self._makeOne()
        message = DummyMessage()
        part = DummyMessage()
        part.payload = 'payload'
        part.content_type = 'text/plain'
        message.payload = (part,)

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'payload')
        self.assertEqual(len(attachments), 0)
示例#16
0
    def test_crackPayload_multiple_no_attachments(self):
        mailin = self._makeOne()
        message = DummyMessage()
        part = DummyMessage()
        part.payload = 'payload'
        part.content_type = 'text/plain'
        message.payload = (part, )

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'payload')
        self.assertEqual(len(attachments), 0)
示例#17
0
    def test_crackPayload_single_bad_encoding(self):
        mailin = self._makeOne()
        message = DummyMessage()
        message.payload = 'Atbild\xe7\xf0u jums p\xe7c atgrie\xf0an\xe2s'
        message.content_type = 'text/plain'
        message.charset = 'windows-foo'

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text,
                         u'Atbild\xe7\xf0u jums p\xe7c atgrie\xf0an\xe2s')
        self.assertEqual(len(attachments), 0)
示例#18
0
    def test_crackPayload_multiple_skips_html(self):
        mailin = self._makeOne()
        message = DummyMessage()
        htmlpart = DummyMessage()
        htmlpart.payload = '<h1>payload</h1>'
        htmlpart.content_type = 'text/html'
        textpart = DummyMessage()
        textpart.payload = 'payload'
        textpart.content_type = 'text/plain'
        message.payload = (htmlpart, textpart)

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'payload')
        self.assertEqual(len(attachments), 0)
示例#19
0
    def test_crackPayload_multiple_skips_html(self):
        mailin = self._makeOne()
        message = DummyMessage()
        htmlpart = DummyMessage()
        htmlpart.payload = '<h1>payload</h1>'
        htmlpart.content_type = 'text/html'
        textpart = DummyMessage()
        textpart.payload = 'payload'
        textpart.content_type = 'text/plain'
        message.payload = (htmlpart, textpart)

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'payload')
        self.assertEqual(len(attachments), 0)
示例#20
0
    def test_crackPayload_w_forwarded_message(self):
        from karl.testing import registerUtility
        from karl.utilities.interfaces import IMailinTextScrubber
        _called_with = []

        def _fooScrubber(text, text_mimetype=None, is_reply=False):
            _called_with.append((text, text_mimetype, is_reply))
            return text.upper()

        registerUtility(_fooScrubber, IMailinTextScrubber, 'foo')
        mailin = self._makeOne()
        mailin.text_scrubber = 'foo'
        message = DummyMessage()
        filepart = DummyMessage()
        filepart.filename = 'file1.bin'
        filepart.payload = '0123456789ABCDEF'
        filepart.content_type = 'application/octet-stream'
        forwarded = DummyMessage()
        forwarded.payload = None
        forwarded.filename = "Re: prune script testing."
        forwarded.content_type = 'message/rfc822; name="Re: prune script..."'
        textpart = DummyMessage()
        textpart.payload = 'payload'
        textpart.charset = 'rot13'
        textpart.content_type = 'text/plain'
        textpart2 = DummyMessage()
        textpart2.payload = 'howdy folks.\n'
        textpart2.charset = 'ascii'
        textpart2.content_type = 'text/plain'
        message.payload = (textpart, forwarded, filepart, textpart2)

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'CNLYBNQ\n\nHOWDY FOLKS.\n')
        self.assertEqual(len(attachments), 1)
        filename, mimetype, data = attachments[0]
        self.assertEqual(filename, 'file1.bin')
        self.assertEqual(mimetype, 'application/octet-stream')
        self.assertEqual(data, '0123456789ABCDEF')
        self.assertEqual(len(_called_with), 1)
        self.assertEqual(_called_with[0][0], 'cnlybnq\n\nhowdy folks.\n')
        self.assertEqual(_called_with[0][1], 'text/plain')
        self.assertEqual(_called_with[0][2], False)
示例#21
0
    def test_crackPayload_w_forwarded_message(self):
        from karl.testing import registerUtility
        from karl.utilities.interfaces import IMailinTextScrubber
        _called_with = []
        def _fooScrubber(text, text_mimetype=None, is_reply=False):
            _called_with.append((text, text_mimetype, is_reply))
            return text.upper()
        registerUtility(_fooScrubber, IMailinTextScrubber, 'foo')
        mailin = self._makeOne()
        mailin.text_scrubber = 'foo'
        message = DummyMessage()
        filepart = DummyMessage()
        filepart.filename = 'file1.bin'
        filepart.payload = '0123456789ABCDEF'
        filepart.content_type = 'application/octet-stream'
        forwarded = DummyMessage()
        forwarded.payload = None
        forwarded.filename = "Re: prune script testing."
        forwarded.content_type = 'message/rfc822; name="Re: prune script..."'
        textpart = DummyMessage()
        textpart.payload = 'payload'
        textpart.charset = 'rot13'
        textpart.content_type = 'text/plain'
        textpart2 = DummyMessage()
        textpart2.payload = 'howdy folks.\n'
        textpart2.charset = 'ascii'
        textpart2.content_type = 'text/plain'
        message.payload = (textpart, forwarded, filepart, textpart2)

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'CNLYBNQ\n\nHOWDY FOLKS.\n')
        self.assertEqual(len(attachments), 1)
        filename, mimetype, data = attachments[0]
        self.assertEqual(filename, 'file1.bin')
        self.assertEqual(mimetype, 'application/octet-stream')
        self.assertEqual(data, '0123456789ABCDEF')
        self.assertEqual(len(_called_with), 1)
        self.assertEqual(_called_with[0][0], 'cnlybnq\n\nhowdy folks.\n')
        self.assertEqual(_called_with[0][1], 'text/plain')
        self.assertEqual(_called_with[0][2], False)
示例#22
0
    def test_crackPayload_single_with_scrubber(self):
        from karl.testing import registerUtility
        from karl.utilities.interfaces import IMailinTextScrubber
        _called_with = []
        def _fooScrubber(text, text_mimetype=None, is_reply=False):
            _called_with.append((text, text_mimetype, is_reply))
            return text.upper()
        registerUtility(_fooScrubber, IMailinTextScrubber, 'foo')
        mailin = self._makeOne()
        mailin.text_scrubber = 'foo'
        message = DummyMessage()
        message.payload = 'payload'
        message.content_type = 'text/plain'

        text, attachments = mailin.crackPayload(message)

        self.assertEqual(text, u'PAYLOAD')
        self.assertEqual(len(attachments), 0)
        self.assertEqual(len(_called_with), 1)
        self.assertEqual(_called_with[0][0], 'payload')
        self.assertEqual(_called_with[0][1], 'text/plain')
        self.assertEqual(_called_with[0][2], False)