diff --git a/src/mu-str.c b/src/mu-str.c index 555ef56b..58f77ac8 100644 --- a/src/mu-str.c +++ b/src/mu-str.c @@ -50,13 +50,34 @@ mu_str_date_s (const char* frm, time_t t) { struct tm *tmbuf; static char buf[128]; - + static int is_utf8 = -1; + + if (G_UNLIKELY(is_utf8 == -1)) + is_utf8 = mu_util_locale_is_utf8 () ? 1 : 0; + g_return_val_if_fail (frm, NULL); tmbuf = localtime(&t); strftime (buf, sizeof(buf), frm, tmbuf); + if (!is_utf8) { + /* charset is _not_ utf8, so we need to convert it, so + * the date could contain locale-specific characters*/ + gchar *conv; + GError *err; + err = NULL; + conv = g_locale_to_utf8 (buf, -1, NULL, NULL, &err); + if (err) { + g_warning ("conversion failed: %s", err->message); + g_error_free (err); + strcpy (buf, ""); + } else + strncpy (buf, conv, sizeof(buf)); + + g_free (conv); + } + return buf; } diff --git a/src/mu-str.h b/src/mu-str.h index f00e69ca..545fa1b3 100644 --- a/src/mu-str.h +++ b/src/mu-str.h @@ -161,6 +161,7 @@ char* mu_str_normalize (const char *str, gboolean downcase) */ char* mu_str_normalize_in_place (char *str, gboolean downcase); + /** * escape the string for use with xapian matching. in practice, if the * string contains an '@', replace '@', single-'.' with '_'. Also,