From c54176037fd26a4ec3b8428976d498a33ee0addf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Tue, 16 Mar 2010 21:27:26 +0000 Subject: [PATCH] * fix imap uid fetching: - imap_strip_headers() : fix loading of the line from the buffer - imap_strip_headers() : split evaluation for headers_not/headers so we can more easily determine and abort if we want to print the header - imap_strip_headers() : if ptr IS StrBufNotNULL we're done reading headers - imap_fetch_body() : partial has to be a StrBuf too if its source is; adjust processing accordingly --- citadel/modules/imap/imap_fetch.c | 69 +++++++++++++++++++------------ 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/citadel/modules/imap/imap_fetch.c b/citadel/modules/imap/imap_fetch.c index d0afd3207..1fa4916b9 100644 --- a/citadel/modules/imap/imap_fetch.c +++ b/citadel/modules/imap/imap_fetch.c @@ -504,7 +504,6 @@ void imap_fetch_envelope(struct CtdlMessage *msg) { */ void imap_strip_headers(StrBuf *section) { citimap_command Cmd; - char buf[SIZ]; StrBuf *which_fields = NULL; int doing_headers = 0; int headers_not = 0; @@ -515,14 +514,16 @@ void imap_strip_headers(StrBuf *section) { int ok = 0; int done_headers = 0; const char *Ptr = NULL; + CitContext *CCC = CC; - if (CC->redirect_buffer == NULL) return; + if (CCC->redirect_buffer == NULL) return; which_fields = NewStrBufDup(section); if (!strncasecmp(ChrPtr(which_fields), "HEADER.FIELDS", 13)) doing_headers = 1; - if (!strncasecmp(ChrPtr(which_fields), "HEADER.FIELDS.NOT", 17)) + if (doing_headers && + !strncasecmp(ChrPtr(which_fields), "HEADER.FIELDS.NOT", 17)) headers_not = 1; for (i=0; i < StrLength(which_fields); ++i) { @@ -539,25 +540,33 @@ void imap_strip_headers(StrBuf *section) { Cmd.CmdBuf = which_fields; num_parms = imap_parameterize(&Cmd); - boiled_headers = NewStrBufPlain(NULL, StrLength(CC->redirect_buffer)); + boiled_headers = NewStrBufPlain(NULL, StrLength(CCC->redirect_buffer)); + Line = NewStrBufPlain(NULL, SIZ); Ptr = NULL; ok = 0; do { - StrBufSipLine(CC->redirect_buffer, Line, &Ptr); + StrBufSipLine(Line, CCC->redirect_buffer, &Ptr); if (!isspace(ChrPtr(Line)[0])) { ok = 0; if (doing_headers == 0) ok = 1; else { - if (headers_not) ok = 1; - else ok = 0; - for (i=0; iredirect_buffer); - CC->redirect_buffer = boiled_headers; + FreeStrBuf(&CCC->redirect_buffer); + CCC->redirect_buffer = boiled_headers; FreeStrBuf(&which_fields); FreeStrBuf(&Line); @@ -591,12 +600,13 @@ void imap_strip_headers(StrBuf *section) { void imap_fetch_body(long msgnum, ConstStr item, int is_peek) { struct CtdlMessage *msg = NULL; StrBuf *section; - char partial[SIZ]; + StrBuf *partial; int is_partial = 0; size_t pstart, pbytes; int loading_body_now = 0; int need_body = 1; int burn_the_cache = 0; + CitContext *CCC = CC; /* extract section */ section = NewStrBufPlain(CKEY(item)); @@ -633,16 +643,19 @@ void imap_fetch_body(long msgnum, ConstStr item, int is_peek) { } /* extract partial */ - safestrncpy(partial, item.Key, sizeof partial); - if (strchr(partial, '<') != NULL) { - stripallbut(partial, '<', '>'); + partial = NewStrBufPlain(CKEY(item)); + if (strchr(ChrPtr(partial), '<') != NULL) { + StrBufStripAllBut(partial, '<', '>'); is_partial = 1; } - if (is_partial == 0) strcpy(partial, ""); - /* if (!IsEmptyStr(partial)) CtdlLogPrintf(CTDL_DEBUG, "Partial is %s\n", partial); */ + if (is_partial == 0) + if (StrLength(partial) > 0) + CtdlLogPrintf(CTDL_DEBUG, + "Partial is %s\n", + ChrPtr(partial)); if (IMAP->cached_body == NULL) { - CC->redirect_buffer = NewStrBufPlain(NULL, SIZ); + CCC->redirect_buffer = NewStrBufPlain(NULL, SIZ); loading_body_now = 1; msg = CtdlFetchMessage(msgnum, (need_body ? 1 : 0)); } @@ -693,8 +706,8 @@ void imap_fetch_body(long msgnum, ConstStr item, int is_peek) { } if (loading_body_now) { - IMAP->cached_body_len = StrLength(CC->redirect_buffer); - IMAP->cached_body = SmashStrBuf(&CC->redirect_buffer); + IMAP->cached_body_len = StrLength(CCC->redirect_buffer); + IMAP->cached_body = SmashStrBuf(&CCC->redirect_buffer); IMAP->cached_bodymsgnum = msgnum; IMAP->cached_body_withbody = need_body; strcpy(IMAP->cached_bodypart, ChrPtr(section)); @@ -706,13 +719,15 @@ void imap_fetch_body(long msgnum, ConstStr item, int is_peek) { pbytes = IMAP->cached_body_len; } else { - sscanf(partial, SIZE_T_FMT "." SIZE_T_FMT, &pstart, &pbytes); + sscanf(ChrPtr(partial), SIZE_T_FMT "." SIZE_T_FMT, &pstart, &pbytes); if (pbytes > (IMAP->cached_body_len - pstart)) { pbytes = IMAP->cached_body_len - pstart; } cprintf("BODY[%s]<" SIZE_T_FMT "> {" SIZE_T_FMT "}\r\n", ChrPtr(section), pstart, pbytes); } + FreeStrBuf(&partial); + /* Here we go -- output it */ client_write(&IMAP->cached_body[pstart], pbytes); -- 2.30.2