py3status/modules/imap.py
def _idle(self):
        """
        since imaplib doesn't support IMAP4r1 IDLE, we'll do it by hand
        """
        socket = None

        try:
            # build a new command tag (Xnnn) as bytes:
            self.command_tag = (self.command_tag + 1) % 1000
            command_tag = b'X' + bytes(str(self.command_tag).zfill(3), 'ascii')

            # make sure we have selected anything before idling:
            directories = self.mailbox.split(',')
            self.connection.select(directories[0])

            socket = self.connection.socket()

            # send IDLE command and check response:
            socket.write(command_tag + b' IDLE\r\n')
            try:
                response = socket.read(4096).decode('ascii')
            except socket_error:
                raise imaplib.IMAP4.abort("Server didn't respond to 'IDLE' in time")
            if not response.lower().startswith('+ idling'):
                raise imaplib.IMAP4.abort("While initializing IDLE: " + str(response))

            # wait for changes (EXISTS, EXPUNGE, etc.):
            socket.settimeout(self.cache_timeout)
            while True:
                try:
                    response = socket.read(4096).decode('ascii')
                    if response.upper().startswith('* OK'):
                        continue  # ignore '* OK Still here'
                    else:
                        break
                except socket_error:  # IDLE timed out
                    break

        finally:  # terminate IDLE command gracefully
            if socket is None:
                return

            socket.settimeout(self.read_timeout)
            socket.write(b'DONE\r\n')  # important! Can't query IMAP again otherwise
            try:
                response = socket.read(4096).decode('ascii')
            except socket_error:
                raise imaplib.IMAP4.abort("Server didn't respond to 'DONE' in time")

            # sometimes, more messages come in between reading and DONEing; so read them again:
            if response.startswith('* '):
                try:
                    response = socket.read(4096).decode('ascii')
                except socket_error:
                    raise imaplib.IMAP4.abort("Server sent more continuations, but no 'DONE' ack")

            expected_response = (command_tag + b' OK').decode('ascii')
            if not response.lower().startswith(expected_response.lower()):
                raise imaplib.IMAP4.abort("While terminating IDLE: " + response)

        since imaplib doesn't support IMAP4r1 IDLE, we'll do it by hand
        
since imaplib doesn't support IMAP4r1 IDLE, we'll do it by hand
since imaplib doesn ' t support IMAP4r1 IDLE we ' ll do it by hand
def _idle(self):
        socket = None
        try:
            self.command_tag = (self.command_tag + 1) % 1000
            command_tag = b'X' + bytes(str(self.command_tag).zfill(3), 'ascii')
            directories = self.mailbox.split(',')
            self.connection.select(directories[0])
            socket = self.connection.socket()
            socket.write(command_tag + b' IDLE\r\n')
            try:
                response = socket.read(4096).decode('ascii')
            except socket_error:
                raise imaplib.IMAP4.abort("Server didn't respond to 'IDLE' in time")
            if not response.lower().startswith('+ idling'):
                raise imaplib.IMAP4.abort("While initializing IDLE: " + str(response))
            socket.settimeout(self.cache_timeout)
            while True:
                try:
                    response = socket.read(4096).decode('ascii')
                    if response.upper().startswith('* OK'):
                        continue  
                    else:
                        break
                except socket_error:  
                    break
        finally:  
            if socket is None:
                return
            socket.settimeout(self.read_timeout)
            socket.write(b'DONE\r\n')  
            try:
                response = socket.read(4096).decode('ascii')
            except socket_error:
                raise imaplib.IMAP4.abort("Server didn't respond to 'DONE' in time")
            if response.startswith('* '):
                try:
                    response = socket.read(4096).decode('ascii')
                except socket_error:
                    raise imaplib.IMAP4.abort("Server sent more continuations, but no 'DONE' ack")
            expected_response = (command_tag + b' OK').decode('ascii')
            if not response.lower().startswith(expected_response.lower()):
                raise imaplib.IMAP4.abort("While terminating IDLE: " + response)
def _idle ( self ) : socket = None try : self . command_tag = ( self . command_tag + 1 ) % 1000 command_tag = b'X' + bytes ( str ( self . command_tag ) . zfill ( 3 ) , 'ascii' ) directories = self . mailbox . split ( ',' ) self . connection . select ( directories [ 0 ] ) socket = self . connection . socket ( ) socket . write ( command_tag + b' IDLE\r\n' ) try : response = socket . read ( 4096 ) . decode ( 'ascii' ) except socket_error : raise imaplib . IMAP4 . abort ( "Server didn't respond to 'IDLE' in time" ) if not response . lower ( ) . startswith ( '+ idling' ) : raise imaplib . IMAP4 . abort ( "While initializing IDLE: " + str ( response ) ) socket . settimeout ( self . cache_timeout ) while True : try : response = socket . read ( 4096 ) . decode ( 'ascii' ) if response . upper ( ) . startswith ( '* OK' ) : continue else : break except socket_error : break finally : if socket is None : return socket . settimeout ( self . read_timeout ) socket . write ( b'DONE\r\n' ) try : response = socket . read ( 4096 ) . decode ( 'ascii' ) except socket_error : raise imaplib . IMAP4 . abort ( "Server didn't respond to 'DONE' in time" ) if response . startswith ( '* ' ) : try : response = socket . read ( 4096 ) . decode ( 'ascii' ) except socket_error : raise imaplib . IMAP4 . abort ( "Server sent more continuations, but no 'DONE' ack" ) expected_response = ( command_tag + b' OK' ) . decode ( 'ascii' ) if not response . lower ( ) . startswith ( expected_response . lower ( ) ) : raise imaplib . IMAP4 . abort ( "While terminating IDLE: " + response )
since imaplib doesn't support IMAP4r1 IDLE, we'll do it by hand
since imaplib doesn ' t support IMAP4r1 IDLE we ' ll do it by hand
"""
        since imaplib doesn't support IMAP4r1 IDLE, we'll do it by hand
        """ # build a new command tag (Xnnn) as bytes: # make sure we have selected anything before idling: # send IDLE command and check response: # wait for changes (EXISTS, EXPUNGE, etc.): # ignore '* OK Still here' # IDLE timed out # terminate IDLE command gracefully # important! Can't query IMAP again otherwise # sometimes, more messages come in between reading and DONEing; so read them again:
self