/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2009 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2012 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
#ifdef HAVE_CONFIG_H
# include "config.h"
+#include "claws-features.h"
#endif
#include "defs.h"
#include "codeconv.h"
#include "unmime.h"
-#include "base64.h"
#include "quoted-printable.h"
#include "utils.h"
#include "prefs_common.h"
size_t len;
CodeConvFunc conv_func;
- if (!strcmp2(src_code, dest_code))
+ if (!strcmp2(src_code, dest_code)) {
+ CharSet dest_charset = conv_get_charset_from_str(dest_code);
+ if (strict_mode && dest_charset == C_UTF_8) {
+ /* ensure valid UTF-8 if target is UTF-8 */
+ if (!g_utf8_validate(inbuf, -1, NULL)) {
+ return NULL;
+ }
+ }
+ /* otherwise, try for a lucky day */
return g_strdup(inbuf);
+ }
src_code = conv_get_fallback_for_private_encoding(src_code);
conv_func = conv_get_code_conv_func(src_code, dest_code);
{"ru_RU.KOI8-R" , C_KOI8_R , C_KOI8_R},
{"ru_RU.KOI8R" , C_KOI8_R , C_KOI8_R},
{"ru_RU.CP1251" , C_WINDOWS_1251, C_KOI8_R},
+#ifdef G_OS_WIN32
+ {"ru_RU" , C_WINDOWS_1251, C_KOI8_R},
+#else
{"ru_RU" , C_ISO_8859_5 , C_KOI8_R},
+#endif
{"tg_TJ" , C_KOI8_T , C_KOI8_T},
{"ru_UA" , C_KOI8_U , C_KOI8_U},
{"uk_UA.CP1251" , C_WINDOWS_1251, C_KOI8_U},
return cur_charset;
}
- if (strcasestr(cur_locale, ".UTF-8") ||
- strcasestr(cur_locale, ".utf8")) {
+ if (strcasestr(cur_locale, "UTF-8") ||
+ strcasestr(cur_locale, "utf8")) {
cur_charset = C_UTF_8;
return cur_charset;
}
static CharSet cur_charset = -1;
const gchar *cur_locale;
const gchar *p;
- gchar *tmp;
gint i;
- if (prefs_common.broken_are_utf8)
- return conv_get_locale_charset();
-
- if (cur_charset != -1)
+ if (prefs_common.broken_are_utf8) {
+ cur_charset = C_UTF_8;
return cur_charset;
+ }
cur_locale = conv_get_current_locale();
if (!cur_locale) {
return cur_charset;
}
- if (strcasestr(cur_locale, "UTF-8")) {
- tmp = g_strdup(cur_locale);
- *(strcasestr(tmp, ".UTF-8")) = '\0';
- cur_locale = tmp;
+ if (strcasestr(cur_locale, "UTF-8") ||
+ strcasestr(cur_locale, "utf8")) {
+ cur_charset = C_UTF_8;
+ return cur_charset;
}
if ((p = strcasestr(cur_locale, "@euro")) && p[5] == '\0') {
return out_charset;
}
- if (strcasestr(cur_locale, "UTF-8")) {
+ if (strcasestr(cur_locale, "UTF-8") ||
+ strcasestr(cur_locale, "utf8")) {
out_charset = C_UTF_8;
return out_charset;
}
return is_ja_locale != 0;
}
-gchar *conv_unmime_header(const gchar *str, const gchar *default_encoding)
+gchar *conv_unmime_header(const gchar *str, const gchar *default_encoding,
+ gboolean addr_field)
{
gchar buf[BUFFSIZE];
if (is_ascii_str(str))
- return unmime_header(str);
+ return unmime_header(str, addr_field);
if (default_encoding) {
gchar *utf8_buf;
if (utf8_buf) {
gchar *decoded_str;
- decoded_str = unmime_header(utf8_buf);
+ decoded_str = unmime_header(utf8_buf, addr_field);
g_free(utf8_buf);
return decoded_str;
}
else
conv_localetodisp(buf, sizeof(buf), str);
- return unmime_header(buf);
+ return unmime_header(buf, addr_field);
}
#define MAX_LINELEN 76
} \
}
+#define B64LEN(len) ((len) / 3 * 4 + ((len) % 3 ? 4 : 0))
+
void conv_encode_header_full(gchar *dest, gint len, const gchar *src,
gint header_len, gboolean addr_field,
const gchar *out_encoding_)
cur_len += mb_len;
p += mb_len;
} else if (cur_len == 0) {
+ left = 0;
LBREAK_IF_REQUIRED(1, FALSE);
continue;
} else {
out_enc_str_len =
qp_get_q_encoding_len(out_str);
- Xalloca(enc_str, out_enc_str_len + 1, );
if (use_base64)
- base64_encode(enc_str, out_str, out_str_len);
- else
+ enc_str = g_base64_encode(out_str, out_str_len);
+ else {
+ Xalloca(enc_str, out_enc_str_len + 1, );
qp_q_encode(enc_str, out_str);
+ }
g_free(out_str);
g_snprintf(destp, mime_block_len + 1,
MIMESEP_BEGIN "%s%s%s" MIMESEP_END,
out_encoding, mimesep_enc, enc_str);
+
+ if (use_base64)
+ g_free(enc_str);
+
destp += mime_block_len;
srcp += cur_len;
}
#undef LBREAK_IF_REQUIRED
+#undef B64LEN
+
gchar *conv_filename_from_utf8(const gchar *utf8_file)
{
gchar *fs_file;