From ff8bc3108abda5bcb07fb5417d8dac5bdbd39fa1 Mon Sep 17 00:00:00 2001 From: NotZed Date: Wed, 3 May 2000 04:20:26 +0000 Subject: [PATCH] If the iconv handle is -1, then dont try and convert (crashes 2000-05-03 NotZed * camel-mime-utils.c (rfc2047_decode_word): If the iconv handle is -1, then dont try and convert (crashes unicode_iconv?). (rfc2047_decode_word): Use alloca for variables instead of g_malloc - by the rfc they should always be short. (rfc2047_decode_word): If we can't do the charset conversion, undo the quoted-printable/base64 at least? Should probably convert unknown characters to the utf-8 unknown character. svn path=/trunk/; revision=2774 --- camel/ChangeLog | 10 ++++++++++ camel/camel-mime-utils.c | 27 +++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/camel/ChangeLog b/camel/ChangeLog index d65d890542..d2aec28651 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,13 @@ +2000-05-03 NotZed + + * camel-mime-utils.c (rfc2047_decode_word): If the iconv handle is + -1, then dont try and convert (crashes unicode_iconv?). + (rfc2047_decode_word): Use alloca for variables instead of + g_malloc - by the rfc they should always be short. + (rfc2047_decode_word): If we can't do the charset conversion, undo + the quoted-printable/base64 at least? Should probably convert + unknown characters to the utf-8 unknown character. + 2000-05-02 Larry Ewing * camel-mime-utils.c (header_decode_date): fix typo when diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index 6c9645b6c8..3f4c4d99d3 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -680,9 +680,10 @@ rfc2047_decode_word(const char *in, int len) if (inptr!=NULL && inptr0) { /* yuck, all this snot is to setup iconv! */ tmplen = inptr-in-3; @@ -705,21 +707,26 @@ rfc2047_decode_word(const char *in, int len) inbuf = decword; outlen = inlen*6; - outbase = g_malloc(outlen); + outbase = alloca(outlen); outbuf = outbase; + /* TODO: Should this cache iconv converters? */ ic = unicode_iconv_open("utf-8", encname); - ret = unicode_iconv(ic, (const char **)&inbuf, &inlen, &outbuf, &outlen); - unicode_iconv_close(ic); - if (ret>=0) { - *outbuf = 0; - decoded = outbase; - outbase = NULL; + if (ic != (unicode_iconv_t)-1) { + ret = unicode_iconv(ic, (const char **)&inbuf, &inlen, &outbuf, &outlen); + unicode_iconv_close(ic); + if (ret>=0) { + *outbuf = 0; + decoded = g_strdup(outbase); + } + } else { + g_warning("Cannot decode charset, header display may be corrupt: %s: %s", encname, strerror(errno)); + /* TODO: Should this do this, or just leave the encoded strings? */ + decword[inlen] = 0; + decoded = g_strdup(decword); } } } - free(outbase); - free(decword); d(printf("decoded '%s'\n", decoded));