views:

77

answers:

3

This is from the POP3 RFC.

"Responses to certain commands are multi-line. In these cases, which are clearly indicated below, after sending the first line of the response and a CRLF, any additional lines are sent, each terminated by a CRLF pair. When all lines of the response have been sent, a final line is sent, consisting of a termination octet (decimal code 046, ".") and a CRLF pair. If any line of the multi-line response begins with the termination octet, the line is "byte-stuffed" by pre-pending the termination octet to that line of the response. Hence a multi-line response is terminated with the five octets "CRLF.CRLF". When examining a multi-line response, the client checks to see if the line begins with the termination octet. If so and if octets other than CRLF follow, the first octet of the line (the termination octet) is stripped away. If so and if CRLF immediately follows the termination character, then the response from the POP server is ended and the line containing ".CRLF" is not considered part of the multi-line response."

Well, i have problem with this, for example gmail sometimes sends the termination octet and then in the NEXT LINE sends the CRLF pair. For example:

"+OK blah blah\r\n"
"blah blah.\r\n"
"\r\n"

That's very rare, but it happens sometimes, so obviously i'm unable to determine the end of the message in such case, because i'm expecting a line that consists of '.\r\n'. Seriously, is Gmail violating the POP3 protocol or i'm doing something wrong? Also i have a second question, english is not my first language so i cannot understand that completely:

"If any line of the multi-line response begins with the termination octet, the line is "byte-stuffed" by pre-pending the termination octet to that line of the response. Hence a multi-line response is terminated with the five octets "CRLF.CRLF"."

When exactly CRLF.CRLF is used? Can someone gives me a simple example? The rfc says that is used when any line of the response begins with the termination octet. But i don't see any lines that starts with '.' in the messages that are terminated with CRLF.CRLF. I checked that. Maybe i don't understand something, that's why i'm asking.

+1  A: 

It would help very much if you posted the code you are using to read the socket. But I will attempt to answer the second part of your question with this example:

If the response is:

hello world\r\n
we are doing fine\r\n
.500 is same as one-half\r\n
this is the last line\r\n

the server must send it as:

hello world\r\n
we are doing fine\r\n
..500 is same as one-half\r\n
this is the last line\r\n
.\r\n

So you can see where it 'byte stuffed' an extra '.' so the '.500' can be distinguished as part of the response. Also the final five octets are '\r\n.\r\n'.

Amardeep
A: 

Well, here's the code, it's c# code.

msgLength = networkStream.Read(readBuffer, 0, readBuffer.Length); msg = Encoding.ASCII.GetString(readBuffer, 0, msgLength);

"So you can see where it 'byte stuffed' an extra '.'"

Well, i checked for messages that starts with '.', i said that there are not such messages, i was wrong, sorry. Here is one of them:

".com/gamespot/shared/newsletter/2007redesign/daily/medal.gif\">score: blah blah"

I didn't posted the whole message because it's too long and the rest of it is not important. So, Gmail doesn't send extra '.', it's just one '.' at the beginning of the line.

According to the RFC, if you receive that line (`.com/gamespot/shared...`) you should parse it as `com/gamespot/shared...`. This is because it matches the phrase *"If so and if octets other than CRLF follow..."* in the quoted section.
caf
A: 

So, if a line starts with a '.' and there are other octets other than CRLF, the dot should be removed and the message will be terminated with CRLF.CRLF, and if there is no line that starts with '.' the message will be terminated with .CRLF, that's what the RFC says. But i'm not sure why i should remove the dot from the beginning at the line i gave in the example, because in this exact case the dot represents a dot from an web address. Also i don't know if server is doing something wrong but i'm reciving messages like this sometimes(it's an extremely rare case though):

+OK blah blah
blah blah\r\n.
\r\n

The last line is \r\n, that exact message doesn't contain a line that starts with '.' so obviously i should look for a line that consists of ".CRLF", but i have only CRLF in this case, the dot is in the previous received message. Is the server doing something wrong or i just don't get something? I'm going crazy with this stuff.