* [PATCH] Update notmuch to use the GMime 2.6 API
2012-01-17 2:26 [PATCH] Make notmuch build and work with GMime 2.6 Adrian Perez
@ 2012-01-17 2:26 ` Adrian Perez
0 siblings, 0 replies; 2+ messages in thread
From: Adrian Perez @ 2012-01-17 2:26 UTC (permalink / raw)
To: notmuch
GMime version 2.6 introduces a number of API changes which affect mostly
the signing/encryption support. This patch makes the hanges needed to build
and link with version 2.6 of it.
---
mime-node.c | 20 ++++++++------
notmuch-client.h | 8 +++---
notmuch-reply.c | 4 +--
notmuch-show.c | 75 +++++++++++++++++++++++++----------------------------
4 files changed, 51 insertions(+), 56 deletions(-)
diff --git a/mime-node.c b/mime-node.c
index d26bb44..7e97d54 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -33,7 +33,7 @@ typedef struct mime_node_context {
GMimeMessage *mime_message;
/* Context provided by the caller. */
- GMimeCipherContext *cryptoctx;
+ GMimeCryptoContext *cryptoctx;
notmuch_bool_t decrypt;
} mime_node_context_t;
@@ -57,7 +57,7 @@ _mime_node_context_free (mime_node_context_t *res)
notmuch_status_t
mime_node_open (const void *ctx, notmuch_message_t *message,
- GMimeCipherContext *cryptoctx, notmuch_bool_t decrypt,
+ GMimeCryptoContext *cryptoctx, notmuch_bool_t decrypt,
mime_node_t **root_out)
{
const char *filename = notmuch_message_get_filename (message);
@@ -113,9 +113,9 @@ DONE:
}
static int
-_signature_validity_free (GMimeSignatureValidity **proxy)
+_signature_validity_free (GMimeSignatureList **proxy)
{
- g_mime_signature_validity_free (*proxy);
+ g_object_unref (*proxy);
return 0;
}
@@ -165,11 +165,13 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
GMimeMultipartEncrypted *encrypteddata =
GMIME_MULTIPART_ENCRYPTED (part);
node->decrypt_attempted = TRUE;
+ GMimeDecryptResult *decryptresult = NULL;
node->decrypted_child = g_mime_multipart_encrypted_decrypt
- (encrypteddata, node->ctx->cryptoctx, &err);
+ (encrypteddata, node->ctx->cryptoctx, &decryptresult, &err);
if (node->decrypted_child) {
node->decrypt_success = node->verify_attempted = TRUE;
- node->sig_validity = g_mime_multipart_encrypted_get_signature_validity (encrypteddata);
+ node->sig_validity = g_object_ref (decryptresult->signatures);
+ g_object_unref (decryptresult);
} else {
fprintf (stderr, "Failed to decrypt part: %s\n",
(err ? err->message : "no error explanation given"));
@@ -190,13 +192,13 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
*
* In GMime 2.6, they're both non-const, so we'll be able
* to clean up this asymmetry. */
- GMimeSignatureValidity *sig_validity = g_mime_multipart_signed_verify
+ GMimeSignatureList *sig_validity = g_mime_multipart_signed_verify
(GMIME_MULTIPART_SIGNED (part), node->ctx->cryptoctx, &err);
node->verify_attempted = TRUE;
node->sig_validity = sig_validity;
if (sig_validity) {
- GMimeSignatureValidity **proxy =
- talloc (node, GMimeSignatureValidity *);
+ GMimeSignatureList **proxy =
+ talloc (node, GMimeSignatureList *);
*proxy = sig_validity;
talloc_set_destructor (proxy, _signature_validity_free);
}
diff --git a/notmuch-client.h b/notmuch-client.h
index 517c010..49db697 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -69,7 +69,7 @@ typedef struct notmuch_show_format {
void (*part_start) (GMimeObject *part,
int *part_count);
void (*part_encstatus) (int status);
- void (*part_sigstatus) (const GMimeSignatureValidity* validity);
+ void (*part_sigstatus) (GMimeSignatureList* validity);
void (*part_content) (GMimeObject *part);
void (*part_end) (GMimeObject *part);
const char *part_sep;
@@ -83,7 +83,7 @@ typedef struct notmuch_show_params {
int entire_thread;
int raw;
int part;
- GMimeCipherContext* cryptoctx;
+ GMimeCryptoContext* cryptoctx;
int decrypt;
} notmuch_show_params_t;
@@ -286,7 +286,7 @@ typedef struct mime_node {
* signature. May be NULL if signature verification failed. If
* there are simply no signatures, this will be non-NULL with an
* empty signers list. */
- const GMimeSignatureValidity *sig_validity;
+ GMimeSignatureList *sig_validity;
/* Internal: Context inherited from the root iterator. */
struct mime_node_context *ctx;
@@ -311,7 +311,7 @@ typedef struct mime_node {
*/
notmuch_status_t
mime_node_open (const void *ctx, notmuch_message_t *message,
- GMimeCipherContext *cryptoctx, notmuch_bool_t decrypt,
+ GMimeCryptoContext *cryptoctx, notmuch_bool_t decrypt,
mime_node_t **node_out);
/* Return a new MIME node for the requested child part of parent.
diff --git a/notmuch-reply.c b/notmuch-reply.c
index da3acce..045a4cc 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -688,15 +688,13 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
reply_format_func = notmuch_reply_format_default;
if (decrypt) {
- GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
- params.cryptoctx = g_mime_gpg_context_new (session, "gpg");
+ params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");
if (params.cryptoctx) {
g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);
params.decrypt = TRUE;
} else {
fprintf (stderr, "Failed to construct gpg context.\n");
}
- g_object_unref (session);
}
config = notmuch_config_open (ctx, NULL, NULL);
diff --git a/notmuch-show.c b/notmuch-show.c
index d14dac9..2277875 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -76,7 +76,7 @@ static void
format_part_encstatus_json (int status);
static void
-format_part_sigstatus_json (const GMimeSignatureValidity* validity);
+format_part_sigstatus_json (GMimeSignatureList* validity);
static void
format_part_content_json (GMimeObject *part);
@@ -487,16 +487,14 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
}
static const char*
-signer_status_to_string (GMimeSignerStatus x)
+signer_status_to_string (GMimeSignatureStatus x)
{
switch (x) {
- case GMIME_SIGNER_STATUS_NONE:
- return "none";
- case GMIME_SIGNER_STATUS_GOOD:
+ case GMIME_SIGNATURE_STATUS_GOOD:
return "good";
- case GMIME_SIGNER_STATUS_BAD:
+ case GMIME_SIGNATURE_STATUS_BAD:
return "bad";
- case GMIME_SIGNER_STATUS_ERROR:
+ case GMIME_SIGNATURE_STATUS_ERROR:
return "error";
}
return "unknown";
@@ -593,7 +591,7 @@ format_part_encstatus_json (int status)
}
static void
-format_part_sigstatus_json (const GMimeSignatureValidity* validity)
+format_part_sigstatus_json (GMimeSignatureList* validity)
{
printf (", \"sigstatus\": [");
@@ -602,50 +600,50 @@ format_part_sigstatus_json (const GMimeSignatureValidity* validity)
return;
}
- const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity);
- int first = 1;
+ int i;
void *ctx_quote = talloc_new (NULL);
- while (signer) {
- if (first)
- first = 0;
- else
+ for (i = 0; i < g_mime_signature_list_length (validity); i++) {
+ GMimeSignature *signature = g_mime_signature_list_get_signature (validity, i);
+ if (i > 0)
printf (", ");
printf ("{");
/* status */
+ const GMimeSignatureStatus status = g_mime_signature_get_status (signature);
printf ("\"status\": %s",
json_quote_str (ctx_quote,
- signer_status_to_string (signer->status)));
+ signer_status_to_string (status)));
+
+ GMimeCertificate *cert = g_mime_signature_get_certificate (signature);
- if (signer->status == GMIME_SIGNER_STATUS_GOOD)
+ if (status == GMIME_SIGNATURE_STATUS_GOOD)
{
- if (signer->fingerprint)
- printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, signer->fingerprint));
+ if (g_mime_certificate_get_fingerprint (cert))
+ printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, g_mime_certificate_get_fingerprint (cert)));
/* these dates are seconds since the epoch; should we
* provide a more human-readable format string? */
- if (signer->created)
- printf (", \"created\": %d", (int) signer->created);
- if (signer->expires)
- printf (", \"expires\": %d", (int) signer->expires);
+ if (g_mime_certificate_get_created (cert) != (time_t) -1)
+ printf (", \"created\": %d", (int) g_mime_certificate_get_created (cert));
+ if (g_mime_certificate_get_expires (cert) != (time_t) -1)
+ printf (", \"expires\": %d", (int) g_mime_certificate_get_expires (cert));
/* output user id only if validity is FULL or ULTIMATE. */
/* note that gmime is using the term "trust" here, which
* is WRONG. It's actually user id "validity". */
- if ((signer->name) && (signer->trust)) {
- if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE))
- printf (", \"userid\": %s", json_quote_str (ctx_quote, signer->name));
- }
- } else {
- if (signer->keyid)
- printf (", \"keyid\": %s", json_quote_str (ctx_quote, signer->keyid));
- }
- if (signer->errors != GMIME_SIGNER_ERROR_NONE) {
- printf (", \"errors\": %x", signer->errors);
- }
-
- printf ("}");
- signer = signer->next;
+ if ((g_mime_certificate_get_name (cert)) &&
+ ((g_mime_certificate_get_trust (cert) == GMIME_CERTIFICATE_TRUST_FULLY) ||
+ (g_mime_certificate_get_trust (cert) == GMIME_CERTIFICATE_TRUST_ULTIMATE)))
+ printf (", \"userid\": %s", json_quote_str (ctx_quote, g_mime_certificate_get_name (cert)));
+ } else {
+ if (g_mime_certificate_get_key_id (cert))
+ printf (", \"keyid\": %s", json_quote_str (ctx_quote, g_mime_certificate_get_key_id (cert)));
+ }
+ if (g_mime_signature_get_errors (signature) != GMIME_SIGNATURE_ERROR_NONE) {
+ printf (", \"errors\": %x", g_mime_signature_get_errors (signature));
+ }
+
+ printf ("}");
}
printf ("]");
@@ -990,13 +988,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
} else if ((STRNCMP_LITERAL (argv[i], "--verify") == 0) ||
(STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {
if (params.cryptoctx == NULL) {
- GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);
- if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg")))
+ if (NULL == (params.cryptoctx = g_mime_gpg_context_new(NULL, "gpg")))
fprintf (stderr, "Failed to construct gpg context.\n");
else
g_mime_gpg_context_set_always_trust((GMimeGpgContext*)params.cryptoctx, FALSE);
- g_object_unref (session);
- session = NULL;
}
if (STRNCMP_LITERAL (argv[i], "--decrypt") == 0)
params.decrypt = 1;
--
1.7.8.3
^ permalink raw reply related [flat|nested] 2+ messages in thread