[Patches] [ python-Patches-632934 ] Problem at the end of misformed mailbox

noreply@sourceforge.net noreply@sourceforge.net
Sun, 03 Nov 2002 08:50:48 -0800


Patches item #632934, was opened at 2002-11-03 17:50
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=632934&group_id=5470

Category: Library (Lib)
Group: Python 2.2.x
Status: Open
Resolution: None
Priority: 5
Submitted By: Rémi Peyronnet (rpeyron)
Assigned to: Nobody/Anonymous (nobody)
Summary: Problem at the end of misformed mailbox

Initial Comment:
I had a problem with a not well formed mailbox (maybe 
ambiguous carriage return chars, due to both use under 
windows and linux) : the function mailbox.readlines 
(lib/mailbox.py:66) entered in an indefinite cycle.

I found that the self.stop value was too big for the file, 
and that the index of self.pos could not go that far. The 
function readlines will call ever and ever readline, which 
will return always the same 1-length string.

I solved this by comparing the fp.pos before and after 
the read operation. If it the same, we re probably at the 
end of the file, or there is a problem, and we should go 
out.

As I do not know much about the Python internals, the 
following patch may not be good :

C:\Python222\Lib>diff "Copie de mailbox.py"  mailbox.py
63c63,68
<         self.pos = self.fp.tell()
---
>         data = self.fp.readline(length)
>         self_fp_tell = self.fp.tell()
>         if self.pos == self_fp_tell:
>           return ''
>         else:
>           self.pos = self_fp_tell

Regards

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=632934&group_id=5470