Subject: fix segfault when gpgme_strerror() returns a non UTF-8 string
From: Colin Leroy <colin@colino.net>
Bug: http://www.thewildbeast.co.uk/claws-mail/bugzilla/show_bug.cgi?id=2650
Applied-Upstream: 3.8.1cvs41
 
diff -purN claws-mail-3.8.1.orig/src/plugins/pgpcore/sgpgme.c claws-mail-3.8.1/src/plugins/pgpcore/sgpgme.c
--- claws-mail-3.8.1.orig/src/plugins/pgpcore/sgpgme.c	2012-06-27 11:05:23.000000000 +0200
+++ claws-mail-3.8.1/src/plugins/pgpcore/sgpgme.c	2012-10-11 23:04:52.000000000 +0200
@@ -610,13 +610,36 @@ bail:
 
 void sgpgme_init()
 {
+	gchar *ctype_locale = NULL, *messages_locale = NULL;
+	gchar *ctype_utf8_locale = NULL, *messages_utf8_locale = NULL;
+
 	gpgme_engine_info_t engineInfo;
 	if (gpgme_check_version("1.0.0")) {
 #ifdef LC_CTYPE
-		gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
+		ctype_locale = g_strdup(setlocale(LC_CTYPE, NULL));
+		if (strchr(ctype_locale, '.'))
+			*(strchr(ctype_locale, '.')) = '\0';
+		else if (strchr(ctype_locale, '@'))
+			*(strchr(ctype_locale, '@')) = '\0';
+		ctype_utf8_locale = g_strconcat(ctype_locale, ".UTF-8", NULL);
+
+		gpgme_set_locale(NULL, LC_CTYPE, ctype_utf8_locale);
+
+		g_free(ctype_utf8_locale);
+		g_free(ctype_locale);
 #endif
 #ifdef LC_MESSAGES
-		gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
+		messages_locale = g_strdup(setlocale(LC_MESSAGES, NULL));
+		if (strchr(messages_locale, '.'))
+			*(strchr(messages_locale, '.')) = '\0';
+		else if (strchr(messages_locale, '@'))
+			*(strchr(messages_locale, '@')) = '\0';
+		messages_utf8_locale = g_strconcat(messages_locale, ".UTF-8", NULL);
+
+		gpgme_set_locale(NULL, LC_MESSAGES, messages_utf8_locale);
+
+		g_free(messages_utf8_locale);
+		g_free(messages_locale);
 #endif
 		if (!gpgme_get_engine_info(&engineInfo)) {
 			while (engineInfo) {
