#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);
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;
}
} \
}
+#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_)
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;