コード例 #1
0
 def fetch_email_messages(self, messages, _class=None):
     """Retrieve messages as Python email Messages.
     *messages* is a list of message IDs to retrieve.
     The optional *_class* is passed to the `email.parser.Parser` that
     generates the Message.
     A dictionary is returned, indexed by message number. Values are
     instances of `email.message.Message` or `email.message.EmailMessage`
     depending on the *_class* used and the version of Python.
     """
     rv = dict()
     i = self.fetch(messages, 'RFC822')
     # print('i: ', i)
     for message_id, content in iteritems(i):
         # print('content: ', content)
         try:
             email_message = email.message_from_bytes(
                 content[b'RFC822'], _class
             )
         except AttributeError:
             # For Python 2.7
             if _class is None:
                 from email.message import Message
                 _class = Message
             email_message = email.message_from_string(
                 to_unicode(content[b'RFC822']), _class
             )
         rv[message_id] = email_message
     return rv
コード例 #2
0
ファイル: livetest.py プロジェクト: zrose584/imapclient
    def test_list_folders(self):
        some_folders = ['simple', b'simple2', 'L\xffR']
        if not self.is_fastmail():
            some_folders.extend([r'test"folder"', br'foo\bar'])
        some_folders = self.add_prefix_to_folders(some_folders)
        for name in some_folders:
            self.client.create_folder(name)

        folders = self.all_test_folder_names()
        self.assertGreater(len(folders), 1, 'No folders visible on server')
        self.assertIn(self.base_folder, folders)
        for name in some_folders:
            self.assertIn(to_unicode(name), folders)
コード例 #3
0
ファイル: livetest.py プロジェクト: nylas/imapclient
    def test_list_folders(self):
        some_folders = ['simple', b'simple2', 'L\xffR']
        if not self.is_fastmail():
            some_folders.extend([r'test"folder"', br'foo\bar'])
        some_folders = self.add_prefix_to_folders(some_folders)
        for name in some_folders:
            self.client.create_folder(name)

        folders = self.all_test_folder_names()
        self.assertGreater(len(folders), 1, 'No folders visible on server')
        self.assertIn(self.base_folder, folders)
        for name in some_folders:
            self.assertIn(to_unicode(name), folders)
コード例 #4
0
ファイル: livetest.py プロジェクト: zrose584/imapclient
    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
コード例 #5
0
ファイル: livetest.py プロジェクト: nylas/imapclient
    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