text: import re
  
  # Blatantly stolen from https://github.com/athoune/imapidle/blob/master/src/imapidle.py
  # This file is under MIT license (https://github.com/athoune/imapidle/blob/master/LICENSE)
  
  def idle(connection):
  	tag = connection._new_tag()
  	connection.send(b'%s IDLE\r\n' % tag)
  	response = connection.readline()
  	connection.loop = True
  	if response == b'+ idling\r\n':
  		while connection.loop:
  			resp = connection.readline().decode('us-ascii')
  			marker, uid, message = resp.rstrip("\r\n").split(' ', 2)
  			yield uid, message
  	else:
  		raise Exception("IDLE not handled? : %s" % response.decode('us-ascii'))
  
  def done(connection):
  	connection.send(b"DONE\r\n")
  	connection.loop = False
  