Beispiel #1
0
 def test_from_config(self):
     connection = IMAPConnection.from_dict(
         self.config['connections']['test-imap'])
     filter_ = MessageFilter.from_dict(
         self.config['filters']['facebook-notification'],
         {'test-imap': connection})
     self.assertIsNotNone(filter_)
Beispiel #2
0
    def test_timeout(self):

        c = IMAPConnection.from_dict(self.config['connections']['gmail-imap'])

        _LOG.debug('sleeping for 5m20s...')
        time.sleep(5 * 60 + 20)
        _LOG.debug('finished sleeping')

        c.connect()
Beispiel #3
0
 def test_retrieve_folders(self):
     for connection_name in ['test-imap', 'test-imap-ssl']:
         with self.subTest(msg=connection_name):
             connection = IMAPConnection.from_dict(
                 self.config['connections'][connection_name])
             connection.connect()
             folders = connection.retrieve_folders()
             connection.disconnect()
             self.assertGreater(len(folders), 0, msg=connection)
             self.assertIn('INBOX', folders, msg=connection)
Beispiel #4
0
 def test_delete_message(self):
     connection = IMAPConnection.from_dict(
         self.config['connections']['test-imap-ssl'])
     connection.connect()
     ids = connection.retrieve_message_ids()
     connection.delete_message(ids[-1], 'INBOX')
     connection.purge_deleted_messages()
     # with self.assertRaises(RuntimeError):
     #     connection.delete_message(ids[-1], 'INBOX')
     connection.delete_message(ids[-2], 'INBOX', purge_immediately=True)
     connection.disconnect()
Beispiel #5
0
 def test_retrieve_message_ids(self):
     for connection_name in ['test-imap', 'test-imap-ssl']:
         with self.subTest(msg=connection_name):
             connection = IMAPConnection.from_dict(
                 self.config['connections'][connection_name])
             connection.connect()
             connection.open_folder('INBOX')
             ids = connection.retrieve_message_ids('INBOX')
             connection.disconnect()
             self.assertIsInstance(ids, list, msg=type(ids))
             for id_ in ids:
                 self.assertIsInstance(id_, int, msg=ids)
Beispiel #6
0
    def test_timeout_after_connect(self):

        c = IMAPConnection.from_dict(self.config['connections']['gmail-imap'])
        c.connect()

        _LOG.debug('sleeping for 5 minutes...')
        time.sleep(5 * 60)
        _LOG.debug('finished sleeping')

        self.assertTrue(c.is_alive())

        _LOG.debug('sleeping for 5.5 minutes...')
        time.sleep(5.5 * 60)
        _LOG.debug('finished sleeping')

        self.assertFalse(c.is_alive())
Beispiel #7
0
 def test_from_email_message(self):
     config = load_config(_TEST_CONFIG_PATH)
     folder = 'INBOX'
     connection = IMAPConnection.from_dict(
         config['connections']['test-imap-ssl'])
     connection.connect()
     connection.open_folder(folder)
     ids = connection.retrieve_message_ids()
     messages_data = connection.retrieve_messages_parts(
         ids[:1], ['BODY.PEEK[]'])
     connection.disconnect()
     _, body = messages_data[0]
     message = Message(email.message_from_bytes(body), connection, folder,
                       1)
     _LOG.debug('%s', message.from_address)
     _LOG.debug('%s', message.subject)
     self.assertGreater(len(message.from_address), 0)
     self.assertGreater(len(str(message.subject)), 0)
Beispiel #8
0
 def test_retrieve_messages_parts(self):
     for connection_name in ['test-imap', 'test-imap-ssl']:
         with self.subTest(msg=connection_name):
             connection = IMAPConnection.from_dict(
                 self.config['connections'][connection_name])
             connection.connect()
             connection.open_folder()
             ids = connection.retrieve_message_ids()
             msgs1 = connection.retrieve_messages_parts(
                 ids[:2], ['UID', 'ENVELOPE'])
             msgs2 = connection.retrieve_messages_parts(
                 ids[:2], ['BODY.PEEK[]'])
             connection.close_folder()
             alive = connection.is_alive()
             connection.disconnect()
             for env, msg in msgs1:
                 # print('uid+envelope', len(env), len(msg) if isinstance(msg, bytes) else msg)
                 self.assertGreater(len(env), 0, msg=msgs1)
                 self.assertIsNone(msg, msg=msgs1)
             for env, msg in msgs2:
                 # print('body', len(env), len(msg) if isinstance(msg, bytes) else msg)
                 self.assertGreater(len(env), 0, msg=msgs2)
                 self.assertGreater(len(msg), 0, msg=msgs2)
             self.assertTrue(alive, msg=connection)