'Connects with IMAP and asserts the existence of an email, then deletes it'

def assertIMAPReceived(self, subject):

    import imaplib
    sleep(1)
    m = imaplib.IMAP4_SSL(TEST_SERVER, 993)
    m.login(TEST_ADDRESS, TEST_PASSWORD)
    m.select()
    (typ, data) = m.search(None, '(SUBJECT    "{}")'.format(subject))
    self.assertTrue(len(data[0].split()), 1)
    m.store(data[0].strip(), '+FLAGS', '\\Deleted')
    m.expunge()
    m.close()
    m.logout()
