# include "config.h"
#endif
+#include "defs.h"
+
#include <glib.h>
#include <glib/gi18n.h>
#include <string.h>
strncpy2(outbuf, inbuf, outlen);
}
+static const gchar *
+conv_get_fallback_for_private_encoding(const gchar *encoding)
+{
+ if (encoding && (encoding[0] == 'X' || encoding[0] == 'x') &&
+ encoding[1] == '-') {
+ if (!g_ascii_strcasecmp(encoding, CS_X_GBK))
+ return CS_GBK;
+ }
+
+ return encoding;
+}
+
CodeConverter *conv_code_converter_new(const gchar *src_charset)
{
CodeConverter *conv;
+ src_charset = conv_get_fallback_for_private_encoding(src_charset);
+
conv = g_new0(CodeConverter, 1);
conv->code_conv_func = conv_get_code_conv_func(src_charset, NULL);
conv->charset_str = g_strdup(src_charset);
size_t len;
CodeConvFunc conv_func;
+ src_code = conv_get_fallback_for_private_encoding(src_code);
conv_func = conv_get_code_conv_func(src_code, dest_code);
if (conv_func != conv_noconv) {
len = (strlen(inbuf) + 1) * 3;
{"ko_KR.EUC-KR" , C_EUC_KR , C_EUC_KR},
{"ko_KR" , C_EUC_KR , C_EUC_KR},
{"zh_CN.GB2312" , C_GB2312 , C_GB2312},
- {"zh_CN.GBK" , C_GBK , C_GB2312},
+ {"zh_CN.GBK" , C_GBK , C_GBK},
{"zh_CN" , C_GB2312 , C_GB2312},
{"zh_HK" , C_BIG5_HKSCS , C_BIG5_HKSCS},
{"zh_TW.eucTW" , C_EUC_TW , C_BIG5},
case C_ISO_2022_CN:
case C_SHIFT_JIS:
case C_GB2312:
+ case C_GBK:
case C_BIG5:
case C_UTF_8:
case C_UTF_7:
return cur_locale;
}
-void conv_unmime_header_overwrite(gchar *str)
+gchar *conv_unmime_header(const gchar *str, const gchar *default_encoding)
{
- gchar *buf;
- gint buflen;
+ gchar buf[BUFFSIZE];
- buflen = strlen(str) * 2 + 1;
- Xalloca(buf, buflen, return);
+ if (is_ascii_str(str))
+ return unmime_header(str);
- if (conv_get_locale_charset() == C_EUC_JP)
- conv_anytodisp(buf, buflen, str);
- else
- conv_localetodisp(buf, buflen, str);
-
- unmime_header(str, buf);
-}
+ if (default_encoding) {
+ gchar *utf8_buf;
-void conv_unmime_header(gchar *outbuf, gint outlen, const gchar *str,
- const gchar *charset)
-{
- gchar *buf;
- gint buflen;
+ utf8_buf = conv_codeset_strdup
+ (str, default_encoding, CS_INTERNAL);
+ if (utf8_buf) {
+ gchar *decoded_str;
- buflen = strlen(str) * 2 + 1;
- Xalloca(buf, buflen, return);
+ decoded_str = unmime_header(utf8_buf);
+ g_free(utf8_buf);
+ return decoded_str;
+ }
+ }
if (conv_get_locale_charset() == C_EUC_JP)
- conv_anytodisp(buf, buflen, str);
+ conv_anytodisp(buf, sizeof(buf), str);
else
- conv_localetodisp(buf, buflen, str);
+ conv_localetodisp(buf, sizeof(buf), str);
- unmime_header(outbuf, buf);
+ return unmime_header(buf);
}
#define MAX_LINELEN 76