def test_append(self): imap_client = yield from self.login_user('user@mail', 'pass') self.assertEquals(0, extract_exists((yield from imap_client.examine('INBOX')))) msg = Mail.create(['user@mail'], subject='append msg', content='do you see me ?') self.assertEquals(('OK', ['APPEND completed.']), (yield from imap_client.append(msg.as_bytes(), mailbox='INBOX', flags='FOO BAR', date=datetime.now(tz=utc), ))) self.assertEquals(1, extract_exists((yield from imap_client.examine('INBOX'))))
def test_rfc6851_uidmove(self): self.imapserver.receive(Mail.create(['user'])) imap_client = yield from self.login_user('user', 'pass', select=True) uidvalidity = self.imapserver.get_connection('user').uidvalidity self.assertEqual(('OK', ['OK [COPYUID %d 1:1 1:1]' % uidvalidity, '1 EXPUNGE', 'Done']), (yield from imap_client.uid('move', '1:1', 'Trash'))) self.assertEquals(0, extract_exists((yield from imap_client.select()))) self.assertEquals(1, extract_exists((yield from imap_client.select('Trash'))))
def test_append(self): imap_client = yield from self.login_user('user@mail', 'pass') self.assertEquals(0, extract_exists((yield from imap_client.examine('INBOX')))) msg = Mail.create(['user@mail'], subject='append msg', content='do you see me ?') response = yield from imap_client.append(msg.as_bytes(), mailbox='INBOX', flags='FOO BAR', date=datetime.now(tz=utc), ) self.assertEquals('OK', response.result) self.assertTrue('1] APPEND completed' in response.lines[0]) self.assertEquals(1, extract_exists((yield from imap_client.examine('INBOX'))))
def test_concurrency_3_executing_async_commands_in_parallel(self): # cf valid example in https://tools.ietf.org/html/rfc3501#section-5.5 self.imapserver.receive(Mail.create(['user'])) imap_client = yield from self.login_user('user', 'pass', select=True) store = asyncio.async(imap_client.store('1', '+FLAGS (FOO)')) copy = asyncio.async(imap_client.copy('1', 'MBOX')) expunge = asyncio.async(imap_client.expunge()) yield from asyncio.wait([store, copy, expunge]) self.assertEquals(0, extract_exists((yield from imap_client.select()))) self.assertEquals(1, extract_exists((yield from imap_client.select('MBOX')))) self.assertEqual('1', (yield from imap_client.search('KEYWORD FOO', charset=None)).lines[0])
def test_examine_no_messages(self): imap_client = yield from self.login_user('user', 'pass') self.assertEquals(0, extract_exists((yield from imap_client.examine()))) self.assertEquals(aioimaplib.AUTH, imap_client.protocol.state)
def test_select_no_messages(self): imap_client = yield from self.login_user('user', 'pass') resp = yield from imap_client.select() self.assertEqual('OK', resp[0]) self.assertEqual(0, extract_exists(resp)) self.assertEquals(aioimaplib.SELECTED, imap_client.protocol.state)
def test_expunge_messages(self): self.imapserver.receive(Mail.create(['user'])) self.imapserver.receive(Mail.create(['user'])) imap_client = yield from self.login_user('user', 'pass', select=True) self.assertEquals(('OK', ['1 EXPUNGE', '2 EXPUNGE', 'EXPUNGE completed.']), (yield from imap_client.expunge())) self.assertEquals(0, extract_exists((yield from imap_client.select())))
def test_copy_messages_by_uid(self): self.imapserver.receive(Mail.create(['user'])) imap_client = yield from self.login_user('user', 'pass', select=True) result, _ = yield from imap_client.uid('copy', '1', 'MAILBOX') self.assertEqual('OK', result) self.assertEquals(1, extract_exists((yield from imap_client.select('MAILBOX'))))
def test_rfc4315_uidplus_expunge(self): self.imapserver.receive(Mail.create(['user'])) self.imapserver.receive(Mail.create(['user'])) imap_client = yield from self.login_user('user', 'pass', select=True) self.assertEquals(('OK', ['1 EXPUNGE', 'UID EXPUNGE completed.']), (yield from imap_client.uid('expunge', '1:1'))) self.assertEquals(1, extract_exists((yield from imap_client.select())))
def test_concurrency_4_sync_command_waits_for_async_commands_to_finish(self): self.imapserver.receive(Mail.create(['user'])) imap_client = yield from self.login_user('user', 'pass', select=True) asyncio.async(imap_client.copy('1', 'MBOX')) asyncio.async(imap_client.expunge()) examine = asyncio.async(imap_client.examine('MBOX')) self.assertEquals(1, extract_exists((yield from asyncio.wait_for(examine, 1))))
async def test_copy_messages(self): self.imapserver.receive(Mail.create(['user'])) self.imapserver.receive(Mail.create(['user'])) imap_client = await self.login_user('user', 'pass', select=True) result, _ = await imap_client.copy('1', '2', 'MAILBOX') self.assertEqual('OK', result) self.assertEqual(2, extract_exists((await imap_client.select('MAILBOX'))))
async def test_append(self): imap_client = await self.login_user('user@mail', 'pass') self.assertEqual(0, extract_exists((await imap_client.examine('INBOX')))) msg = Mail.create(['user@mail'], subject='append msg', content='do you see me ?') response = await imap_client.append( msg.as_bytes(), mailbox='INBOX', flags='FOO BAR', date=datetime.now(tz=utc), ) self.assertEqual('OK', response.result) self.assertTrue('1] APPEND completed' in response.lines[0]) self.assertEqual(1, extract_exists((await imap_client.examine('INBOX'))))
def test_copy_messages(self): imap_receive(Mail.create(['user'])) imap_receive(Mail.create(['user'])) imap_client = yield from self.login_user('user', 'pass', select=True) result, _ = yield from imap_client.copy('1', '2', 'MAILBOX') self.assertEqual('OK', result) self.assertEquals( 2, extract_exists((yield from imap_client.select('MAILBOX'))))
def test_append_too_short(self): imap_client = yield from self.login_user('user@mail', 'pass') self.assertEquals( 0, extract_exists((yield from imap_client.examine('INBOX')))) message_bytes = b'do you see me ?' * 2 imap_client.protocol.literal_data = message_bytes[:5] args = ['INBOX', '{%s}' % len(message_bytes)] response = yield from imap_client.protocol.execute( Command('APPEND', imap_client.protocol.new_tag(), *args, loop=self.loop)) self.assertEquals('BAD', response.result) self.assertTrue('expected 30 but was' in response.lines[0])
async def test_examine_no_messages(self): imap_client = await self.login_user('user', 'pass') self.assertEqual(0, extract_exists((await imap_client.examine()))) self.assertEqual(aioimaplib.AUTH, imap_client.protocol.state)