![](https://secure.gravatar.com/avatar/6cd37343ce1da139b1d2ff5ee717f5d5.jpg?s=120&d=mm&r=g)
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 message. 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). Abe