[issue9010] Infinite loop in imaplib.IMAP4_SSL when used with Gmail

2010-06-17 Thread Ruben Bakker

Ruben Bakker ruben.bakk...@gmail.com added the comment:

I installed Python 2.7RC1 on Mac OS X 10.6.3 and tried my script and it
worked for me. Imaplib throws the right exception instead of looping
forever:

Traceback (most recent call last):
  File stdin, line 1, in module
  File imapmail/explore/test2.py, line 30, in f
server.select(INBOX)
  File
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/imaplib.py,
line 642, in select
typ, dat = self._simple_command(name, mailbox)
  File
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/imaplib.py,
line 1060, in _simple_command
return self._command_complete(name, self._command(name, *args))
  File
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/imaplib.py,
line 890, in _command_complete
raise self.abort('command: %s = %s' % (name, val))
imaplib.abort: command: SELECT = socket error: EOF


On Wed, Jun 16, 2010 at 6:12 PM, Shashwat Anand rep...@bugs.python.orgwrote:


 Shashwat Anand anand.shash...@gmail.com added the comment:

 import imaplib

 HOST=imap.gmail.com
 PORT=993
 USERNAME=usern...@gmail.com
 PASSWORD=password

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

 def f():
print server.select(INBOX)
print server.uid(FETCH, 1:*, (UID FLAGS BODY.PEEK[HEADER.FIELDS
 (Subject)]))

 Call the f() function and then wait about about an hour. Call f() again and
 server.select() will not return but take all CPU.

 Tried to reproduce this on Python 2.7RC1. Seemed Ok to me. Took some 3
 seconds to call f() not only once, but twice, thrice.

 --
 nosy: +l0nwlf

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue9010
 ___


--
Added file: http://bugs.python.org/file17695/unnamed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9010
___I installed Python 2.7RC1 on Mac OS X 10.6.3 and tried my script and it worked 
for me. Imaplib throws the right exception instead of looping 
forever:divbr/divdivdivgt;gt;gt; f()/divdivTraceback (most 
recent call last):/div

div  File quot;lt;stdingt;quot;, line 1, in 
lt;modulegt;/divdiv  File quot;imapmail/explore/test2.pyquot;, line 
30, in f/divdiv    server.select(quot;INBOXquot;)/divdiv  File 
quot;/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/imaplib.pyquot;,
 line 642, in select/div

div    typ, dat = self._simple_command(name, mailbox)/divdiv  File 
quot;/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/imaplib.pyquot;,
 line 1060, in _simple_command/divdiv    return 
self._command_complete(name, self._command(name, *args))/div

div  File 
quot;/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/imaplib.pyquot;,
 line 890, in _command_complete/divdiv    raise self.abort(#39;command: 
%s =gt; %s#39; % (name, val))/divdivimaplib.abort: command: SELECT =gt; 
socket error: EOF/div

divgt;gt;gt; /divdivbr/divdivbr/divdivbrdiv 
class=gmail_quoteOn Wed, Jun 16, 2010 at 6:12 PM, Shashwat Anand span 
dir=ltrlt;a 
href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;/span 
wrote:br

blockquote class=gmail_quote style=margin:0 0 0 .8ex;border-left:1px #ccc 
solid;padding-left:1ex;br
Shashwat Anand lt;a 
href=mailto:anand.shash...@gmail.com;anand.shash...@gmail.com/agt; added 
the comment:br
div class=imbr
quot;import imaplibbr
br
HOST=quot;a href=http://imap.gmail.com; 
target=_blankimap.gmail.com/aquot;br
PORT=993br
USERNAME=quot;a 
href=mailto:usern...@gmail.com;usern...@gmail.com/aquot;br
PASSWORD=quot;passwordquot;br
br
server = imaplib.IMAP4_SSL(host=HOST, port=PORT)br
server.login(USERNAME, PASSWORD)br
br
def f():br
        print server.select(quot;INBOXquot;)br
        print server.uid(quot;FETCHquot;, quot;1:*quot;, quot;(UID 
FLAGS BODY.PEEK[HEADER.FIELDS (Subject)])quot;)br
br
Call the f() function and then wait about about an hour. Call f() again and 
server.select() will not return but take all CPU.quot;br
br
/divTried to reproduce this on Python 2.7RC1. Seemed Ok to me. Took some 3 
seconds to call f() not only once, but twice, thrice.br
br
--br
nosy: +l0nwlfbr
divdiv/divdiv class=h5br
___br
Python tracker lt;a 
href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;br
lt;a href=http://bugs.python.org/issue9010; 
target=_blankhttp://bugs.python.org/issue9010/agt;br
___br
/div/div/blockquote/divbrbr clear=allbr-- brRuben 
Bakkerbruncomplex gmbhbra 
href=http://mailplaneapp.com;http://mailplaneapp.com/abr
/div/div
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9010] Infinite loop in imaplib.IMAP4_SSL when used with Gmail

2010-06-16 Thread Ruben Bakker

New submission from Ruben Bakker ruben.bakk...@gmail.com:

When using imaplib.IMAP4_SSL to open a Gmail mailbox, the readline method can 
go into a infinite loop. It happens after Gmail drops the connection, usually 
after some time/inactivity. The next imaplib request will cause the infinite 
loop inside the readline() method.

Steps to reproduce:
Perform this script (use python -i to get the prompt):

import imaplib

HOST=imap.gmail.com
PORT=993
USERNAME=usern...@gmail.com
PASSWORD=password

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

def f():
print server.select(INBOX)
print server.uid(FETCH, 1:*, (UID FLAGS BODY.PEEK[HEADER.FIELDS 
(Subject)]))

Call the f() function and then wait about about an hour. Call f() again and 
server.select() will not return but take all CPU.

Add this line in IMAP4_SSL
  if not char: raise self.abort('socket error: EOF')

complete method:
def readline(self):
Read line from remote.
line = []
while 1:
char = self.sslobj.read(1)
if not char: raise self.abort('socket error: EOF')
line.append(char)
if char == \n: return ''.join(line)

--
components: Library (Lib)
messages: 107925
nosy: Ruben.Bakker
priority: normal
severity: normal
status: open
title: Infinite loop in imaplib.IMAP4_SSL when used with Gmail
type: behavior
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9010
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9010] Infinite loop in imaplib.IMAP4_SSL when used with Gmail

2010-06-16 Thread Ruben Bakker

Ruben Bakker ruben.bakk...@gmail.com added the comment:

I forgot to mention that the section after Add this line to IMAP4_SSL 
describes the solution. Sorry about that.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9010
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com