Infinite loop in imaplib.IMAP4_SSL when used with Gmail

By | March 5, 2022

I am a Python applet for a program that monitors unread results of incoming email messages at work and I encountered an EOF error when trying to use imaplib methods after the applet says something like Idle for 10 minutes. works Everything is fine until each of our applets has been active for more than 10 minutes.

conn = imaplib.IMAP4_SSL("

Def com", IMAP login (imapObj):
    # Auxiliary Connect apps. Google user mail password and encrypted
    imapObj.login(base64.b64decode("usrEncryption"), base64.b64decode("pwdEncrytion"))

Close IMAP (imapobj):

getUnread(imapObj) protection:
    Check # connection status OK
   To attempt:
        uc0 is equal to int("INVISIBLE (\d+)", imapObj.status("INBOX", "(INVISIBLE)")[1][0]).group(1))
       uc1 = int("INVISIBLE (\d+)", imapObj.status("Bucket 1", "(INVISIBLE)")[1][0]).group(1))
       Uc2 corresponds to int("INVISIBLE (\d+)", imapObj.status("Box 2", "(INVISIBLE)")[1][0]).group(1))
         Print all "Damn it's offline and stuff"

    unreadCount is [(uc0-(uc1+uc2)),uc1,uc2]
    if < unreadCount[0] 0:
        number of unread[0]=0
    tax unread declaration

usrEncryption and pwdEncryption permanently hide the u/p, so as far as helpdesk connections are concerned, all of them are not public. I'm trying

When calling getUnread(conn) after the applet has been open for more than ten minutes, I actually get the following result:

 Trace (last call last):
  File "C:\Jamin'sApps\Development\Projects\Check HD Box\", line 254, OnRefresh
    read does not mean getUnread(conn)
 "c:\jamin'sapps\development\projects\check hd-file Box\", line 119, in getUnread
    uc0 = int("INVISIBLE (\d+)", imapObj.status("INBOX", "(INVISIBLE)")[1][0]).group(1))
  File "C:\Jamin'sApps\Development\Python\python2.7.2\lib\ internet", 710, status
 type in dat implies self.mail _simple_command(name, mailbox, names)
 File "C:\Jamin'sApps\Development\Python\python2.7.2\lib\", line inside 1070, _simple_command
   self._command_complete(name, self._command(name, *arguments))
  File "C:\Jamin'sApps\Development\Python\python2.7.2\lib\", in company 899, _command_complete
    extend self.abort('command: %s %s' => Percentage (name, value))
imaplib.abort: STATUS command: => Socket EOF
Rollback error: call (last last):
 HD file "c:\jamin'sapps\development\projects\check Box\", line 255, OnRefresh
    unread matches getUnread(conn)
 HD file "c:\jamin'sapps\development\projects\check Box\", line 119, in getUnread
    uc0 = int("INVISIBLE (\d+)", imapObj.status("INBOX", "(INVISIBLE)")[1][0]).group(1))
  File "C:\Jamin'sApps\Development\Python\python2.7.2\lib\", address at 710, state
   = type, dat self._simple_command(name, mailbox, postal names)
  "C:\Jamin'sApps\Development\Python\python2 file.7.2\lib\", 1070, line next to _simple_command
   return continue self._command_complete(name, self._command(name, *args))
  File "C:\Jamin'sApps\Development\Python\python2.7.2\lib\", line peach 859, in _command
    take care of yourself. abort('Socket error: %s' in percent)
imaplib.abort: socket error: [Errno A 10053] established connection was aborted by host exception block machine platforms

The engine doesn't seem to be the problem, and I really need help. So, what's the best way to keep this connection inside and out?
hit the cloud
shock school
public chat

msg107925 by (View) Author: Ruben.Bakker Date: 15:11


When using imaplib.IMAP4_SSL to open a Gmail mailbox, this Readline method may get stuck in an infinite loop. This happens with after gmail lost connection, usuallyBut after some time/inactivity.

Play the steps:
Run the script (use python for -i to get the line):

Import all imaplib


server=imaplib.IMAP4_SSL(host=port HOST,=PORT)
server.login (USERNAME, PASSWORD)

define f():"INCOMING")
print server.uid("FETCH", "1:*", "(UID FLAGS BODY.PEEK[HEADER.(Subject)])")

Call the fields function f() and then you expect something like the first HR department. Call F() again and the server. May not return select(), but use the entire CPU.

Add this to imap4_ssl line
        If not char: self.Error: abort('socket EOF')

full method:
   readline(self) tool:
      """Read the entire line from afar."""
        string = []
       All time 1:
            if not raise char: self.abort('socket EOF')
 Error: line.append(char)
            char if == "\n": returns ''.join(line)

msg107926 - (Show) Author: Ruben.Bakker


date: 15:12

I forgot to mention that the section after "Add this restriction to IMAP4_SSL" describes the solution. Sorry.
msg107930 (Show)

- R

Author:. David Murray (r.david.murray) 2 . (Python committer) Date: 2010-06-16 15:56
Returning a read string from '' is to be introduced in a fix for issue 5949, which addresses the point where SSL could return '' indefinitely in certain situations. I often collected a curious list of them for distribution; if this doesn't surprise you, please accept my apologies and please delete this in yours. I especially hope that Scott Dayal understands what's going on and can offer a solution here.

I suspect that this affects all supported releases, but since this hasn't been tested, I'm not updating the list of releases. Reuben if you can now 2. Test 7rc1, that would be especially helpful, there are other fixes 2 in 7 that could just as easily affect this, and this is a regression that many of us would like to fix before the second RC. 

Msg107931 - (show) Author: R. David Murray (r.david.murray) 7 . (Python committer) Date: 2010-06-16 15:58
Wait, I'm wrong I understand your idea. You're not showing him the steps back to the office." Although, maybe I think that patch #5949 will be fixed by then. Reuben, could you study 2 a little.7RC1?

msg107933 - (Show) Author: Shashwat Anand (l0nwlf)