From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 87B7A431E82 for ; Mon, 16 Jan 2012 18:25:48 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Um2DCucZ9CpS for ; Mon, 16 Jan 2012 18:25:47 -0800 (PST) Received: from smtp4.mundo-r.com (smtp4.mundo-r.com [212.51.32.151]) by olra.theworths.org (Postfix) with ESMTP id 17081429E35 for ; Mon, 16 Jan 2012 18:25:46 -0800 (PST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap4EAFnbFE9bdWOb/2dsb2JhbABCAqsLgSWCEYFzAQUnLzM5BxE5DRGIFbYRiWABBQgFBBEFAQYBAQYBBSwBAgEJAQEBCkkMZIFwAgYBSAsBgxQElRGSQw X-IronPort-AV: E=Sophos;i="4.71,521,1320620400"; d="scan'208";a="856064831" Received: from 155.99.117.91.static.mundo-r.com (HELO fanzine.igalia.com) ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 17 Jan 2012 03:25:46 +0100 Received: from dsl-hkibrasgw3-fe7cfb00-20.dhcp.inet.fi ([84.251.124.20] helo=kaze.ara-ara.org) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim) id 1Rmyjz-0008JZ-Rp for ; Tue, 17 Jan 2012 03:25:45 +0100 Received: (nullmailer pid 25215 invoked by uid 1000); Tue, 17 Jan 2012 02:26:48 -0000 From: Adrian Perez To: notmuch@notmuchmail.org Subject: [PATCH] Update notmuch to use the GMime 2.6 API Date: Tue, 17 Jan 2012 04:26:48 +0200 Message-Id: <1326767208-25174-2-git-send-email-aperez@igalia.com> X-Mailer: git-send-email 1.7.8.3 In-Reply-To: <1326767208-25174-1-git-send-email-aperez@igalia.com> References: <1326767208-25174-1-git-send-email-aperez@igalia.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jan 2012 02:25:48 -0000 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