* found new bug in the RFC822 Decoder
authorWilfried Göesgens <willi@citadel.org>
Sat, 20 Feb 2010 14:16:03 +0000 (14:16 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 20 Feb 2010 14:16:03 +0000 (14:16 +0000)
libcitadel/lib/stringbuf.c
libcitadel/tests/stringbuf_conversion.c

index 502afd8b9a14ea3bf2a3c09e94f40b8d82344efe..1029a34ac0638175d3324801854864a4672e4658 100644 (file)
@@ -2595,7 +2595,7 @@ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf*
 #endif
        const char *eptr;
        int passes = 0;
-       int i, len, delta;
+       int i, len;
        int illegal_non_rfc2047_encoding = 0;
 
        /* Sometimes, badly formed messages contain strings which were simply
@@ -2692,22 +2692,16 @@ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf*
                                (*ptr == '\n') || 
                                (*ptr == '\t')))
                                ptr ++;
-                       /* did we find a gab just filled with blanks? */
-                       if (ptr == next)
+                       /* 
+                        * did we find a gab just filled with blanks?
+                        * if not, copy its stuff over.
+                        */
+                       if (ptr != next)
                        {
-                               long gap = next - start;
-                               memmove (end + 2,
-                                        next,
-                                        len - (gap));
-                               len -= gap;
-                               /* now terminate the gab at the end */
-                               delta = (next - end) - 2; ////TODO: const! 
-                               ((StrBuf*)DecodeMee)->BufUsed -= delta;
-                               ((StrBuf*)DecodeMee)->buf[DecodeMee->BufUsed] = '\0';
-
-                               /* move next to its new location. */
-                               next -= delta;
-                               nextend -= delta;
+                               StrBufAppendBufPlain(Target, 
+                                                    end + 2, 
+                                                    next - end - 2,
+                                                    0);
                        }
                }
                /* our next-pair is our new first pair now. */
index 5c7c36fbba1845049f16e2d53df85488ad2d0448..85ae46eec93d031cbe22b0997b799aa0d3c963a4 100644 (file)
@@ -88,6 +88,21 @@ static void TestRFC822Decode(void)
        FreeStrBuf(&Target);
        FreeStrBuf(&FoundCharset);
        FreeStrBuf(&DefaultCharset);
+
+
+       DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
+       FoundCharset = NewStrBuf();
+       Source = NewStrBufPlain(HKEY("\"w.goesgens\" <w.goesgens@aoeuaoeuaoeu.org>, =?ISO-8859-15?Q?Walter_?= =?ISO-8859-15?Q?G=F6aoeus?= <aoeuaoeu@aoe.de>, =?ISO-8859-15?Q?aoeuaoeuh?= =?ISO-8859-15?Q?_G=F6aoeus?= <aoeuoeuaoeu@oeu.de>, aoeuao aoeuaoeu <aoeuaoeuaoeaoe@aoe.de"));
+       Target = NewStrBufPlain(NULL, 256);
+
+       StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
+       TestRevalidateStrBuf(Target);
+       printf("the ugly multi:>%s<\n", ChrPtr(Target));
+       FreeStrBuf(&Source);
+       FreeStrBuf(&Target);
+       FreeStrBuf(&FoundCharset);
+       FreeStrBuf(&DefaultCharset);
+
 }