def clean_tmp_mailboxes(cls, account): with imap.login(account) as conn: responses = conn.list_mailboxes(MAILBOX_PREFIX, "*") for response in responses: mbox_name = response.mailbox.decode("ASCII", errors="strict") print('Deleting mailbox "%s"' % mbox_name) conn.delete_mailbox(response.mailbox)
def _thread_main(self): try: with imap.login(self.account) as self.conn: self.conn.select_mailbox(self.mbox, readonly=True) # Add an event to let the the main thread know we have started # successfully. self.events.put(None) self._main_loop() except Exception as ex: self.events.put(ex) self.conn = None
def test_copy(self, dest_conn, dest_mbox, examiner): with imap.login(self.account) as src_conn: with self.tmp_mbox(src_conn) as src_mbox: src_conn.select_mailbox(src_mbox.name) msg = random_message() src_conn.append_msg(src_mbox.name, msg) src_conn.copy(1, dest_mbox) response = examiner.expect_event(b"EXISTS", 1) # Fetch the message from the dest mailbox, # and make sure it is the same as the source message. # We have to at least send a noop on the dest conn # so that it sees an EXISTS response for the new message # before it can fetch it. Use wait_for_exists() to do this. dest_conn.wait_for_exists(timeout=1) fetched_msg = dest_conn.fetch_msg(1) self.assert_msg_equal(fetched_msg, msg)
def test_login(self): conn = imap.login(self.account) conn.close()
def test_wrapper(self): with imap.login(self.account) as conn: with self.tmp_mbox(conn) as mbox: with self.examiner(mbox) as examiner: conn.select_mailbox(mbox.name) fn(self, conn, mbox.name, examiner)
def test_wrapper(self): with imap.login(self.account) as conn: fn(self, conn)
def get_conn(self): return imap.login(self.server.get_account())