Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_uid_with_illegal_command(self):
imap_client = yield from self.login_user('user', 'pass', select=True)
for command in {'COPY', 'FETCH', 'STORE'}.symmetric_difference(Commands.keys()):
with self.assertRaises(aioimaplib.Abort) as expected:
yield from imap_client.uid(command)
self.assertEqual(expected.exception.args,
('command UID only possible with COPY, FETCH or STORE (was %s)' % command,))
def test_login(self):
imap_client = aioimaplib.IMAP4(port=12345, loop=self.loop, timeout=3)
yield from asyncio.wait_for(imap_client.wait_hello_from_server(), 2)
result, data = yield from imap_client.login('user', 'password')
self.assertEquals(aioimaplib.AUTH, imap_client.protocol.state)
self.assertEqual('OK', result)
self.assertEqual('LOGIN completed', data[-1])
def test_capabilities(self):
imap_client = aioimaplib.IMAP4(port=12345, loop=self.loop)
yield from asyncio.wait_for(imap_client.wait_hello_from_server(), 2)
self.assertEquals('IMAP4REV1', imap_client.protocol.imap_version)
self.assertEquals(['IMAP4rev1', 'LITERAL+', 'IDLE'], imap_client.protocol.capabilities)
def login_user(self, login, password, select=False, lib=aioimaplib.IMAP4):
imap_client = aioimaplib.IMAP4(port=12345, loop=self.loop, timeout=3)
yield from asyncio.wait_for(imap_client.wait_hello_from_server(), 2)
yield from imap_client.login('user', 'password')
if select:
yield from imap_client.select()
return imap_client
def login_user(self, login, password, select=False, lib=aioimaplib.IMAP4):
imap_client = aioimaplib.IMAP4(port=12345, loop=self.loop, timeout=3)
yield from asyncio.wait_for(imap_client.wait_hello_from_server(), 2)
yield from imap_client.login('user', 'password')
if select:
yield from imap_client.select()
return imap_client
def test_login_twice(self):
with self.assertRaises(aioimaplib.Error) as expected:
imap_client = yield from self.login_user('user', 'pass')
yield from imap_client.login('user', 'password')
self.assertEqual(expected.exception.args, ('command LOGIN illegal in state AUTH',))
def fetch_mail(host, user, password):
imap_client = aioimaplib.IMAP4_SSL(host=host)
yield from imap_client.wait_hello_from_server()
yield from imap_client.login(user, password)
res, data = yield from imap_client.select()
print('there is %s messages INBOX' % data[0])
yield from imap_client.logout()
def test_split_responses_with_message_data_expunge(self):
self.assertEquals([b'* 123 EXPUNGE', b'TAG OK SELECT completed.'],
_split_responses(b'* 123 EXPUNGE\r\nTAG OK SELECT completed.\r\n'))
def test_split_responses_regular_lines(self):
self.assertEquals([b'* BYE Logging out', b'CAPB2 OK LOGOUT completed'],
_split_responses(b'* BYE Logging out\r\nCAPB2 OK LOGOUT completed\r\n'))
def test_split_responses_with_message_data(self):
self.assertEquals([b'* FETCH ...\r\n(mail content)\r\n...\r\n)',
b'TAG OK FETCH completed.'],
_split_responses(
b'* 1 FETCH (UID 1 RFC822 {26}\r\n...\r\n(mail content)\r\n...\r\n)\r\n'
b'TAG OK FETCH completed.'))