commit 3c8ca0db96f18600d5a95a3963a8f902f81bbe55
Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Date:   Fri Jun 3 20:19:40 2011 -0400

    Added g_mime_gpg_context_{set,get}_use_agent
    
    This allows the invoker to declare that they expect there to be a
    functioning gpg-agent, and want gpg to talk to it for any needed
    credentials.

diff --git a/gmime/gmime-gpg-context.c b/gmime/gmime-gpg-context.c
index 9f93151..bb9f041 100644
--- a/gmime/gmime-gpg-context.c
+++ b/gmime/gmime-gpg-context.c
@@ -164,6 +164,7 @@ g_mime_gpg_context_init (GMimeGpgContext *ctx, GMimeGpgContextClass *klass)
 	
 	ctx->path = NULL;
 	ctx->always_trust = FALSE;
+	ctx->use_agent = FALSE;
 	
 	cipher->sign_protocol = "application/pgp-signature";
 	cipher->encrypt_protocol = "application/pgp-encrypted";
@@ -310,7 +311,8 @@ struct _GpgCtx {
 	unsigned int nopubkey:1;
 	unsigned int nodata:1;
 	
-	unsigned int padding:14;
+	unsigned int use_agent:1;
+	unsigned int padding:13;
 };
 
 static struct _GpgCtx *
@@ -339,6 +341,7 @@ gpg_ctx_new (GMimeSession *session, const char *path)
 	gpg->hash = GMIME_CIPHER_HASH_DEFAULT;
 	gpg->always_trust = FALSE;
 	gpg->armor = FALSE;
+	gpg->use_agent = FALSE;
 	
 	gpg->stdin_fd = -1;
 	gpg->stdout_fd = -1;
@@ -416,6 +419,12 @@ gpg_ctx_set_always_trust (struct _GpgCtx *gpg, gboolean trust)
 }
 
 static void
+gpg_ctx_set_use_agent (struct _GpgCtx *gpg, gboolean trust)
+{
+	gpg->use_agent = trust;
+}
+
+static void
 gpg_ctx_set_userid (struct _GpgCtx *gpg, const char *userid)
 {
 	g_free (gpg->userid);
@@ -608,6 +617,8 @@ gpg_ctx_get_argv (struct _GpgCtx *gpg, int status_fd, int secret_fd, char ***str
 		(*strv)[v++] = buf = g_strdup_printf ("--command-fd=%d", secret_fd);
 		g_ptr_array_add (args, buf);
 	}
+	if (gpg->use_agent)
+		g_ptr_array_add (args, "--use-agent");
 	
 	switch (gpg->mode) {
 	case GPG_CTX_MODE_SIGN:
@@ -1833,6 +1844,7 @@ gpg_encrypt (GMimeCipherContext *context, gboolean sign, const char *userid,
 	gpg_ctx_set_istream (gpg, istream);
 	gpg_ctx_set_ostream (gpg, ostream);
 	gpg_ctx_set_always_trust (gpg, ctx->always_trust);
+	gpg_ctx_set_use_agent (gpg, ctx->use_agent);
 	
 	for (i = 0; i < recipients->len; i++)
 		gpg_ctx_add_recipient (gpg, recipients->pdata[i]);
@@ -2108,3 +2120,38 @@ g_mime_gpg_context_set_always_trust (GMimeGpgContext *ctx, gboolean always_trust
 	
 	ctx->always_trust = always_trust;
 }
+
+
+/**
+ * g_mime_gpg_context_get_use_agent:
+ * @ctx: a #GMimeGpgContext
+ *
+ * Gets the @use_agent flag on the gpg context.
+ *
+ * Returns: the @use_agent flag on the gpg context, which indicates
+ * that GnuPG should attempt to use gpg-agent for credentials.
+ **/
+gboolean
+g_mime_gpg_context_get_use_agent (GMimeGpgContext *ctx)
+{
+	g_return_val_if_fail (GMIME_IS_GPG_CONTEXT (ctx), FALSE);
+	
+	return ctx->use_agent;
+}
+
+
+/**
+ * g_mime_gpg_context_set_use_agent:
+ * @ctx: a #GMimeGpgContext
+ * @use_agent: always trust flag
+ *
+ * Sets the @use_agent flag on the gpg context, which indicates that
+ * GnuPG should attempt to use gpg-agent for credentials.
+ **/
+void
+g_mime_gpg_context_set_use_agent (GMimeGpgContext *ctx, gboolean use_agent)
+{
+	g_return_if_fail (GMIME_IS_GPG_CONTEXT (ctx));
+	
+	ctx->use_agent = use_agent;
+}
diff --git a/gmime/gmime-gpg-context.h b/gmime/gmime-gpg-context.h
index 4b60f35..84e1fdb 100644
--- a/gmime/gmime-gpg-context.h
+++ b/gmime/gmime-gpg-context.h
@@ -49,6 +49,7 @@ struct _GMimeGpgContext {
 	GMimeCipherContext parent_object;
 	gboolean always_trust;
 	char *path;
+	gboolean use_agent;
 };
 
 struct _GMimeGpgContextClass {
@@ -65,6 +66,9 @@ GMimeCipherContext *g_mime_gpg_context_new (GMimeSession *session, const char *p
 gboolean g_mime_gpg_context_get_always_trust (GMimeGpgContext *ctx);
 void g_mime_gpg_context_set_always_trust (GMimeGpgContext *ctx, gboolean always_trust);
 
+gboolean g_mime_gpg_context_get_use_agent (GMimeGpgContext *ctx);
+void g_mime_gpg_context_set_use_agent (GMimeGpgContext *ctx, gboolean use_agent);
+
 G_END_DECLS
 
 #endif /* __GMIME_GPG_CONTEXT_H__ */
