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!