aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-charset-map.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-09-14 02:36:53 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-09-14 02:36:53 +0800
commitc9ee98edc7223d480a1da4f5feddcb70d1a3ac8e (patch)
tree0063b276001f16b1dc5e814633b921c11f85eefb /camel/camel-charset-map.c
parentb59ff6e2f0e09ca24c6f9a08590cc4be9ccb2cef (diff)
downloadgsoc2013-evolution-c9ee98edc7223d480a1da4f5feddcb70d1a3ac8e.tar.gz
gsoc2013-evolution-c9ee98edc7223d480a1da4f5feddcb70d1a3ac8e.tar.zst
gsoc2013-evolution-c9ee98edc7223d480a1da4f5feddcb70d1a3ac8e.zip
Convert the charset to the iconv-friendly name.
2001-09-13 Jeffrey Stedfast <fejj@ximian.com> * camel-mime-part-utils.c (simple_data_wrapper_construct_from_parser): Convert the charset to the iconv-friendly name. * camel-charset-map.c (camel_charset_to_iconv): Add code to convert windows-[cp]#### charsets to their iconv-friendly format of cp####. svn path=/trunk/; revision=12804
Diffstat (limited to 'camel/camel-charset-map.c')
-rw-r--r--camel/camel-charset-map.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/camel/camel-charset-map.c b/camel/camel-charset-map.c
index 777f6278dd..af036fec51 100644
--- a/camel/camel-charset-map.c
+++ b/camel/camel-charset-map.c
@@ -201,6 +201,7 @@ void main(void)
#include <gal/unicode/gunicode.h>
#include <locale.h>
#include <string.h>
+#include <ctype.h>
#include <glib.h>
#ifdef ENABLE_THREADS
#include <pthread.h>
@@ -233,6 +234,11 @@ struct {
{ "windows-cp1251", "cp1251" },
{ "windows-1251", "cp1251" },
{ "cp1251", "cp1251" },
+ /* the above mostly serves as an example for windows-style
+ charsets, but we have code that will parse and convert them
+ to their cp#### equivalents if/when they show up in
+ camel_charset_map_to_iconv() so I'm not going to bother
+ putting them all in here... */
{ NULL, NULL }
};
@@ -394,17 +400,28 @@ camel_charset_to_iconv (const char *name)
charset = g_hash_table_lookup (iconv_charsets, name);
if (!charset) {
/* Attempt to friendlyify the charset */
- char *new_charset;
+ char *new_charset, *p;
int len;
- /* Hack to convert charsets like ISO8859-1 to iconv-friendly ISO-8859-1 */
if (!g_strncasecmp (name, "iso", 3) && name[3] != '-' && name[3] != '_') {
+ /* Hack to convert charsets like ISO8859-1 to iconv-friendly ISO-8859-1 */
len = strlen (name);
new_charset = g_malloc (len + 2);
memcpy (new_charset, name, 3);
new_charset[3] = '-';
memcpy (new_charset + 4, name + 3, len - 3);
new_charset[len + 1] = '\0';
+ } else if (!g_strncasecmp (name, "windows-", 8)) {
+ /* Convert charsets like windows-1251 and windows-cp1251 to iconv-friendly cp1251 */
+ new_charset = (char *) name + 8;
+ if (!g_strncasecmp (new_charset, "cp", 2))
+ new_charset += 2;
+
+ for (p = new_charset; *p && isdigit ((unsigned) *p); p++);
+ if (*p == '\0')
+ new_charset = g_strdup_printf ("cp%s", new_charset);
+ else
+ new_charset = g_strdup (name);
} else {
/* *shrug* - add it to the hash table just the way it is? */
new_charset = g_strdup (name);
@@ -415,7 +432,7 @@ camel_charset_to_iconv (const char *name)
}
ICONV_CHARSETS_UNLOCK ();
- /*g_warning ("camel_charset_to_iconv (\"%s\") => \"%s\"", name, charset);*/
+ g_warning ("camel_charset_to_iconv (\"%s\") => \"%s\"", name, charset);
return charset;
}