From: Wilfried Göesgens Date: Tue, 2 Mar 2010 22:59:44 +0000 (+0000) Subject: * don't use strchr to find the end of the email header; instead iterate over it until... X-Git-Tag: v7.86~343 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=ec3264ea1cfbf34d4a474e9f109d976acbc651a8;p=citadel.git * don't use strchr to find the end of the email header; instead iterate over it untill we run into it anyway --- diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 40635193a..78d5f296d 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -2042,45 +2042,51 @@ START_TEXT: (void *)&ma, 0); } else if (mode == MT_RFC822) { /* unparsed RFC822 dump */ - char *start_of_text = NULL; - start_of_text = strstr(mptr, "\n\r\n"); - if (start_of_text == NULL) start_of_text = strstr(mptr, "\n\n"); - if (start_of_text == NULL) start_of_text = mptr; - ++start_of_text; - start_of_text = strstr(start_of_text, "\n"); - ++start_of_text; + int eoh = 0; char outbuf[1024]; int outlen = 0; int nllen = strlen(nl); prev_ch = 0; - while (ch=*mptr, ch!=0) { - if (ch==13) { + while (*mptr != '\0') { + if (*mptr == '\r') { /* do nothing */ } else { + if ((!eoh) && + (*mptr == '\n')) + { + if (crlf) { + eoh = (*(mptr+1) == '\r') && (*(mptr+2) == '\n'); + } + else { + eoh = *(mptr+1) == '\n'; + } + } + if ( - ((headers_only == HEADERS_NONE) && (mptr >= start_of_text)) - || ((headers_only == HEADERS_ONLY) && (mptr < start_of_text)) + ((headers_only == HEADERS_NONE) && (eoh)) + || ((headers_only == HEADERS_ONLY) && (!eoh)) || ((headers_only != HEADERS_NONE) && (headers_only != HEADERS_ONLY)) ) { - if (ch == 10) { - sprintf(&outbuf[outlen], "%s", nl); + if (*mptr == '\n') { + memcpy(&outbuf[outlen], nl, nllen); outlen += nllen; + outbuf[outlen] = '\0'; } else { - outbuf[outlen++] = ch; + outbuf[outlen++] = *mptr; } } } if (flags & ESC_DOT) { - if ((prev_ch == 10) && (ch == '.') && ((*(mptr+1) == 13) || (*(mptr+1) == 10))) + if ((prev_ch == '\n') && (*mptr == '.') && ((*(mptr+1) == '\r') || (*(mptr+1) == '\n'))) { outbuf[outlen++] = '.'; } } - prev_ch = ch; + prev_ch = *mptr; ++mptr; if (outlen > 1000) { client_write(outbuf, outlen);