PDA

View Full Version : How to end reading POP3 server's response before its actual end, is this a good idea?



kremuwa
4th July 2010, 22:33
In my program, I'm sending a command: "TOP X 200" to a POP3 server, for every mail from a given mailbox (X is the number of the mail), because I want to gather information about the mail's subject and attachment name. But in a lot of cases I don't need all these 200 lines because information I need are in, let's say, first 80 lines of a response for such a TOP command. While reading the response from the server, if I will find out that I already have the information I need and there are still 120 lines to read - do I must read them or is there a way to stop reading and going to the next mail? If so, how to do it and is it at least worth anything?

tbscope
4th July 2010, 22:45
You can't just stop a data stream unless there's a command to let the server know how many lines you want or to stop sending.

In these cases, you can set the read buffer size, or count the lines when you're receiving the packets.
If you've read the buffer (when setting the size) or are at 80 lines, just disconnect from the server.

This, however comes at a cost!
If the server requires a log in, you do need to connect and log in again. In some cases, the extra overhead of establishing the connection again might be too costly and reading all the data might be quicker.

kremuwa
4th July 2010, 22:49
Thank you for such a quick reply. I think I'll just try to figure out what is the minimal number of lines which I must ask for to gather the information I need. Thanks again.