From 8f17757a08a497abbc982c2d7b64a57b9ef7a8c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Tue, 29 Jan 2008 21:46:11 +0000 Subject: [PATCH] * don't double evaluate the first pair; some nice comments --- webcit/messages.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/webcit/messages.c b/webcit/messages.c index 9cfc2e81a..6fec9cc45 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -112,16 +112,22 @@ void utf8ify_rfc822_string(char *buf) { } } + /* pre evaluate the first pair */ + end = NULL; len = strlen(buf); start = strstr(buf, "=?"); - while ((start != NULL) && - ((end = strstr(start, "?=")) != NULL)) + if (start != NULL) + end = strstr(start, "?="); + + while ((start != NULL) && (end != NULL)) { next = strstr(end, "=?"); if (next != NULL) nextend = strstr(next, "?="); if (nextend == NULL) next = NULL; + + /* did we find two partitions */ if ((next != NULL) && ((next - end) > 2)) { @@ -132,21 +138,26 @@ void utf8ify_rfc822_string(char *buf) { (*ptr == '\n') || (*ptr == '\t'))) ptr ++; - // did we find a gab just filled with blanks? + /* did we find a gab just filled with blanks? */ if (ptr == next) { memmove (end + 2, next, len - (next - start)); - // now fill the gab at the end with blanks + + /* now terminate the gab at the end */ delta = (next - end) - 2; len -= delta; buf[len] = '\0'; - // move next to its new location. - next = end + 2; + + /* move next to its new location. */ + next -= delta; + nextend -= delta; } } + /* our next-pair is our new first pair now. */ start = next; + end = nextend; } /** Now we handle foreign character sets properly encoded -- 2.39.2