When quoting a message in a reply, make sure that the language for the
day of the week matches the language of the quoting text generated by
evolution.

A bug is triggered, for example, when LC_MESSAGE is set to "C" (not
infrequent at all) and the other locale variables are set to the user
first language.
 
Signed-off-by: Guido Trentalancia <guido@trentalancia.net>
---
 libedataserver/e-data-server-util.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

--- evolution-data-server-3.20.1-orig/libedataserver/e-data-server-util.c	2016-04-15 16:46:52.220964656 +0200
+++ evolution-data-server-3.20.1/libedataserver/e-data-server-util.c	2016-04-15 16:45:50.933169226 +0200
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <time.h>
 #include <unistd.h>
+#include <locale.h>
 
 #ifdef G_OS_WIN32
 #include <mbstring.h>
@@ -753,16 +754,38 @@ e_utf8_strftime (gchar *string,
 {
 	gsize sz, ret;
 	gchar *locale_fmt, *buf;
+	char *ctime, *cmessages, *saved_locale;
 
 	g_return_val_if_fail (string != NULL, 0);
 	g_return_val_if_fail (fmt != NULL, 0);
 	g_return_val_if_fail (tm != NULL, 0);
 
+	/* Use LC_MESSAGES instead of LC_TIME for the day
+	 * of the week (%a and %A) in quoted messages, so
+	 * that the language matches that of the quoting
+	 * message.
+	 */
+	if (!strcasecmp(fmt, "%a")) {
+		ctime = setlocale(LC_TIME, NULL);
+		saved_locale = strdup(ctime);
+		cmessages = setlocale(LC_MESSAGES, NULL);
+		setlocale (LC_TIME, cmessages);
+	}
+
 	locale_fmt = g_locale_from_utf8 (fmt, -1, NULL, &sz, NULL);
 	if (!locale_fmt)
 		return 0;
 
 	ret = e_strftime (string, max, locale_fmt, tm);
+
+	/* Restore LC_TIME, if it has been changed to match
+	 * LC_MESSAGES.
+	 */
+	if (!strcasecmp(fmt, "%a")) {
+		setlocale (LC_TIME, saved_locale);
+		free(saved_locale);
+	}
+
 	if (!ret) {
 		g_free (locale_fmt);
 		return 0;
