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
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>orstd::stringas a buffer and read one byte at a time andpush_backon to the buffer in aselect()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, https://www.rfc-editor.org/rfc/rfc2822 says that it was obsoleted by https://www.rfc-editor.org/rfc/rfc5322. I usually check
https://www.rfc-editor.org/rfc/rfcXXXXwhereXXXXis 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.