From: Art Cancro Date: Thu, 20 Nov 2008 21:09:55 +0000 (+0000) Subject: Fixed a serious problem with IMAP header fetch. memreadline() returns a pointer... X-Git-Tag: v7.86~1786 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=64c5deb3abadc256b390413fe34a1cd9d5b4046d Fixed a serious problem with IMAP header fetch. memreadline() returns a pointer to the *next* line, or null if we're at the end. In the IMAP header parsing routine we were checking for null at the top of a while loop, where we should have been checking for null at the end of a do-while loop. As a result, the last header line was being discarded under any circumstances. --- diff --git a/citadel/modules/imap/imap_fetch.c b/citadel/modules/imap/imap_fetch.c index 75a05dbb4..2aedb2117 100644 --- a/citadel/modules/imap/imap_fetch.c +++ b/citadel/modules/imap/imap_fetch.c @@ -530,7 +530,8 @@ void imap_strip_headers(char *section) { ptr = CC->redirect_buffer; ok = 0; - while ( (done_headers == 0) && (ptr = memreadline(ptr, buf, sizeof buf), *ptr != 0) ) { + do { + ptr = memreadline(ptr, buf, sizeof buf); if (!isspace(buf[0])) { ok = 0; if (doing_headers == 0) ok = 1; @@ -556,7 +557,8 @@ void imap_strip_headers(char *section) { if (IsEmptyStr(buf)) done_headers = 1; if (buf[0]=='\r') done_headers = 1; if (buf[0]=='\n') done_headers = 1; - } + if (*ptr == 0) done_headers = 1; + } while (!done_headers); strcat(boiled_headers, "\r\n"); @@ -924,12 +926,13 @@ void imap_fetch_bodystructure (long msgnum, char *item, CC->redirect_alloc = 0; ptr = rfc822; - while (ptr = memreadline(ptr, buf, sizeof buf), *ptr != 0) { + do { + ptr = memreadline(ptr, buf, sizeof buf); ++lines; if ((IsEmptyStr(buf)) && (rfc822_body == NULL)) { rfc822_body = ptr; } - } + } while (*ptr != 0); rfc822_headers_len = rfc822_body - rfc822; rfc822_body_len = rfc822_len - rfc822_headers_len;