[Twisted-Python] POP3 improvements

Abe Fettig abe at fettig.net
Mon Dec 30 11:27:23 EST 2002

Over the weekend I was working on adding POP3 support to the messaging
library I'm working on.  I noticed that while downloading large messages
from a POP3 server on my local network my test app would use 100% CPU,
and would stop responding to events until it finished downloading the

Looking at the twisted.protocols.pop3.POP3Client code I saw that it was
handling downloaded messages by concatenating a string, adding one line
at a time.  This seemed like an inefficient way to do it, so I modified
the code to use a file-like object instead.  The result is much faster,
and gives you the option of writing a downloading message to a file as
it comes in rather than keeping it all in memory.

The modified POP3Client (attached) still has some work to be done, but I
was hoping to get some comments from the list first.  

Currently it works like this:  When you send a command that returns a
multi-line response (LIST or RETR), you pass an optional file-like
object that the response should be written to.  If no file argument is
supplied a StringIO is used.  When the server is finished sending the
response, handle_COMMANDNAME is called, passing back the file object
containing the downloaded response.

At this point I'm still not correcting byte-stuffed lines in downloaded
messages, so I need to do that.  Also, if it would be OK with everyone,
I think it might be nice to make POP3Client a little higher-level, so
that LIST, for example, would return an actual list instead of a file
(or, in the current implementation, a string) that the implementer has
to parse.  And it might be good to offer support for more POP3 commands
like TOP.

If somebody could take a look at my code and tell me what I'd need to do
to make it meet the Twisted standards I'd appreciate it.

(There are also some improvements that could probably be made to the
POP3 server code, but I thought those could wait 'till later).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: pop3support.py
Type: text/x-python
Size: 7903 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20021230/7c92bc9e/attachment.py 

More information about the Twisted-Python mailing list