2005-09-18 [colin] 1.9.14cvs42
authorColin Leroy <colin@colino.net>
Sun, 18 Sep 2005 09:14:59 +0000 (09:14 +0000)
committerColin Leroy <colin@colino.net>
Sun, 18 Sep 2005 09:14:59 +0000 (09:14 +0000)
* src/codeconv.c
* src/codeconv.h
* src/procmime.c
Add a way to get locale's charset ignoring utf-8,
and use that as default encoding for broken mails

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/codeconv.c
src/codeconv.h
src/procmime.c

index 4c75f795036d1609178861168d6e4b9264d6687a..d713cfa55fc08c79d158b0f7c5584bc0ce0d3011 100644 (file)
@@ -1,3 +1,11 @@
+2005-09-18 [colin]     1.9.14cvs42
+
+       * src/codeconv.c
+       * src/codeconv.h
+       * src/procmime.c
+               Add a way to get locale's charset ignoring utf-8,
+               and use that as default encoding for broken mails
+
 2005-09-18 [colin]     1.9.14cvs41
 
        * src/gtk/logwindow.c
index 51067d0dea6abc4c26597d844bbf4800e96596df..f45c990b1314edf5644bdf6a3ca98737c2c5ec1e 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.65.2.35 -r 1.65.2.36 src/codeconv.c;  cvs diff -u -r 1.382.2.170 -r 1.382.2.171 src/compose.c;  cvs diff -u -r 1.49.2.60 -r 1.49.2.61 src/procmime.c;  ) > 1.9.14cvs39.patchset
 ( cvs diff -u -r 1.654.2.850 -r 1.654.2.851 configure.ac;  ) > 1.9.14cvs40.patchset
 ( cvs diff -u -r 1.1.4.10 -r 1.1.4.11 src/gtk/logwindow.c;  ) > 1.9.14cvs41.patchset
+( cvs diff -u -r 1.65.2.36 -r 1.65.2.37 src/codeconv.c;  cvs diff -u -r 1.15.2.10 -r 1.15.2.11 src/codeconv.h;  cvs diff -u -r 1.49.2.61 -r 1.49.2.62 src/procmime.c;  ) > 1.9.14cvs42.patchset
index 0fefd7a585944be5a63c3410511830ebdcd5f1cc..b65905886e6bd1d718b8780f83c262ae85b72516 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=14
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=41
+EXTRA_VERSION=42
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 3e7676b11b0f82f822078b61b471729c888348ec..0a7c9a97a64c8fa7c1c61a1f2334a040296a7236 100644 (file)
@@ -1305,6 +1305,57 @@ CharSet conv_get_locale_charset(void)
        return cur_charset;
 }
 
+static CharSet conv_get_locale_charset_no_utf8(void)
+{
+       static CharSet cur_charset = -1;
+       const gchar *cur_locale;
+       const gchar *p;
+       gchar *tmp;
+       gint i;
+
+       if (cur_charset != -1)
+               return cur_charset;
+
+       cur_locale = conv_get_current_locale();
+       if (!cur_locale) {
+               cur_charset = C_US_ASCII;
+               return cur_charset;
+       }
+
+       if (strcasestr(cur_locale, "UTF-8")) {
+               tmp = g_strdup(cur_locale);
+               *(strcasestr(tmp, ".UTF-8")) = '\0';
+               cur_locale = tmp;
+       }
+
+       if ((p = strcasestr(cur_locale, "@euro")) && p[5] == '\0') {
+               cur_charset = C_ISO_8859_15;
+               return cur_charset;
+       }
+
+       for (i = 0; i < sizeof(locale_table) / sizeof(locale_table[0]); i++) {
+               const gchar *p;
+
+               /* "ja_JP.EUC" matches with "ja_JP.eucJP", "ja_JP.EUC" and
+                  "ja_JP". "ja_JP" matches with "ja_JP.xxxx" and "ja" */
+               if (!g_ascii_strncasecmp(cur_locale, locale_table[i].locale,
+                                strlen(locale_table[i].locale))) {
+                       cur_charset = locale_table[i].charset;
+                       return cur_charset;
+               } else if ((p = strchr(locale_table[i].locale, '_')) &&
+                        !strchr(p + 1, '.')) {
+                       if (strlen(cur_locale) == 2 &&
+                           !g_ascii_strncasecmp(cur_locale, locale_table[i].locale, 2)) {
+                               cur_charset = locale_table[i].charset;
+                               return cur_charset;
+                       }
+               }
+       }
+
+       cur_charset = C_AUTO;
+       return cur_charset;
+}
+
 const gchar *conv_get_locale_charset_str(void)
 {
        static const gchar *codeset = NULL;
@@ -1315,6 +1366,16 @@ const gchar *conv_get_locale_charset_str(void)
        return codeset ? codeset : CS_INTERNAL;
 }
 
+const gchar *conv_get_locale_charset_str_no_utf8(void)
+{
+       static const gchar *codeset = NULL;
+
+       if (!codeset)
+               codeset = conv_get_charset_str(conv_get_locale_charset_no_utf8());
+
+       return codeset ? codeset : CS_INTERNAL;
+}
+
 CharSet conv_get_internal_charset(void)
 {
        return C_INTERNAL;
index 0eb547aeb827902f7600db6b45622e1284134a76..9b1306aa2a08d9d6aaeeaa600331231ffc993c89 100644 (file)
@@ -201,6 +201,7 @@ const gchar *conv_get_charset_str           (CharSet         charset);
 CharSet conv_get_charset_from_str              (const gchar    *charset);
 CharSet conv_get_locale_charset                        (void);
 const gchar *conv_get_locale_charset_str       (void);
+const gchar *conv_get_locale_charset_str_no_utf8(void);
 CharSet conv_get_internal_charset              (void);
 const gchar *conv_get_internal_charset_str     (void);
 CharSet conv_get_outgoing_charset              (void);
index a9f1a4d4887f9ec8002c1f06f33fc531b803ea79..eba860e8f3836b22cd06d39ceada3dc72c8bde88 100644 (file)
@@ -1613,14 +1613,10 @@ static void procmime_parse_content_type(const gchar *content_type, MimeInfo *mim
                mimeinfo->subtype = g_strdup("plain");
                if (g_hash_table_lookup(mimeinfo->typeparameters,
                                       "charset") == NULL) {
-                       if (strcmp(conv_get_locale_charset_str(), CS_UTF_8))
-                               g_hash_table_insert(mimeinfo->typeparameters,
-                                           g_strdup("charset"),
-                                           g_strdup(conv_get_locale_charset_str()));
-                       else
-                               g_hash_table_insert(mimeinfo->typeparameters,
-                                           g_strdup("charset"),
-                                           g_strdup(CS_ISO_8859_1));
+                       g_hash_table_insert(mimeinfo->typeparameters,
+                                   g_strdup("charset"),
+                                   g_strdup(
+                                       conv_get_locale_charset_str_no_utf8()));
                }
        } else {
                gchar *type, *subtype, *params;
@@ -1723,14 +1719,10 @@ int procmime_parse_mimepart(MimeInfo *parent,
                mimeinfo->subtype = g_strdup("plain");
                if (g_hash_table_lookup(mimeinfo->typeparameters,
                                       "charset") == NULL) {
-                       if (strcmp(conv_get_locale_charset_str(), CS_UTF_8))
-                               g_hash_table_insert(mimeinfo->typeparameters,
-                                           g_strdup("charset"),
-                                           g_strdup(conv_get_locale_charset_str()));
-                       else
-                               g_hash_table_insert(mimeinfo->typeparameters,
-                                           g_strdup("charset"),
-                                           g_strdup(CS_ISO_8859_1));
+                       g_hash_table_insert(mimeinfo->typeparameters,
+                                   g_strdup("charset"),
+                                   g_strdup(
+                                       conv_get_locale_charset_str_no_utf8()));
                }
        }