From 0c29bfd43c82a09225733235db2d9cd9a79b07ae Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Tue, 4 Nov 2003 21:52:59 +0000 Subject: We might need to convert the passwd from UTF-8 into the locale charset. 2003-11-04 Jeffrey Stedfast * camel-gpg-context.c (gpg_ctx_parse_status): We might need to convert the passwd from UTF-8 into the locale charset. Fixes bug #50485. svn path=/trunk/; revision=23186 --- camel/camel-gpg-context.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'camel/camel-gpg-context.c') diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c index 6f79cdb4ff..ea27ac2926 100644 --- a/camel/camel-gpg-context.c +++ b/camel/camel-gpg-context.c @@ -208,7 +208,9 @@ struct _GpgCtx { unsigned int diagflushed:1; - unsigned int padding:17; + unsigned int utf8:1; + + unsigned int padding:16; }; static struct _GpgCtx * @@ -266,6 +268,8 @@ gpg_ctx_new (CamelSession *session) CamelMimeFilterCharset *filter; CamelStreamFilter *fstream; + gpg->utf8 = FALSE; + if ((filter = camel_mime_filter_charset_new_convert (charset, "UTF-8"))) { fstream = camel_stream_filter_new_with_stream (stream); camel_stream_filter_add (fstream, (CamelMimeFilter *) filter); @@ -274,6 +278,8 @@ gpg_ctx_new (CamelSession *session) stream = (CamelStream *) fstream; } + } else { + gpg->utf8 = TRUE; } gpg->diagnostics = stream; @@ -663,6 +669,7 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex) { register unsigned char *inptr; const unsigned char *status; + size_t nread, nwritten; int len; parse: @@ -691,7 +698,6 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex) status += 9; if (!strncmp (status, "USERID_HINT ", 12)) { - size_t nread, nwritten; char *hint, *user; status += 12; @@ -708,7 +714,7 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex) goto recycle; } - if (!(user = g_locale_to_utf8 (status, -1, &nread, &nwritten, NULL))) + if (gpg->utf8 || !(user = g_locale_to_utf8 (status, -1, &nread, &nwritten, NULL))) user = g_strdup (status); g_strstrip (user); @@ -734,7 +740,16 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex) prompt = g_strdup_printf (_("You need a passphrase to unlock the key for\n" "user: \"%s\""), name); - passwd = camel_session_get_password (gpg->session, prompt, FALSE, TRUE, NULL, userid, ex); + if ((passwd = camel_session_get_password (gpg->session, prompt, FALSE, TRUE, NULL, userid, ex)) && !gpg->utf8) { + char *opasswd = passwd; + + if ((passwd = g_locale_to_utf8 (passwd, -1, &nread, &nwritten, NULL))) { + memset (opasswd, 0, strlen (opasswd)); + g_free (opasswd); + } else { + passwd = opasswd; + } + } g_free (prompt); g_free (gpg->userid); -- cgit v1.2.3