Пример #1
0
        def test_fetch(self):
            # Generate a fresh message-id each time because Gmail is
            # clever and will treat appends of messages with
            # previously seen message-ids as the same message. This
            # breaks our tests when the test message is updated.
            msg_id_header = make_msgid()
            msg = ("Message-ID: %s\r\n" % msg_id_header) + MULTIPART_MESSAGE

            self.client.select_folder(self.base_folder)
            self.append_msg(msg)
            self.client.normalise_times = False

            fields = ["RFC822", b"FLAGS", "INTERNALDATE", "ENVELOPE"]
            msg_id = self.client.search()[0]
            resp = self.client.fetch(msg_id, fields)

            self.assertEqual(len(resp), 1)
            msginfo = resp[msg_id]

            extra_fields = [b"SEQ"]
            if self.condstore_enabled:
                extra_fields.append(b"MODSEQ")
            self.assertSetEqual(
                set(msginfo.keys()),
                set([to_bytes(f) for f in fields] + extra_fields),
            )
            self.assertEqual(msginfo[b"SEQ"], 1)
            self.assertEqual(msginfo[b"RFC822"], to_bytes(msg))
            self.assertIsInstance(msginfo[b"INTERNALDATE"], datetime)
            self.assertIsInstance(msginfo[b"FLAGS"], tuple)
            self.assertSequenceEqual(
                msginfo[b"ENVELOPE"],
                Envelope(
                    datetime(2010, 3, 16, 16, 45, 32, tzinfo=FixedOffset(0)),
                    b"A multipart message",
                    (Address(b"Bob Smith", None, b"bob", b"smith.com"), ),
                    (Address(b"Bob Smith", None, b"bob", b"smith.com"), ),
                    (Address(b"Bob Smith", None, b"bob", b"smith.com"), ),
                    (
                        Address(b"Some One", None, b"some", b"one.com"),
                        Address(None, None, b"foo", b"foo.com"),
                    ),
                    None,
                    None,
                    None,
                    to_bytes(msg_id_header),
                ),
            )
Пример #2
0
 def _flagtest(func, args, expected_flags):
     answer = func(msg_id, *args)
     self.assertTrue(msg_id in answer)
     answer_flags = set(answer[msg_id])
     answer_flags.discard(RECENT)  # Might be present but don't care
     self.assertSetEqual(answer_flags,
                         set(to_bytes(f) for f in expected_flags))
Пример #3
0
        def check_append(self, in_message, out_message):
            # Message time microseconds are set to 0 because the server will return
            # time with only seconds precision.
            msg_time = datetime.now().replace(microsecond=0)

            # Append message
            resp = self.client.append(self.base_folder, in_message,
                                      ('abc', 'def'), msg_time)
            self.assertIsInstance(resp, binary_type)

            # Retrieve the just added message and check that all looks well
            self.assertEqual(
                self.client.select_folder(self.base_folder)[b'EXISTS'], 1)

            resp = self.client.fetch(self.client.search()[0],
                                     ('RFC822', 'FLAGS', 'INTERNALDATE'))

            self.assertEqual(len(resp), 1)
            msginfo = tuple(resp.values())[0]

            # Time should match the time we specified
            returned_msg_time = msginfo[b'INTERNALDATE']
            self.assertIsNone(returned_msg_time.tzinfo)
            self.assertEqual(returned_msg_time, msg_time)

            # Flags should be the same
            self.assertIn(b'abc', msginfo[b'FLAGS'])
            self.assertIn(b'def', msginfo[b'FLAGS'])

            # Message body should match
            self.assertEqual(msginfo[b'RFC822'], to_bytes(out_message))
Пример #4
0
        def check_append(self, in_message, out_message):
            # Message time microseconds are set to 0 because the server will return
            # time with only seconds precision.
            msg_time = datetime.now().replace(microsecond=0)

            # Append message
            resp = self.client.append(self.base_folder, in_message, ('abc', 'def'), msg_time)
            self.assertIsInstance(resp, binary_type)

            # Retrieve the just added message and check that all looks well
            self.assertEqual(self.client.select_folder(self.base_folder)[b'EXISTS'], 1)

            resp = self.client.fetch(self.client.search()[0], ('RFC822', 'FLAGS', 'INTERNALDATE'))

            self.assertEqual(len(resp), 1)
            msginfo = tuple(resp.values())[0]

            # Time should match the time we specified
            returned_msg_time = msginfo[b'INTERNALDATE']
            self.assertIsNone(returned_msg_time.tzinfo)
            self.assertEqual(returned_msg_time, msg_time)

            # Flags should be the same
            self.assertIn(b'abc', msginfo[b'FLAGS'])
            self.assertIn(b'def', msginfo[b'FLAGS'])

            # Message body should match
            self.assertEqual(msginfo[b'RFC822'], to_bytes(out_message))
Пример #5
0
        def test_getacl(self):
            self.skip_unless_capable('ACL')

            folder = self.add_prefix_to_folder('test_acl')
            self.client.create_folder(folder)

            who = to_bytes(conf['username'])
            rights = self.client.getacl(folder)
            self.assertIn(who, [u for u, r in rights])
Пример #6
0
        def test_getacl(self):
            self.skip_unless_capable('ACL')

            folder = self.add_prefix_to_folder('test_acl')
            self.client.create_folder(folder)

            who = to_bytes(conf['username'])
            rights = self.client.getacl(folder)
            self.assertIn(who, [u for u, r in rights])
Пример #7
0
        def test_fetch(self):
            # Generate a fresh message-id each time because Gmail is
            # clever and will treat appends of messages with
            # previously seen message-ids as the same message. This
            # breaks our tests when the test message is updated.
            msg_id_header = make_msgid()
            msg = ('Message-ID: %s\r\n' % msg_id_header) + MULTIPART_MESSAGE

            self.client.select_folder(self.base_folder)
            self.append_msg(msg)
            self.client.normalise_times = False

            fields = ['RFC822', b'FLAGS', 'INTERNALDATE', 'ENVELOPE']
            msg_id = self.client.search()[0]
            resp = self.client.fetch(msg_id, fields)

            self.assertEqual(len(resp), 1)
            msginfo = resp[msg_id]

            extra_fields = [b'SEQ']
            if self.condstore_enabled:
                extra_fields.append(b'MODSEQ')
            self.assertSetEqual(
                set(msginfo.keys()),
                set([to_bytes(f) for f in fields] + extra_fields),
            )
            self.assertEqual(msginfo[b'SEQ'], 1)
            self.assertEqual(msginfo[b'RFC822'], to_bytes(msg))
            self.assertIsInstance(msginfo[b'INTERNALDATE'], datetime)
            self.assertIsInstance(msginfo[b'FLAGS'], tuple)
            self.assertSequenceEqual(
                msginfo[b'ENVELOPE'],
                Envelope(
                    datetime(2010, 3, 16, 16, 45, 32,
                             tzinfo=FixedOffset(0)), b'A multipart message',
                    (Address(b'Bob Smith', None, b'bob', b'smith.com'), ),
                    (Address(b'Bob Smith', None, b'bob', b'smith.com'), ),
                    (Address(b'Bob Smith', None, b'bob', b'smith.com'), ),
                    (Address(b'Some One', None, b'some', b'one.com'),
                     Address(None, None, b'foo', b'foo.com')), None, None,
                    None, to_bytes(msg_id_header)))
Пример #8
0
        def test_fetch(self):
            # Generate a fresh message-id each time because Gmail is
            # clever and will treat appends of messages with
            # previously seen message-ids as the same message. This
            # breaks our tests when the test message is updated.
            msg_id_header = make_msgid()
            msg = ('Message-ID: %s\r\n' % msg_id_header) + MULTIPART_MESSAGE

            self.client.select_folder(self.base_folder)
            self.append_msg(msg)
            self.client.normalise_times = False

            fields = ['RFC822', b'FLAGS', 'INTERNALDATE', 'ENVELOPE']
            msg_id = self.client.search()[0]
            resp = self.client.fetch(msg_id, fields)

            self.assertEqual(len(resp), 1)
            msginfo = resp[msg_id]

            extra_fields = [b'SEQ']
            if self.condstore_enabled:
                extra_fields.append(b'MODSEQ')
            self.assertSetEqual(
                set(msginfo.keys()),
                set([to_bytes(f) for f in fields] + extra_fields),
            )
            self.assertEqual(msginfo[b'SEQ'], 1)
            self.assertEqual(msginfo[b'RFC822'], to_bytes(msg))
            self.assertIsInstance(msginfo[b'INTERNALDATE'], datetime)
            self.assertIsInstance(msginfo[b'FLAGS'], tuple)
            self.assertSequenceEqual(msginfo[b'ENVELOPE'],
                                     Envelope(
                datetime(2010, 3, 16, 16, 45, 32, tzinfo=FixedOffset(0)),
                b'A multipart message',
                (Address(b'Bob Smith', None, b'bob', b'smith.com'),),
                (Address(b'Bob Smith', None, b'bob', b'smith.com'),),
                (Address(b'Bob Smith', None, b'bob', b'smith.com'),),
                (Address(b'Some One', None, b'some', b'one.com'),
                 Address(None, None, b'foo', b'foo.com')),
                None, None, None, to_bytes(msg_id_header)))
Пример #9
0
    def run_folder_tests(self, folder_names, folder_encode):
        self.client.folder_encode = folder_encode
        try:
            folder_names = self.add_prefix_to_folders(folder_names)

            for folder in folder_names:
                self.assertFalse(self.client.folder_exists(folder))

                self.client.create_folder(folder)

                self.assertTrue(self.client.folder_exists(folder))

                self.assertIn(
                    to_unicode(folder) if folder_encode else to_bytes(folder),
                    self.all_test_folder_names())

                self.client.select_folder(folder)
                self.client.close_folder()

                self.client.delete_folder(folder)
                self.assertFalse(self.client.folder_exists(folder))
        finally:
            self.client.folder_encode = True
Пример #10
0
    def run_folder_tests(self, folder_names, folder_encode):
        self.client.folder_encode = folder_encode
        try:
            folder_names = self.add_prefix_to_folders(folder_names)

            for folder in folder_names:
                self.assertFalse(self.client.folder_exists(folder))

                self.client.create_folder(folder)

                self.assertTrue(self.client.folder_exists(folder))

                self.assertIn(
                    to_unicode(folder) if folder_encode else to_bytes(folder),
                    self.all_test_folder_names()
                )

                self.client.select_folder(folder)
                self.client.close_folder()

                self.client.delete_folder(folder)
                self.assertFalse(self.client.folder_exists(folder))
        finally:
            self.client.folder_encode = True
Пример #11
0
 def _flagtest(func, args, expected_flags):
     answer = func(msg_id, *args)
     self.assertTrue(msg_id in answer)
     answer_flags = set(answer[msg_id])
     answer_flags.discard(RECENT)  # Might be present but don't care
     self.assertSetEqual(answer_flags, set(to_bytes(f) for f in expected_flags))