* if we decode a RFC 822 Message, output the charset we found, so the user can use...
authorWilfried Göesgens <willi@citadel.org>
Mon, 3 Nov 2008 23:20:50 +0000 (23:20 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 3 Nov 2008 23:20:50 +0000 (23:20 +0000)
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index 66d15c2b0658a686aab6b5639c64d06e6d704b2a..7223456a8899b80462ed0ea267ece22e4715dd84 100644 (file)
@@ -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 */
index ab7dfb88661cbd34a709e4f329c2b57bfa4b11d7..ba8fdec4af7289d1b5e9151bed1de795e864df8d 100644 (file)
@@ -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;