def _idle(self):
socket = None<EOL>try:<EOL><INDENT>self.command_tag = (self.command_tag + <NUM_LIT:1>) % <NUM_LIT:1000><EOL>command_tag = b"<STR_LIT:X>" + bytes(str(self.command_tag).zfill(<NUM_LIT:3>), "<STR_LIT:ascii>")<EOL>directories = self.mailbox.split("<STR_LIT:U+002C>")<EOL>self.connection.select(directories[<NUM_LIT:0>])<EOL>socket = self.connection.socket()<EOL>socket.write(command_tag + b"<STR_LIT>")<EOL>try:<EOL><INDENT>response = socket.read(<NUM_LIT>).decode("<STR_LIT:ascii>")<EOL><DEDENT>except socket_error:<EOL><INDENT>raise imaplib.IMAP4.abort("<STR_LIT>")<EOL><DEDENT>if not response.lower().startswith("<STR_LIT>"):<EOL><INDENT>raise imaplib.IMAP4.abort("<STR_LIT>" + str(response))<EOL><DEDENT>socket.settimeout(self.cache_timeout)<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>response = socket.read(<NUM_LIT>).decode("<STR_LIT:ascii>")<EOL>if response.upper().startswith("<STR_LIT>"):<EOL><INDENT>continue  <EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>except socket_error:  <EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>finally:  <EOL><INDENT>if socket is None:<EOL><INDENT>return<EOL><DEDENT>socket.settimeout(self.read_timeout)<EOL>socket.write(b"<STR_LIT>")  <EOL>try:<EOL><INDENT>response = socket.read(<NUM_LIT>).decode("<STR_LIT:ascii>")<EOL><DEDENT>except socket_error:<EOL><INDENT>raise imaplib.IMAP4.abort("<STR_LIT>")<EOL><DEDENT>if response.startswith("<STR_LIT>"):<EOL><INDENT>try:<EOL><INDENT>response = socket.read(<NUM_LIT>).decode("<STR_LIT:ascii>")<EOL><DEDENT>except socket_error:<EOL><INDENT>raise imaplib.IMAP4.abort(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>expected_response = (command_tag + b"<STR_LIT>").decode("<STR_LIT:ascii>")<EOL>if not response.lower().startswith(expected_response.lower()):<EOL><INDENT>raise imaplib.IMAP4.abort("<STR_LIT>" + response)<EOL><DEDENT><DEDENT>
since imaplib doesn't support IMAP4r1 IDLE, we'll do it by hand