unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org, notmuch@freelists.org
Subject: [PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR, STATUS} to gmime-3
Date: Sat,  3 Jun 2017 14:47:47 -0300	[thread overview]
Message-ID: <20170603174754.16911-17-david@tethera.net> (raw)
In-Reply-To: <20170603174754.16911-1-david@tethera.net>

The ERROR enum is merged into to the STATUS enum, and the set of flags
is different.
---
 notmuch-show.c     | 49 ++++++++++++++++++++++++++++++++++++++-----------
 util/gmime-extra.c | 41 +++++++++++++++++++++++++++++++++++++++++
 util/gmime-extra.h | 13 ++++++++++++-
 3 files changed, 91 insertions(+), 12 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 8afc5273..3234ab95 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -320,22 +320,21 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out,
 	g_object_unref(stream_filter);
 }
 
-/* Get signature status string (GMime 2.6) */
 static const char*
-signature_status_to_string (GMimeSignatureStatus x)
+signature_status_to_string (GMimeSignatureStatus status)
 {
-    switch (x) {
-    case GMIME_SIGNATURE_STATUS_GOOD:
-	return "good";
-    case GMIME_SIGNATURE_STATUS_BAD:
+    if (g_mime_signature_status_bad (status))
 	return "bad";
-    case GMIME_SIGNATURE_STATUS_ERROR:
+
+    if (g_mime_signature_status_error (status))
 	return "error";
-    }
+
+    if (g_mime_signature_status_good (status))
+	return "good";
+
     return "unknown";
 }
 
-
 /* Print signature flags */
 struct key_map_struct {
     GMimeSignatureError bit;
@@ -358,6 +357,7 @@ do_format_signature_errors (sprinter_t *sp, struct key_map_struct *key_map,
     sp->end (sp);
 }
 
+#if (GMIME_MAJOR_VERSION < 3)
 static void
 format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
 {
@@ -376,6 +376,33 @@ format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
 
     do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
 }
+#else
+static void
+format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
+{
+    GMimeSignatureError errors = g_mime_signature_get_errors (signature);
+
+    if (!(errors & GMIME_SIGNATURE_STATUS_ERROR_MASK))
+	return;
+
+    struct {
+	GMimeSignatureStatus bit;
+	const char * string;
+    } key_map[] = {
+	{ GMIME_SIGNATURE_STATUS_KEY_REVOKED, "key-revoked"},
+	{ GMIME_SIGNATURE_STATUS_KEY_EXPIRED, "key-expired"},
+	{ GMIME_SIGNATURE_STATUS_SIG_EXPIRED, "sig-expired" },
+	{ GMIME_SIGNATURE_STATUS_KEY_MISSING, "key-missing"},
+	{ GMIME_SIGNATURE_STATUS_CRL_MISSING, "crl-missing"},
+	{ GMIME_SIGNATURE_STATUS_CRL_TOO_OLD, "crl-too-old"},
+	{ GMIME_SIGNATURE_STATUS_BAD_POLICY, "bad-policy"},
+	{ GMIME_SIGNATURE_STATUS_SYS_ERROR, "sys-error"},
+	{ GMIME_SIGNATURE_STATUS_TOFU_CONFLICT, "tofu-conflict"},
+    };
+
+    do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
+}
+#endif
 
 /* Signature status sprinter (GMime 2.6) */
 static void
@@ -405,7 +432,7 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
 	sp->string (sp, signature_status_to_string (status));
 
 	GMimeCertificate *certificate = g_mime_signature_get_certificate (signature);
-	if (status == GMIME_SIGNATURE_STATUS_GOOD) {
+	if (g_mime_signature_status_good (status)) {
 	    if (certificate) {
 		sp->map_key (sp, "fingerprint");
 		sp->string (sp, g_mime_certificate_get_fingerprint (certificate));
@@ -443,7 +470,7 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
 
 	if (notmuch_format_version <= 3) {
 	    GMimeSignatureError errors = g_mime_signature_get_errors (signature);
-	    if (errors != GMIME_SIGNATURE_ERROR_NONE) {
+	    if (g_mime_signature_status_error (errors)) {
 		sp->map_key (sp, "errors");
 		sp->integer (sp, errors);
 	    }
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
index 8f9e77a1..350f75ea 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -84,6 +84,20 @@ g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
     return talloc_strdup(ctx, g_mime_message_get_reply_to (message));
 }
 
+gboolean
+g_mime_signature_status_good (GMimeSignatureStatus status) {
+    return (status == GMIME_SIGNATURE_STATUS_GOOD);
+}
+
+gboolean
+g_mime_signature_status_bad (GMimeSignatureStatus status) {
+    return (status == GMIME_SIGNATURE_STATUS_BAD);
+}
+
+gboolean
+g_mime_signature_status_error (GMimeSignatureError error) {
+    return (error != GMIME_SIGNATURE_ERROR_NONE);
+}
 
 #else /* GMime >= 3.0 */
 
@@ -125,5 +139,32 @@ g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
     return g_string_talloc_strdup (ctx, internet_address_list_to_string (list, NULL, 0));
 }
 
+void
+g_mime_parser_set_scan_from (GMimeParser *parser, gboolean flag)
+{
+    g_mime_parser_set_format (parser, flag ? GMIME_FORMAT_MBOX : GMIME_FORMAT_MESSAGE);
+}
+
+/* In GMime 3.0, status GOOD and VALID both imply something about the
+ * validity of the UIDs attached to the signing key. This forces us to
+ * use following somewhat relaxed definition of a "good" signature to
+ * preserve current notmuch semantics.
+ */
+
+gboolean
+g_mime_signature_status_good (GMimeSignatureStatus status) {
+    return ((status  & (GMIME_SIGNATURE_STATUS_RED | GMIME_SIGNATURE_STATUS_ERROR_MASK)) == 0);
+}
+
+gboolean
+g_mime_signature_status_bad (GMimeSignatureStatus status) {
+    return (status & GMIME_SIGNATURE_STATUS_RED);
+}
+
+gboolean
+g_mime_signature_status_error (GMimeSignatureStatus status) {
+    return (status & GMIME_SIGNATURE_STATUS_ERROR_MASK);
+}
+
 
 #endif
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 3c16e46e..90f230c1 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -13,7 +13,6 @@ GMimeStream *g_mime_stream_stdout_new(void);
 #define GMIME_ADDRESS_TYPE_CC GMIME_RECIPIENT_TYPE_CC
 #define GMIME_ADDRESS_TYPE_BCC GMIME_RECIPIENT_TYPE_BCC
 
-
 #else /* GMime >= 3.0 */
 typedef GMimeAddressType GMimeRecipientType;
 
@@ -39,6 +38,9 @@ typedef GMimeAddressType GMimeRecipientType;
 #define internet_address_to_string(ia,encode) internet_address_to_string (ia,NULL,encode)
 #define internet_address_list_parse_string(str) internet_address_list_parse (NULL,str)
 typedef GMimeAddressType GMimeRecipientType;
+
+typedef GMimeSignatureStatus GMimeSignatureError;
+
 #endif
 
 /**
@@ -61,6 +63,7 @@ char *g_mime_message_get_date_string (void *ctx, GMimeMessage *message);
 
 InternetAddressList * g_mime_message_get_from (GMimeMessage *message);
 
+
 /**
  * return string for From: address
  * (owned by gmime)
@@ -73,4 +76,12 @@ InternetAddressList * g_mime_message_get_reply_to_list (GMimeMessage *message);
  * return talloc allocated reply-to string
  */
 char * g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message);
+
+void g_mime_parser_set_scan_from (GMimeParser *parser, gboolean flag);
+
+gboolean g_mime_signature_status_good (GMimeSignatureStatus status);
+
+gboolean g_mime_signature_status_bad (GMimeSignatureStatus status);
+
+gboolean g_mime_signature_status_error (GMimeSignatureError status);
 #endif
-- 
2.11.0

  parent reply	other threads:[~2017-06-03 17:48 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-03 17:47 David Bremner
2017-06-03 17:47 ` [PATCH 01/23] emacs: convert to use format-version 3 David Bremner
2017-06-03 17:47 ` [PATCH 02/23] devel/schemata: describe version 4 David Bremner
2017-06-03 17:47 ` [PATCH 03/23] cli: implement structured output " David Bremner
2017-07-04 11:37   ` David Bremner
2017-06-03 17:47 ` [PATCH 04/23] test/multipart: reorganize creation of multipart message David Bremner
2017-06-03 17:47 ` [PATCH 05/23] test: mark inclusion of headers as broken in gmime-2.x David Bremner
2017-06-03 17:47 ` [PATCH 06/23] test: mark test as broken in gmime 3.0 David Bremner
2017-06-03 17:47 ` [PATCH 07/23] test/crypto: mark extra space in userid as a bug in gmime-2.6 David Bremner
2017-07-05 20:26   ` Tomi Ollila
2017-07-06 14:15     ` Daniel Kahn Gillmor
2017-06-03 17:47 ` [PATCH 08/23] test: add test for modified pgp/mime signed message David Bremner
2017-06-03 17:47 ` [PATCH 09/23] test/crypto: add test for corrupted signatures David Bremner
2017-07-05 11:03   ` David Bremner
2017-06-03 17:47 ` [PATCH 10/23] test: test parsing of malformed from addresses David Bremner
2017-06-03 17:47 ` [PATCH 11/23] cli: replace use of g_mime_message_get_date_as_string David Bremner
2017-06-03 17:47 ` [PATCH 12/23] cli: replace use of g_mime_message_get_reply_to David Bremner
2017-06-03 17:47 ` [PATCH 13/23] lib/cli: replace use of g_mime_message_get_sender David Bremner
2017-06-03 17:47 ` [PATCH 14/23] cli: replace use of g_mime_message_get_recipients David Bremner
2017-06-03 17:47 ` [PATCH 15/23] util: fake gmime-2.6 compatible API for gmime-3.0 David Bremner
2017-06-03 17:47 ` David Bremner [this message]
2017-07-07 22:18   ` [PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR, STATUS} to gmime-3 Daniel Kahn Gillmor
2017-06-03 17:47 ` [PATCH 17/23] cli: hide rename of GMimeCertificateTrust David Bremner
2017-06-03 17:47 ` [PATCH 18/23] lib: wrap use of g_mime_utils_header_decode_date David Bremner
2017-06-03 17:47 ` [PATCH 19/23] lib: refactor _notmuch_messsage_file_get_combined_header David Bremner
2017-06-03 17:47 ` [PATCH 20/23] lib: add version of _n_m_f_get_combinded_header for gmime 3.0 David Bremner
2017-06-03 17:47 ` [PATCH 21/23] lib: paper over allocation difference David Bremner
2017-06-03 17:47 ` [PATCH 22/23] cli: make keyid from fingerprint in gmime 3.0 David Bremner
2017-06-03 17:47 ` [PATCH 23/23] cli: wrap getting uid David Bremner
2017-07-14 13:12   ` [PATCH 1/3] config: deprecate/drop crypto.gpg_path under gmime 2.6/3.0 Daniel Kahn Gillmor
2017-07-14 13:12     ` [PATCH 2/3] clean up use of constants in g_mime_multipart_ wrappers Daniel Kahn Gillmor
2017-07-14 13:12     ` [PATCH 3/3] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3.0 Daniel Kahn Gillmor
2017-07-15 11:55       ` David Bremner
2017-07-15 18:57       ` [PATCH 1/4] cli/crypto: treat failure to create a crypto context as fatal David Bremner
2017-07-15 18:57         ` [PATCH 2/4] cli/crypto: eliminated compiler warnings about unused arguments David Bremner
2017-07-15 18:57         ` [PATCH 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3 David Bremner
2017-07-15 22:45           ` Daniel Kahn Gillmor
2017-07-15 23:01             ` [PATCH v2 1/4] cli/crypto: treat failure to create a crypto context as fatal Daniel Kahn Gillmor
2017-07-15 23:01               ` [PATCH v2 2/4] cli/crypto: eliminated compiler warnings about unused arguments Daniel Kahn Gillmor
2017-07-15 23:01               ` [PATCH v2 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3 Daniel Kahn Gillmor
2017-07-15 23:01               ` [PATCH v2 4/4] crypto: clean up unused definitions in gmime 3.0 Daniel Kahn Gillmor
2017-07-16 10:53               ` [PATCH v2 1/4] cli/crypto: treat failure to create a crypto context as fatal David Bremner
2017-07-15 18:57         ` [PATCH 4/4] crypto: clean up unused definitions in gmime 3.0 David Bremner
2017-07-14 13:19     ` [PATCH 1/3] config: deprecate/drop crypto.gpg_path under gmime 2.6/3.0 Daniel Kahn Gillmor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170603174754.16911-17-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@freelists.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).