diff options
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 11 | ||||
-rw-r--r-- | camel/camel-charset-map.c | 35 | ||||
-rw-r--r-- | camel/camel-charset-map.h | 2 | ||||
-rw-r--r-- | camel/camel-sasl-digest-md5.c | 13 |
4 files changed, 58 insertions, 3 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 8027680908..99abe595ea 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,5 +1,16 @@ 2001-04-11 Jeffrey Stedfast <fejj@ximian.com> + * camel-sasl-digest-md5.c (digest_response): Use + camel_charset_locale_name() to get the locale charset rather than + checking the CHARSET environment variable. This is a much less + ugly hack. Also: If we fail to be able to convert to UTF8, then + disavow all knowledge of the charset parameter. + + * camel-charset-map.c (camel_charset_locale_name): New function to + return the locale charset (or NULL if US-ASCII). + +2001-04-11 Jeffrey Stedfast <fejj@ximian.com> + * camel-pgp-context.c (camel_pgp_verify): Use e_utf8_from_locale_string() rather than trying to do it manually since Lauris's version works much better. diff --git a/camel/camel-charset-map.c b/camel/camel-charset-map.c index c8974af936..d5d7665dac 100644 --- a/camel/camel-charset-map.c +++ b/camel/camel-charset-map.c @@ -202,6 +202,7 @@ void main(void) #include "camel-charset-map.h" #include "camel-charset-map-private.h" #include <unicode.h> +#include <locale.h> #include <glib.h> void camel_charset_init(CamelCharset *c) @@ -282,6 +283,40 @@ camel_charset_best(const char *in, int len) return camel_charset_best_name(&charset); } +char * +camel_charset_locale_name (void) +{ + char *locale, *charset; + + locale = setlocale (LC_ALL, NULL); + + if (!locale || !strcmp (locale, "C") || !strcmp (locale, "POSIX")) { + /* The locale "C" or "POSIX" is a portable locale; its + * LC_CTYPE part corresponds to the 7-bit ASCII character + * set. + */ + + return NULL; + } else { + /* A locale name is typically of the form language[_terri- + * tory][.codeset][@modifier], where language is an ISO 639 + * language code, territory is an ISO 3166 country code, and + * codeset is a character set or encoding identifier like + * ISO-8859-1 or UTF-8. + */ + char *p; + int len; + + p = strchr (locale, '@'); + len = p ? (p - locale) : strlen (locale); + if ((p = strchr (locale, '.'))) { + charset = g_strndup (p + 1, len - (p - locale) + 1); + g_strdown (charset); + } + } + + return charset; +} #endif /* !BUILD_MAP */ diff --git a/camel/camel-charset-map.h b/camel/camel-charset-map.h index 53ba4af9d9..db76281c6f 100644 --- a/camel/camel-charset-map.h +++ b/camel/camel-charset-map.h @@ -35,4 +35,6 @@ const char *camel_charset_best_name(CamelCharset *); /* helper function */ const char *camel_charset_best(const char *in, int len); +char *camel_charset_locale_name (void); + #endif /* ! _CAMEL_CHARSET_MAP_H */ diff --git a/camel/camel-sasl-digest-md5.c b/camel/camel-sasl-digest-md5.c index fa0d9a8175..0ef881ee41 100644 --- a/camel/camel-sasl-digest-md5.c +++ b/camel/camel-sasl-digest-md5.c @@ -286,7 +286,7 @@ decode_quoted_string (const char **in) } *outptr++ = c; } - *outptr = 0; + *outptr = '\0'; } *in = inptr; @@ -696,11 +696,12 @@ digest_response (struct _DigestResponse *resp) const char *buf; iconv_t cd; - charset = getenv ("CHARSET"); + charset = camel_charset_locale_name (); if (!charset) - charset = "ISO-8859-1"; + charset = g_strdup ("iso-8859-1"); cd = iconv_open (resp->charset, charset); + g_free (charset); len = strlen (resp->username); outlen = 2 * len; /* plenty of space */ @@ -708,6 +709,11 @@ digest_response (struct _DigestResponse *resp) outbuf = username = g_malloc0 (outlen + 1); buf = resp->username; if (cd == (iconv_t) -1 || iconv (cd, &buf, &len, &outbuf, &outlen) == -1) { + /* We can't convert to UTF-8 - pretend we never got a charset param? */ + g_free (resp->charset); + resp->charset = NULL; + + /* Set the username to the non-UTF-8 version */ g_free (username); username = g_strdup (resp->username); } @@ -716,6 +722,7 @@ digest_response (struct _DigestResponse *resp) iconv_close (cd); g_byte_array_append (buffer, username, strlen (username)); + g_free (username); } else { g_byte_array_append (buffer, resp->username, strlen (resp->username)); } |