From 09d3b87661723d9d59cdd64119213ac3b75da581 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Mon, 3 Nov 2008 23:20:50 +0000 Subject: [PATCH] * if we decode a RFC 822 Message, output the charset we found, so the user can use it later. --- libcitadel/lib/libcitadel.h | 2 +- libcitadel/lib/stringbuf.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 66d15c2b0..7223456a8 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -265,7 +265,7 @@ void StrBufReplaceChars(StrBuf *buf, char search, char replace); int CompressBuffer(StrBuf *Buf); void StrBufConvert(StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic); void ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic); -void StrBuf_RFC822_to_Utf8(StrBuf *Target, StrBuf *DecodeMe, const StrBuf* DefaultCharset); +void StrBuf_RFC822_to_Utf8(StrBuf *Target, StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset); int StrBufDecodeBase64(StrBuf *Buf); int StrBufRFC2047encode(StrBuf **target, const StrBuf *source); #define LB (1) /* Internal escape chars */ diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index ab7dfb886..ba8fdec4a 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -1602,7 +1602,8 @@ inline static void DecodeSegment(StrBuf *Target, char *SegmentStart, char *SegmentEnd, StrBuf *ConvertBuf, - StrBuf *ConvertBuf2) + StrBuf *ConvertBuf2, + StrBuf *FoundCharset) { StrBuf StaticBuf; char charset[128]; @@ -1616,6 +1617,10 @@ inline static void DecodeSegment(StrBuf *Target, StaticBuf.BufUsed = SegmentEnd - SegmentStart; StaticBuf.BufSize = DecodeMe->BufSize - (SegmentStart - DecodeMe->buf); extract_token(charset, SegmentStart, 1, '?', sizeof charset); + if (FoundCharset != NULL) { + FlushStrBuf(FoundCharset); + StrBufAppendBufPlain(FoundCharset, charset, -1, 0); + } extract_token(encoding, SegmentStart, 2, '?', sizeof encoding); StrBufExtract_token(ConvertBuf, &StaticBuf, 3, '?'); @@ -1658,7 +1663,7 @@ inline static void DecodeSegment(StrBuf *Target, * Handle subjects with RFC2047 encoding such as: * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?= */ -void StrBuf_RFC822_to_Utf8(StrBuf *Target, StrBuf *DecodeMe, const StrBuf* DefaultCharset) +void StrBuf_RFC822_to_Utf8(StrBuf *Target, StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset) { StrBuf *ConvertBuf, *ConvertBuf2; char *start, *end, *next, *nextend, *ptr; @@ -1752,7 +1757,8 @@ void StrBuf_RFC822_to_Utf8(StrBuf *Target, StrBuf *DecodeMe, const StrBuf* Defau start, end, ConvertBuf, - ConvertBuf2); + ConvertBuf2, + FoundCharset); next = strstr(end, "=?"); nextend = NULL; -- 2.39.2