From dbe98bddd36330aaca54af847593d05742da3840 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Thu, 31 Aug 2000 01:46:44 +0000 Subject: New function - even though its broken, we'll assume mailers send latin1 2000-08-31 Not Zed * camel-mime-utils.c (append_latin1): New function - even though its broken, we'll assume mailers send latin1 headers instead of us-ascii. We just have to encode high chars into utf-8. (header_decode_text): Call append_latin1 for appending unencoded text segments. svn path=/trunk/; revision=5128 --- camel/camel-mime-utils.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'camel/camel-mime-utils.c') diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index 90d7496ce3..193d9d00c5 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -914,6 +914,28 @@ g_string_append_len(GString *st, const char *s, int l) return g_string_append(st, tmp); } +/* ok, a lot of mailers are BROKEN, and send iso-latin1 encoded + headers, when they should just be sticking to US-ASCII + according to the rfc's. Anyway, since the conversion to utf-8 + is trivial, just do it here without iconv */ +static GString * +append_latin1(GString *out, const char *in, int len) +{ + unsigned int c; + + while (len) { + c = (unsigned int)*in++; + len--; + if (c & 0x80) { + out = g_string_append_c(out, 0xc0 | (c>>6)); /* 110000xx */ + out = g_string_append_c(out, 0x80 | (c&0x3f)); /* 10xxxxxx */ + } else { + out = g_string_append_c(out, c); + } + } + return out; +} + /* decodes a simple text, rfc822 */ static char * header_decode_text(const char *in, int inlen) @@ -934,11 +956,11 @@ header_decode_text(const char *in, int inlen) out = g_string_append_len(out, decword, strlen(decword)); g_free (decword); } else { - out = g_string_append_len(out, inptr, encend-inptr+2); + out = append_latin1(out, inptr, encend-inptr+2); } inptr = encend+2; } - out = g_string_append_len(out, inptr, inend-inptr); + out = append_latin1(out, inptr, inend-inptr); encstart = out->str; g_string_free(out, FALSE); -- cgit v1.2.3