/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
# include <locale.h>
#endif
-#include <iconv.h>
-
#include "codeconv.h"
#include "unmime.h"
#include "base64.h"
#include "utils.h"
#include "prefs_common.h"
+/* For unknown reasons the inconv.m4 macro undefs that macro if no
+ const is needed. This would break the code below so we define it. */
+#ifndef ICONV_CONST
+#define ICONV_CONST
+#endif
+
typedef enum
{
JIS_ASCII,
state = JIS_AUXKANJI; \
}
+static CodeConvFunc conv_get_code_conv_func (const gchar *src_charset_str,
+ const gchar *dest_charset_str);
+
+static gchar *conv_iconv_strdup_with_cd (const gchar *inbuf,
+ iconv_t cd);
+
+static CharSet conv_get_locale_charset (void);
+static CharSet conv_get_outgoing_charset (void);
+static CharSet conv_guess_ja_encoding(const gchar *str);
+static gboolean conv_is_ja_locale (void);
+
static void conv_jistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf);
static void conv_euctojis(gchar *outbuf, gint outlen, const gchar *inbuf);
static void conv_sjistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf);
}
}
-#define NCV '\0'
-
-void conv_mb_alnum(gchar *str)
-{
- static guchar char_tbl[] = {
- /* 0xa0 - 0xaf */
- NCV, ' ', NCV, NCV, ',', '.', NCV, ':',
- ';', '?', '!', NCV, NCV, NCV, NCV, NCV,
- /* 0xb0 - 0xbf */
- NCV, NCV, NCV, NCV, NCV, NCV, NCV, NCV,
- NCV, NCV, NCV, NCV, NCV, NCV, NCV, NCV,
- /* 0xc0 - 0xcf */
- NCV, NCV, NCV, NCV, NCV, NCV, NCV, NCV,
- NCV, NCV, '(', ')', NCV, NCV, '[', ']',
- /* 0xd0 - 0xdf */
- '{', '}', NCV, NCV, NCV, NCV, NCV, NCV,
- NCV, NCV, NCV, NCV, '+', '-', NCV, NCV,
- /* 0xe0 - 0xef */
- NCV, '=', NCV, '<', '>', NCV, NCV, NCV,
- NCV, NCV, NCV, NCV, NCV, NCV, NCV, NCV
- };
-
- register guchar *p = str;
- register gint len;
-
- len = strlen(str);
-
- while (len > 1) {
- if (*p == 0xa3) {
- register guchar ch = *(p + 1);
-
- if (ch >= 0xb0 && ch <= 0xfa) {
- /* [a-zA-Z] */
- *p = ch & 0x7f;
- p++;
- len--;
- memmove(p, p + 1, len);
- len--;
- } else {
- p += 2;
- len -= 2;
- }
- } else if (*p == 0xa1) {
- register guchar ch = *(p + 1);
-
- if (ch >= 0xa0 && ch <= 0xef &&
- NCV != char_tbl[ch - 0xa0]) {
- *p = char_tbl[ch - 0xa0];
- p++;
- len--;
- memmove(p, p + 1, len);
- len--;
- } else {
- p += 2;
- len -= 2;
- }
- } else if (iseuckanji(*p)) {
- p += 2;
- len -= 2;
- } else {
- p++;
- len--;
- }
- }
-}
-
-CharSet conv_guess_ja_encoding(const gchar *str)
+static CharSet conv_guess_ja_encoding(const gchar *str)
{
const guchar *p = str;
CharSet guessed = C_US_ASCII;
g_free(tmpstr);
return;
} else {
- if (tmpstr)
- g_free(tmpstr);
+ g_free(tmpstr);
conv_utf8todisp(outbuf, outlen, inbuf);
}
}
return conv_iconv_strdup(inbuf, src_code, dest_code);
}
-CodeConvFunc conv_get_code_conv_func(const gchar *src_charset_str,
+static CodeConvFunc conv_get_code_conv_func(const gchar *src_charset_str,
const gchar *dest_charset_str)
{
CodeConvFunc code_conv = conv_noconv;
iconv_t cd;
gchar *outbuf;
+ if (!src_code && !dest_code &&
+ g_utf8_validate(inbuf, -1, NULL))
+ return g_strdup(inbuf);
+
if (!src_code)
src_code = conv_get_outgoing_charset_str();
if (!dest_code)
if (!strcasecmp(src_code, dest_code))
return g_strdup(inbuf);
- /* don't convert if current codeset is US-ASCII */
+ /* don't convert if dest codeset is US-ASCII */
+ if (!strcasecmp(src_code, CS_US_ASCII))
+ return g_strdup(inbuf);
+
+ /* don't convert if dest codeset is US-ASCII */
if (!strcasecmp(dest_code, CS_US_ASCII))
return g_strdup(inbuf);
return GPOINTER_TO_UINT(g_hash_table_lookup(table, charset));
}
-CharSet conv_get_locale_charset(void)
+static CharSet conv_get_locale_charset(void)
{
static CharSet cur_charset = -1;
const gchar *cur_locale;
return codeset ? codeset : CS_INTERNAL;
}
-CharSet conv_get_internal_charset(void)
-{
- return C_INTERNAL;
-}
-
-const gchar *conv_get_internal_charset_str(void)
-{
- return CS_INTERNAL;
-}
-
-CharSet conv_get_outgoing_charset(void)
+static CharSet conv_get_outgoing_charset(void)
{
static CharSet out_charset = -1;
const gchar *cur_locale;
return str ? str : CS_UTF_8;
}
-gboolean conv_is_multibyte_encoding(CharSet encoding)
-{
- switch (encoding) {
- case C_EUC_JP:
- case C_EUC_JP_MS:
- case C_EUC_KR:
- case C_EUC_TW:
- case C_EUC_CN:
- case C_ISO_2022_JP:
- case C_ISO_2022_JP_2:
- case C_ISO_2022_JP_3:
- case C_ISO_2022_KR:
- 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 TRUE;
- default:
- return FALSE;
- }
-}
-
const gchar *conv_get_current_locale(void)
{
const gchar *cur_locale;
return cur_locale;
}
-gboolean conv_is_ja_locale(void)
+static gboolean conv_is_ja_locale(void)
{
static gint is_ja_locale = -1;
const gchar *cur_locale;
continue;
}
- /* don't include parentheses in encoded strings */
- if (addr_field && (*srcp == '(' || *srcp == ')')) {
+ /* don't include parentheses and quotes in encoded strings */
+ if (addr_field && (*srcp == '(' || *srcp == ')' || *srcp == '"')) {
LBREAK_IF_REQUIRED(left < 2, FALSE);
*destp++ = *srcp++;
left--;
break;
/* don't include parentheses in encoded
strings */
- if (addr_field && (*p == '(' || *p == ')'))
+ if (addr_field && (*p == '(' || *p == ')' || *p == '"'))
break;
mb_len = g_utf8_skip[*p];