tags:

views:

58

answers:

2

I'm trying to build a basic POP3 mail client in C/++, but I've run into a bit of an issue. Since you have to define the buffer size when building the program, but a message can be arbitrarily large, how do you, say, get the mail server to send it to you in parts? And if this isn't the correct means of solving the problem, what is?

And while I'm here, can anyone confirm for me that RFC 2822 is still the current document defining email layout?

Thanks

A: 

If you are reading from a socket, you can specify the number of bytes you wish to read. Also, you can allocate a buffer dynamically at run-time using new.

Dima
+3  A: 

Since most email is done using TCP/IP, you can read one byte at a time if you really want to. The underlying implementation will buffer the stream for you. It is received approximately 1,400 bytes at a time off of the network. Generally, I using either std::vector<char> or std::string as a buffer and read one byte at a time and push_back on to the buffer in a select() loop with a short timeout.

I can't remember if POP includes a maximum line length or not. If it does, then you can use that as your buffer size and call reserve() on the vector. That will minimize memory reallocations and copies that might otherwise occur.

As for which standard is most recent, http://tools.ietf.org/html/rfc2822 says that it was obsoleted by http://tools.ietf.org/html/rfc5322. I usually check http://tools.ietf.org/html/rfcXXXX where XXXX is the RFC number. If it is obsolete, then there is a link to the most appropriate RFC at the top.

And as a final mention, don't build a POP client for deployment without a good reason too. There are a lot of gotcha's buried in the various RFCs. It is a really good learning experience though.

D.Shawley
Thanks for all that, it's fantastic.I have no real plans for using the client at all, I just like to learn how things work. I find these days, with laissez-faire implementations of POP like gmail, even professionally-built clients fall apart, so I wouldn't trust mine as far as I could throw it.
wyatt