Carriage Returns In SMTP Server Responses
Posted: Thu Mar 24, 2016 7:06 am
I made a commercial product based on a NetBurner - it has been selling for years. It uses email, but I've found that it doesn't work with the Microsoft Office 365 cloud-based email servers. After the EHLO command verb, their servers' multi-lined response has 2 carriage returns followed by a line feed after each line (CR CR LF, or 0x0D 0x0D 0x0A), which confuses NNDK's code (I altered the formatting here for clarity):
RFC 5321, Section 4.2.1, demands only 1 CR and 1 LF from the server. When I telnet into the server from a Windows machine (while 'logging all' with terminal emulator software "putty" and reading its logs using the tool "HxD"), everything looks proper. So I assume the NNDK is adding a CR somewhere deep in its TCP code (since the Windows server is unable to discern the distant OS via only its socket?), but my admittedly brief attempt at a NNDK code search got me lost.
Microsoft support tells me that there are sometimes issues with "newlines" between disparate systems (like NNDK's GNU/GCC and Microsoft's Windows server). This seems to be supported by Wikipedia's newline article.
Before I start hacking at NNDK's internals to bandage it, I wanted others' takes on whether my thoughts are correct, and whether I should deal with it differently. Thank you!
Code: Select all
/* From ssl_mailto.cpp... */
/*
code result is nnn- xxxxx\r\n
until nnn is a space...
*/
int ReadMultiLineResponse( int fd, char * buffer, int size, DWORD timeout ) {
DWORD now=TimeTick;
int count=0;
char * LastLine=NULL;
int state=0;
while(1) {
int rv = ReadWithTimeout( fd, buffer+count, size-count, timeout );
if(rv>0) {
SaveToMailLog(buffer+count, rv);
if(LastLine==NULL) LastLine=buffer;
for(int i=0; i<rv; i++) {
if(buffer[count+i]=='\r') // ONLY CONSIDERS ONE <CR>.
state=1;
else
if ((buffer[count+i]=='\n') && (state==1)) { //We are reading \r\n
state=2;
//was the last line xxx- or xxx
char * cpe=buffer+count+i;
char * cpscan=LastLine;
while ((*cpscan>='0') && (*cpscan<='9') && (cpscan<cpe)) cpscan++;
if(*cpscan==' ') return count+rv;
} else {
if(state==2) { LastLine=buffer+count+i; }
state=0;
}
}
count+=rv;
if(count>=(size-1)) return count;
} else // if(!(rv>0))...
return rv;
if ((timeout) && ((now+timeout)<TimeTick)) return count;
} // End of while(1).
return count;
} // End of ReadMultiLineResponse().
Microsoft support tells me that there are sometimes issues with "newlines" between disparate systems (like NNDK's GNU/GCC and Microsoft's Windows server). This seems to be supported by Wikipedia's newline article.
Before I start hacking at NNDK's internals to bandage it, I wanted others' takes on whether my thoughts are correct, and whether I should deal with it differently. Thank you!