diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2001-07-20 05:00:27 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-07-20 05:00:27 +0800 |
commit | 8a56749aa6d8544544e75a79971144fb0b29fd81 (patch) | |
tree | 9027f438482c02fffb787fb8b5edc3a2111311b8 /camel/camel-mime-utils.c | |
parent | 31fbb7d1dfdec64631a10e05726f0a7b787cb2b7 (diff) | |
download | gsoc2013-evolution-8a56749aa6d8544544e75a79971144fb0b29fd81.tar gsoc2013-evolution-8a56749aa6d8544544e75a79971144fb0b29fd81.tar.gz gsoc2013-evolution-8a56749aa6d8544544e75a79971144fb0b29fd81.tar.bz2 gsoc2013-evolution-8a56749aa6d8544544e75a79971144fb0b29fd81.tar.lz gsoc2013-evolution-8a56749aa6d8544544e75a79971144fb0b29fd81.tar.xz gsoc2013-evolution-8a56749aa6d8544544e75a79971144fb0b29fd81.tar.zst gsoc2013-evolution-8a56749aa6d8544544e75a79971144fb0b29fd81.zip |
Remove my iso8859-1 -> iso-8859-1 hack and use
2001-07-19 Jeffrey Stedfast <fejj@ximian.com>
* camel-mime-utils.c (rfc2047_decode_word): Remove my iso8859-1 ->
iso-8859-1 hack and use camel_charset_get_iconv_friendly_name()
instead.
(rfc2184_decode): Use camel_charset_get_iconv_friendly_name()
* camel.c (camel_init): Call camel_charset_map_init().
* camel-charset-map.c (camel_charset_map_init): New function to
initialize the charset-equivalent lookup table. To be called by
camel_init().
(camel_charset_get_iconv_friendly_name): New function to try and
convert a charset into something that iconv is more likely to
accept.
svn path=/trunk/; revision=11235
Diffstat (limited to 'camel/camel-mime-utils.c')
-rw-r--r-- | camel/camel-mime-utils.c | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index 357c183f02..ba704b19dc 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -904,6 +904,7 @@ rfc2047_decode_word(const char *in, int len) const char *inptr = in+2; const char *inend = in+len-2; const char *inbuf; + const char *charset; char *encname; int tmplen; int ret; @@ -949,19 +950,12 @@ rfc2047_decode_word(const char *in, int len) if (inlen > 0) { /* yuck, all this snot is to setup iconv! */ tmplen = inptr - in - 3; - encname = alloca (tmplen + 2); - - /* Hack to convert charsets like ISO8859-1 to iconv-friendly ISO-8859-1 */ - if (!g_strncasecmp (in + 2, "iso", 3) && *(in + 5) != '-') { - memcpy (encname, in + 2, 3); - encname[3] = '-'; - memcpy (encname + 4, in + 5, tmplen - 3); - tmplen++; - } else { - memcpy (encname, in + 2, tmplen); - } + encname = alloca (tmplen + 1); + memcpy (encname, in + 2, tmplen); encname[tmplen] = '\0'; + charset = camel_charset_get_iconv_friendly_name (encname); + inbuf = decword; outlen = inlen * 6 + 16; @@ -969,27 +963,27 @@ rfc2047_decode_word(const char *in, int len) outbuf = outbase; /* TODO: Should this cache iconv converters? */ - ic = iconv_open ("UTF-8", encname); + ic = iconv_open ("UTF-8", charset); if (ic != (iconv_t)-1) { ret = iconv (ic, &inbuf, &inlen, &outbuf, &outlen); - if (ret>=0) { + if (ret >= 0) { iconv (ic, NULL, 0, &outbuf, &outlen); *outbuf = 0; decoded = g_strdup (outbase); } iconv_close (ic); } else { - w(g_warning("Cannot decode charset, header display may be corrupt: %s: %s", - encname, strerror(errno))); + w(g_warning ("Cannot decode charset, header display may be corrupt: %s: %s", + charset, g_strerror (errno))); /* TODO: Should this do this, or just leave the encoded strings? */ decword[inlen] = 0; - decoded = g_strdup(decword); + decoded = g_strdup (decword); } } } - + d(printf("decoded '%s'\n", decoded)); - + return decoded; } @@ -1166,16 +1160,16 @@ rfc2047_encode_word(GString *outstring, const char *in, int len, const char *typ d(printf("Converting [%d] '%.*s' to %s\n", len, len, in, type)); /* convert utf8->encoding */ - bufflen = len*6+16; - buffer = alloca(bufflen); + bufflen = len * 6 + 16; + buffer = alloca (bufflen); inlen = len; inptr = in; - - ascii = alloca(bufflen); - - if (strcasecmp(type, "UTF-8") != 0) - ic = iconv_open(type, "UTF-8"); - + + ascii = alloca (bufflen); + + if (g_strcasecmp (type, "UTF-8") != 0) + ic = iconv_open (type, "UTF-8"); + while (inlen) { int convlen, i, proclen; @@ -1802,6 +1796,7 @@ rfc2184_decode (const char *in, int len) { const char *inptr = in; const char *inend = in + len; + const char *charset; char *decoded = NULL; char *encoding; @@ -1810,11 +1805,12 @@ rfc2184_decode (const char *in, int len) return NULL; encoding = g_strndup (in, inptr - in); + charset = camel_charset_get_iconv_friendly_name (encoding); + g_free (encoding); + inptr = memchr (inptr + 1, '\'', inend - inptr - 1); - if (!inptr) { - g_free (encoding); + if (!inptr) return NULL; - } inptr++; if (inptr < inend) { @@ -1825,14 +1821,14 @@ rfc2184_decode (const char *in, int len) inbuf = decword = hex_decode (inptr, inend - inptr); inlen = strlen (inbuf); - - ic = iconv_open ("UTF-8", encoding); + + ic = iconv_open ("UTF-8", charset); if (ic != (iconv_t) -1) { int ret; - + outlen = inlen * 6 + 16; outbuf = outbase = g_malloc (outlen); - + ret = iconv (ic, &inbuf, &inlen, &outbuf, &outlen); if (ret >= 0) { iconv (ic, NULL, 0, &outbuf, &outlen); |