[PATCH 3/3] cli: impliment structured output version 4

David Bremner david at tethera.net
Wed May 31 04:45:35 PDT 2017


The only non-trivial change to use the new format is in
notmuch-crypto-instert-sigstatus-button.
---
 emacs/notmuch-crypto.el |  9 +++++----
 emacs/notmuch-query.el  |  2 +-
 notmuch-client.h        |  2 +-
 notmuch-show.c          | 52 +++++++++++++++++++++++++++++++++++++++++++------
 test/T350-crypto.sh     | 22 ++++++++++-----------
 test/T355-smime.sh      |  4 ++--
 test/T450-emacs-show.sh |  2 +-
 7 files changed, 66 insertions(+), 27 deletions(-)

diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index 0af727ef..66ad39ba 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -90,13 +90,14 @@ mode."
   :supertype 'notmuch-button-type)
 
 (defun notmuch-crypto-insert-sigstatus-button (sigstatus from)
-  (let* ((status (plist-get sigstatus :status))
+  (let* ((flags (plist-get sigstatus :flags))
+	 (status (plist-get sigstatus :status))
 	 (help-msg nil)
 	 (label "Signature not processed")
 	 (face 'notmuch-crypto-signature-unknown)
 	 (button-action (lambda (button) (message (button-get button 'help-echo)))))
     (cond
-     ((string= status "good")
+     ((plist-get flags :good)
       (let ((fingerprint (concat "0x" (plist-get sigstatus :fingerprint))))
 	;; if userid present, userid has full or greater validity
 	(if (plist-member sigstatus :userid)
@@ -108,12 +109,12 @@ mode."
 	    (setq face 'notmuch-crypto-signature-good-key)))
 	(setq button-action 'notmuch-crypto-sigstatus-good-callback)
 	(setq help-msg (concat "Click to list key ID 0x" fingerprint "."))))
-     ((string= status "error")
+     ((plist-get flags :error)
       (let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
 	(setq label (concat "Unknown key ID " keyid " or unsupported algorithm"))
 	(setq button-action 'notmuch-crypto-sigstatus-error-callback)
 	(setq help-msg (concat "Click to retrieve key ID " keyid " from keyserver and redisplay."))))
-     ((string= status "bad")
+     ((plist-get flags :bad)
       (let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
 	(setq label (concat "Bad signature (claimed key ID " keyid ")"))
 	(setq face 'notmuch-crypto-signature-bad)))
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index 48acb551..592fd8f1 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -30,7 +30,7 @@ A thread is a forest or list of trees. A tree is a two element
 list where the first element is a message, and the second element
 is a possibly empty forest of replies.
 "
-  (let ((args '("show" "--format=sexp" "--format-version=3")))
+  (let ((args '("show" "--format=sexp" "--format-version=4")))
     (if notmuch-show-process-crypto
 	(setq args (append args '("--decrypt"))))
     (setq args (append args search-terms))
diff --git a/notmuch-client.h b/notmuch-client.h
index 62d4bcec..77b34184 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -145,7 +145,7 @@ chomp_newline (char *str)
  * this.  New (required) map fields can be added without increasing
  * this.
  */
-#define NOTMUCH_FORMAT_CUR 3
+#define NOTMUCH_FORMAT_CUR 4
 /* The minimum supported structured output format version.  Requests
  * for format versions below this will return an error. */
 #define NOTMUCH_FORMAT_MIN 1
diff --git a/notmuch-show.c b/notmuch-show.c
index accea48a..f9fd9c14 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -340,6 +340,40 @@ signature_status_to_string (GMimeSignatureStatus x)
     return "unknown";
 }
 
+
+/* Print signature flags */
+static void
+format_signature_flags (sprinter_t *sp, GMimeSignature *signature)
+{
+    GMimeSignatureError errors = g_mime_signature_get_errors (signature);
+
+    struct {
+	GMimeSignatureError bit;
+	const char * string;
+    } key_map[] = {
+	{ GMIME_SIGNATURE_ERROR_EXPSIG, "sig-expired" },
+	{ GMIME_SIGNATURE_ERROR_NO_PUBKEY, "key-missing"},
+	{ GMIME_SIGNATURE_ERROR_EXPKEYSIG, "key-expired"},
+	{ GMIME_SIGNATURE_ERROR_REVKEYSIG, "key-revoked"},
+	{ GMIME_SIGNATURE_ERROR_UNSUPP_ALGO, "alg-unsupported"},
+    };
+
+    sp->map_key (sp, "flags");
+    sp->begin_map (sp);
+
+    sp->map_key (sp, signature_status_to_string (g_mime_signature_get_status (signature)));
+    sp->boolean (sp, TRUE);
+
+    for (unsigned int i = 0; i < ARRAY_SIZE (key_map); i++) {
+	if (errors & key_map[i].bit) {
+	    sp->map_key (sp, key_map[i].string);
+	    sp->boolean (sp, TRUE);
+	}
+    }
+
+    sp->end (sp);
+}
+
 /* Signature status sprinter (GMime 2.6) */
 static void
 format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
@@ -364,8 +398,10 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
 
 	/* status */
 	GMimeSignatureStatus status = g_mime_signature_get_status (signature);
-	sp->map_key (sp, "status");
-	sp->string (sp, signature_status_to_string (status));
+	if (notmuch_format_version <= 3) {
+	    sp->map_key (sp, "status");
+	    sp->string (sp, signature_status_to_string (status));
+	}
 
 	GMimeCertificate *certificate = g_mime_signature_get_certificate (signature);
 	if (status == GMIME_SIGNATURE_STATUS_GOOD) {
@@ -404,10 +440,14 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
 	    }
 	}
 
-	GMimeSignatureError errors = g_mime_signature_get_errors (signature);
-	if (errors != GMIME_SIGNATURE_ERROR_NONE) {
-	    sp->map_key (sp, "errors");
-	    sp->integer (sp, errors);
+	if (notmuch_format_version <= 3) {
+	    GMimeSignatureError errors = g_mime_signature_get_errors (signature);
+	    if (errors != GMIME_SIGNATURE_ERROR_NONE) {
+		sp->map_key (sp, "errors");
+		sp->integer (sp, errors);
+	    }
+	} else {
+	    format_signature_flags (sp, signature);
 	}
 
 	sp->end (sp);
diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
index d21cad14..dcad2f60 100755
--- a/test/T350-crypto.sh
+++ b/test/T350-crypto.sh
@@ -53,8 +53,8 @@ expected='[[[{"id": "XXXXX",
  "To": "test_suite at notmuchmail.org",
  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
  "body": [{"id": 1,
- "sigstatus": [{"status": "good",
- "fingerprint": "'$FINGERPRINT'",
+ "sigstatus": [{"fingerprint": "'$FINGERPRINT'",
+ "flags": {"good" : true},
  "created": 946728000}],
  "content-type": "multipart/signed",
  "content": [{"id": 2,
@@ -87,8 +87,8 @@ expected='[[[{"id": "XXXXX",
  "To": "test_suite at notmuchmail.org",
  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
  "body": [{"id": 1,
- "sigstatus": [{"status": "good",
- "fingerprint": "'$FINGERPRINT'",
+ "sigstatus": [{"fingerprint": "'$FINGERPRINT'",
+ "flags": {"good" : true},
  "created": 946728000,
  "userid": " Notmuch Test Suite <test_suite at notmuchmail.org> (INSECURE!)"}],
  "content-type": "multipart/signed",
@@ -121,9 +121,8 @@ expected='[[[{"id": "XXXXX",
  "To": "test_suite at notmuchmail.org",
  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
  "body": [{"id": 1,
- "sigstatus": [{"status": "error",
- "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
- "errors": 2}],
+ "sigstatus": [{"keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
+ "flags": {"error" : true, "key-missing": true}}],
  "content-type": "multipart/signed",
  "content": [{"id": 2,
  "content-type": "text/plain",
@@ -292,8 +291,8 @@ expected='[[[{"id": "XXXXX",
  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
  "body": [{"id": 1,
  "encstatus": [{"status": "good"}],
- "sigstatus": [{"status": "good",
- "fingerprint": "'$FINGERPRINT'",
+ "sigstatus": [{"fingerprint": "'$FINGERPRINT'",
+ "flags" : {"good" : true},
  "created": 946728000,
  "userid": " Notmuch Test Suite <test_suite at notmuchmail.org> (INSECURE!)"}],
  "content-type": "multipart/encrypted",
@@ -365,9 +364,8 @@ expected='[[[{"id": "XXXXX",
  "To": "test_suite at notmuchmail.org",
  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
  "body": [{"id": 1,
- "sigstatus": [{"status": "error",
- "keyid": "6D92612D94E46381",
- "errors": 8}],
+ "sigstatus": [{"keyid": "6D92612D94E46381",
+ "flags": {"error" : true, "key-revoked" : true}}],
  "content-type": "multipart/signed",
  "content": [{"id": 2,
  "content-type": "text/plain",
diff --git a/test/T355-smime.sh b/test/T355-smime.sh
index 0f39bc69..c5ab0b6a 100755
--- a/test/T355-smime.sh
+++ b/test/T355-smime.sh
@@ -64,8 +64,8 @@ expected='[[[{"id": "XXXXX",
  "To": "test_suite at notmuchmail.org",
  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
  "body": [{"id": 1,
- "sigstatus": [{"status": "good",
- "fingerprint": "'$FINGERPRINT'",
+ "sigstatus": [{"fingerprint": "'$FINGERPRINT'",
+ "flags": {"good" : true},
  "expires": 424242424,
  "created": 946728000}],
  "content-type": "multipart/signed",
diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh
index d302efb6..c4bc5ce0 100755
--- a/test/T450-emacs-show.sh
+++ b/test/T450-emacs-show.sh
@@ -191,7 +191,7 @@ This is an error (see *Notmuch errors* for more details)
 === ERROR ===
 [XXX]
 This is an error
-command: YYY/notmuch_fail show --format\\=sexp --format-version\\=3 --exclude\\=false \\' \\* \\'
+command: YYY/notmuch_fail show --format\\=sexp --format-version\\=4 --exclude\\=false \\' \\* \\'
 exit status: 1
 stderr:
 This is an error
-- 
2.11.0



More information about the notmuch mailing list