unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* (no subject)
@ 2017-06-03 17:47 David Bremner
  2017-06-03 17:47 ` [PATCH 01/23] emacs: convert to use format-version 3 David Bremner
                   ` (22 more replies)
  0 siblings, 23 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

This is the first allegedly complete version of support for gmime 3

It obsoletes several partial series [1][2]

   - id:20170602022232.17264-1-david@tethera.net
   - patches 9-11, starting at id:20170527165121.9654-10-david@tethera.net

There still remains the question of whether we should include

      [PATCH 10/23] test: test parsing of malformed from addresses

I'm not very optimistic about a fix coming along, and it's not
obviously a big issue for users.

The following are crypto related, and could particularly use review

[PATCH 01/23] emacs: convert to use format-version 3
[PATCH 02/23] devel/schemata: describe version 4
[PATCH 03/23] cli: implement structured output version 4
[PATCH 07/23] test/crypto: mark extra space in userid as a bug in
[PATCH 08/23] test: add test for modified pgp/mime signed message
[PATCH 09/23] test/crypto: add test for corrupted signatures
[PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR,STATUS}
[PATCH 17/23] cli: hide rename of GMimeCertificateTrust
[PATCH 22/23] cli: make keyid from fingerprint in gmime 3.0
[PATCH 23/23] cli: wrap getting uid

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH 01/23] emacs: convert to use format-version 3
  2017-06-03 17:47 David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 02/23] devel/schemata: describe version 4 David Bremner
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

Keeping the emacs interface running old format-versions makes it
impossible to test new format-versions or deprecate old ones.
---
 emacs/notmuch-address.el | 2 +-
 emacs/notmuch-mua.el     | 2 +-
 emacs/notmuch-query.el   | 2 +-
 emacs/notmuch-show.el    | 3 ++-
 emacs/notmuch-tree.el    | 2 +-
 emacs/notmuch.el         | 2 +-
 test/T310-emacs.sh       | 2 +-
 test/T450-emacs-show.sh  | 2 +-
 8 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index d504ff2d..74a4584f 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -317,7 +317,7 @@ execution, CALLBACK is called when harvesting finishes."
 			    (when config-query
 			      (format " and (%s)" config-query)))
 		  from-or-to-me-query))
-	 (args `("address" "--format=sexp" "--format-version=2"
+	 (args `("address" "--format=sexp" "--format-version=3"
 		 ,(if sent "--output=recipients" "--output=sender")
 		 "--deduplicate=address"
 		 ,query)))
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 93747b1c..ddfb9811 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -176,7 +176,7 @@ mutiple parts get a header."
   (unless (bolp) (insert "\n")))
 
 (defun notmuch-mua-reply (query-string &optional sender reply-all)
-  (let ((args '("reply" "--format=sexp" "--format-version=1"))
+  (let ((args '("reply" "--format=sexp" "--format-version=3"))
 	(process-crypto notmuch-show-process-crypto)
 	reply
 	original)
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index 436ad160..48acb551 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=1")))
+  (let ((args '("show" "--format=sexp" "--format-version=3")))
     (if notmuch-show-process-crypto
 	(setq args (append args '("--decrypt"))))
     (setq args (append args search-terms))
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index e7c22da0..21fcc036 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1660,9 +1660,10 @@ current thread."
 
 ;; dme: Would it make sense to use a macro for many of these?
 
+;; XXX TODO figure out what to do about multiple filenames
 (defun notmuch-show-get-filename ()
   "Return the filename of the current message."
-  (notmuch-show-get-prop :filename))
+  (car (notmuch-show-get-prop :filename)))
 
 (defun notmuch-show-get-header (header &optional props)
   "Return the named header of the current message, if any."
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index d4d40761..6812d7e9 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -917,7 +917,7 @@ the same as for the function notmuch-tree."
     (notmuch-tag-clear-cache)
     (let ((proc (notmuch-start-notmuch
 		 "notmuch-tree" (current-buffer) #'notmuch-tree-process-sentinel
-		 "show" "--body=false" "--format=sexp" "--format-version=2"
+		 "show" "--body=false" "--format=sexp" "--format-version=3"
 		 message-arg search-args))
 	  ;; Use a scratch buffer to accumulate partial output.
 	  ;; This buffer will be killed by the sentinel, which
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 40b9fabd..a4a7fd8b 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -990,7 +990,7 @@ the configured default sort order."
       (save-excursion
 	(let ((proc (notmuch-start-notmuch
 		     "notmuch-search" buffer #'notmuch-search-process-sentinel
-		     "search" "--format=sexp" "--format-version=2"
+		     "search" "--format=sexp" "--format-version=3"
 		     (if oldest-first
 			 "--sort=oldest-first"
 		       "--sort=newest-first")
diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
index ef599849..8a881941 100755
--- a/test/T310-emacs.sh
+++ b/test/T310-emacs.sh
@@ -1014,7 +1014,7 @@ YYY/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)
 === ERROR ===
 [XXX]
 YYY/notmuch_fail exited with status 1
-command: YYY/notmuch_fail search --format\=sexp --format-version\=2 --sort\=newest-first tag\:inbox
+command: YYY/notmuch_fail search --format\=sexp --format-version\=3 --sort\=newest-first tag\:inbox
 exit status: 1"
 
 test_begin_subtest "Search handles subprocess warnings"
diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh
index 74d546bd..d302efb6 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\\=1 --exclude\\=false \\' \\* \\'
+command: YYY/notmuch_fail show --format\\=sexp --format-version\\=3 --exclude\\=false \\' \\* \\'
 exit status: 1
 stderr:
 This is an error
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 02/23] devel/schemata: describe version 4
  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 ` David Bremner
  2017-06-03 17:47 ` [PATCH 03/23] cli: implement structured output " David Bremner
                   ` (20 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

Replace numeric errors with human readable flags.  Not all sig_error
keys will necessarily be generated with a given version of gmime.

Drop status "none" as it's currrently unused and I don't know what
it's for.
---
 devel/schemata | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/devel/schemata b/devel/schemata
index 00ebb7a6..42b1bcf3 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -14,7 +14,7 @@ are interleaved. Keys are printed as keywords (symbols preceded by a
 colon), e.g. (:id "123" :time 54321 :from "foobar"). Null is printed as
 nil, true as t and false as nil.
 
-This is version 2 of the structured output format.
+This is version 4 of the structured output format.
 
 Version history
 ---------------
@@ -30,6 +30,10 @@ v3
 - Replaced message.filename string with a list of filenames.
 - Added part.content-disposition field.
 
+v4
+- replace signature error integer bitmask with a set of flags for
+  individual errors.
+
 Common non-terminals
 --------------------
 
@@ -121,7 +125,7 @@ sigstatus = [signature*]
 
 signature = {
     # (signature_status_to_string)
-    status:         "none"|"good"|"bad"|"error"|"unknown",
+    status:         "good"|"bad"|"error"|"unknown",
     # if status is "good":
     fingerprint?:   string,
     created?:       unix_time,
@@ -129,8 +133,20 @@ signature = {
     userid?:        string
     # if status is not "good":
     keyid?:         string
-    # if the signature has errors:
-    errors?:        int
+    errors?: 	    sig_errors
+}
+
+sig_errors = {
+    key-revoked?: bool,
+    key-expired?: bool,
+    sig-expired?: bool,
+    key-missing?: bool,
+    alg-unsupported?: bool,
+    crl-missing?: bool,
+    crl-too-old?: bool,
+    bad-policy?: bool,
+    sys-error?: bool,
+    tofu-conflict?: bool
 }
 
 notmuch search schema
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 03/23] cli: implement structured output version 4
  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 ` 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
                   ` (19 subsequent siblings)
  22 siblings, 1 reply; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

Since the error field is unused by the emacs front end, no changes are
needed other than bumping the format version number.

As it is, this is a bit overengineered, but it will reduce duplication
when we support gmime 3.0
---
 emacs/notmuch-query.el  |  2 +-
 notmuch-client.h        |  2 +-
 notmuch-show.c          | 54 +++++++++++++++++++++++++++++++++++++++++++++----
 test/T350-crypto.sh     |  4 ++--
 test/T355-smime.sh      |  4 ++--
 test/T450-emacs-show.sh |  2 +-
 6 files changed, 57 insertions(+), 11 deletions(-)

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..1614547b 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -340,6 +340,48 @@ signature_status_to_string (GMimeSignatureStatus x)
     return "unknown";
 }
 
+
+/* Print signature flags */
+struct key_map_struct {
+    GMimeSignatureError bit;
+    const char * string;
+};
+
+static void
+do_format_signature_errors (sprinter_t *sp, struct key_map_struct *key_map,
+			    unsigned int array_map_len, GMimeSignatureError errors) {
+    sp->map_key (sp, "errors");
+    sp->begin_map (sp);
+
+    for (unsigned int i = 0; i < array_map_len; i++) {
+	if (errors & key_map[i].bit) {
+	    sp->map_key (sp, key_map[i].string);
+	    sp->boolean (sp, TRUE);
+	}
+    }
+
+    sp->end (sp);
+}
+
+static void
+format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
+{
+    GMimeSignatureError errors = g_mime_signature_get_errors (signature);
+
+    if (errors == GMIME_SIGNATURE_ERROR_NONE)
+	return;
+
+    struct key_map_struct 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"},
+    };
+
+    do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
+}
+
 /* Signature status sprinter (GMime 2.6) */
 static void
 format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
@@ -404,10 +446,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_errors (sp, signature);
 	}
 
 	sp->end (sp);
diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
index d21cad14..0753acf3 100755
--- a/test/T350-crypto.sh
+++ b/test/T350-crypto.sh
@@ -123,7 +123,7 @@ expected='[[[{"id": "XXXXX",
  "body": [{"id": 1,
  "sigstatus": [{"status": "error",
  "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
- "errors": 2}],
+ "errors": {"key-missing": true}}],
  "content-type": "multipart/signed",
  "content": [{"id": 2,
  "content-type": "text/plain",
@@ -367,7 +367,7 @@ expected='[[[{"id": "XXXXX",
  "body": [{"id": 1,
  "sigstatus": [{"status": "error",
  "keyid": "6D92612D94E46381",
- "errors": 8}],
+ "errors": {"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..03d24581 100755
--- a/test/T355-smime.sh
+++ b/test/T355-smime.sh
@@ -64,8 +64,8 @@ expected='[[[{"id": "XXXXX",
  "To": "test_suite@notmuchmail.org",
  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
  "body": [{"id": 1,
- "sigstatus": [{"status": "good",
- "fingerprint": "'$FINGERPRINT'",
+ "sigstatus": [{"fingerprint": "'$FINGERPRINT'",
+ "status": "good",
  "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

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 04/23] test/multipart: reorganize creation of multipart message
  2017-06-03 17:47 David Bremner
                   ` (2 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 03/23] cli: implement structured output " David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 05/23] test: mark inclusion of headers as broken in gmime-2.x David Bremner
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

We want to have the bodies of the multipart available in a file on
their own for planned modifications to tests.
---
 test/T190-multipart.sh | 40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh
index 12a10451..91a632c6 100755
--- a/test/T190-multipart.sh
+++ b/test/T190-multipart.sh
@@ -2,14 +2,7 @@
 test_description="output of multipart message"
 . ./test-lib.sh || exit 1
 
-cat <<EOF > embedded_message
-From: Carl Worth <cworth@cworth.org>
-To: cworth@cworth.org
-Subject: html message
-Date: Fri, 05 Jan 2001 15:42:57 +0000
-User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
-Message-ID: <87liy5ap01.fsf@yoom.home.cworth.org>
-MIME-Version: 1.0
+cat <<EOF > embedded_message_body
 Content-Type: multipart/alternative; boundary="==-=-=="
 
 --==-=-==
@@ -24,15 +17,19 @@ This is an embedded message, with a multipart/alternative part.
 
 --==-=-==--
 EOF
-
-cat <<EOF > ${MAIL_DIR}/multipart
+cat <<EOF > embedded_message
 From: Carl Worth <cworth@cworth.org>
 To: cworth@cworth.org
-Subject: Multipart message
-Date: Fri, 05 Jan 2001 15:43:57 +0000
+Subject: html message
+Date: Fri, 05 Jan 2001 15:42:57 +0000
 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
-Message-ID: <87liy5ap00.fsf@yoom.home.cworth.org>
+Message-ID: <87liy5ap01.fsf@yoom.home.cworth.org>
 MIME-Version: 1.0
+EOF
+
+cat embedded_message_body >> embedded_message
+
+cat <<EOF > multipart_body
 Content-Type: multipart/signed; boundary="==-=-=";
 	micalg=pgp-sha1; protocol="application/pgp-signature"
 
@@ -44,8 +41,9 @@ Content-Type: message/rfc822
 Content-Disposition: inline
 
 EOF
-cat embedded_message >> ${MAIL_DIR}/multipart
-cat <<EOF >> ${MAIL_DIR}/multipart
+
+cat embedded_message >> multipart_body
+cat <<EOF >> multipart_body
 
 --=-=-=
 Content-Disposition: attachment; filename=attachment
@@ -73,6 +71,18 @@ W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
 --==-=-=--
 EOF
 
+cat <<EOF > ${MAIL_DIR}/multipart
+From: Carl Worth <cworth@cworth.org>
+To: cworth@cworth.org
+Subject: Multipart message
+Date: Fri, 05 Jan 2001 15:43:57 +0000
+User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
+Message-ID: <87liy5ap00.fsf@yoom.home.cworth.org>
+MIME-Version: 1.0
+EOF
+
+cat multipart_body >> ${MAIL_DIR}/multipart
+
 cat <<EOF > ${MAIL_DIR}/base64-part-with-crlf
 From: Carl Worth <cworth@cworth.org>
 To: cworth@cworth.org
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 05/23] test: mark inclusion of headers as broken in gmime-2.x
  2017-06-03 17:47 David Bremner
                   ` (3 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 04/23] test/multipart: reorganize creation of multipart message David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 06/23] test: mark test as broken in gmime 3.0 David Bremner
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

The output of headers here reflects an underlying bug / quirk of
gmime-2.6.
---
 test/T190-multipart.sh | 28 ++++------------------------
 1 file changed, 4 insertions(+), 24 deletions(-)

diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh
index 91a632c6..94bb0570 100755
--- a/test/T190-multipart.sh
+++ b/test/T190-multipart.sh
@@ -465,8 +465,9 @@ notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUT
 test_expect_equal_file "${MAIL_DIR}"/multipart OUTPUT
 
 test_begin_subtest "--format=raw --part=1, message body"
+test_subtest_broken_gmime_2
 notmuch show --format=raw --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
-test_expect_equal_file "${MAIL_DIR}"/multipart OUTPUT
+test_expect_equal_file multipart_body OUTPUT
 
 test_begin_subtest "--format=raw --part=2, multipart/mixed"
 notmuch show --format=raw --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
@@ -518,30 +519,9 @@ notmuch show --format=raw --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUT
 test_expect_equal_file embedded_message OUTPUT
 
 test_begin_subtest "--format=raw --part=4, rfc822's multipart"
+test_subtest_broken_gmime_2
 notmuch show --format=raw --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
-cat <<EOF >EXPECTED
-From: Carl Worth <cworth@cworth.org>
-To: cworth@cworth.org
-Subject: html message
-Date: Fri, 05 Jan 2001 15:42:57 +0000
-User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
-Message-ID: <87liy5ap01.fsf@yoom.home.cworth.org>
-MIME-Version: 1.0
-Content-Type: multipart/alternative; boundary="==-=-=="
-
---==-=-==
-Content-Type: text/html
-
-<p>This is an embedded message, with a multipart/alternative part.</p>
-
---==-=-==
-Content-Type: text/plain
-
-This is an embedded message, with a multipart/alternative part.
-
---==-=-==--
-EOF
-test_expect_equal_file EXPECTED OUTPUT
+test_expect_equal_file embedded_message_body OUTPUT
 
 test_begin_subtest "--format=raw --part=5, rfc822's html part"
 notmuch show --format=raw --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 06/23] test: mark test as broken in gmime 3.0
  2017-06-03 17:47 David Bremner
                   ` (4 preceding siblings ...)
  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 ` 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
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

Currently I'm not sure what the intent of this test is, so it's not
clear if the new answer is better or worse than the old one.
---
 test/T310-emacs.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
index 8a881941..c8a25de2 100755
--- a/test/T310-emacs.sh
+++ b/test/T310-emacs.sh
@@ -86,6 +86,7 @@ test_emacs "(let ((notmuch-show-indent-messages-width 4))
 test_expect_equal_file $EXPECTED/notmuch-show-thread-maildir-storage-with-fourfold-indentation OUTPUT
 
 test_begin_subtest "notmuch-show for message with invalid From"
+test_subtest_broken_gmime_3
 add_message "[subject]=\"message-with-invalid-from\"" \
 	    "[from]=\"\\\"Invalid \\\" From\\\" <test_suite@notmuchmail.org>\""
 thread=$(notmuch search --output=threads subject:message-with-invalid-from)
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 07/23] test/crypto: mark extra space in userid as a bug in gmime-2.6
  2017-06-03 17:47 David Bremner
                   ` (5 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 06/23] test: mark test as broken in gmime 3.0 David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-07-05 20:26   ` Tomi Ollila
  2017-06-03 17:47 ` [PATCH 08/23] test: add test for modified pgp/mime signed message David Bremner
                   ` (15 subsequent siblings)
  22 siblings, 1 reply; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

I can't see the space in the output of gpg -K --with-colons
---
 test/T350-crypto.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
index 0753acf3..720a2225 100755
--- a/test/T350-crypto.sh
+++ b/test/T350-crypto.sh
@@ -69,6 +69,7 @@ test_expect_equal_json \
     "$expected"
 
 test_begin_subtest "signature verification with full owner trust"
+test_subtest_broken_gmime_2
 # give the key full owner trust
 echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
 gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
@@ -90,7 +91,7 @@ expected='[[[{"id": "XXXXX",
  "sigstatus": [{"status": "good",
  "fingerprint": "'$FINGERPRINT'",
  "created": 946728000,
- "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
+ "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
  "content-type": "multipart/signed",
  "content": [{"id": 2,
  "content-type": "text/plain",
@@ -276,6 +277,7 @@ test_expect_success \
     "(mml-secure-message-sign-encrypt)"'
 
 test_begin_subtest "decryption + signature verification"
+test_subtest_broken_gmime_2
 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
     | notmuch_json_show_sanitize \
     | sed -e 's|"created": [1234567890]*|"created": 946728000|')
@@ -295,7 +297,7 @@ expected='[[[{"id": "XXXXX",
  "sigstatus": [{"status": "good",
  "fingerprint": "'$FINGERPRINT'",
  "created": 946728000,
- "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
+ "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
  "content-type": "multipart/encrypted",
  "content": [{"id": 2,
  "content-type": "application/pgp-encrypted",
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 08/23] test: add test for modified pgp/mime signed message
  2017-06-03 17:47 David Bremner
                   ` (6 preceding siblings ...)
  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-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 09/23] test/crypto: add test for corrupted signatures David Bremner
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

This is a good thing to test in any case, but particularly as we hit
the dark corners of the gmime crypto API.
---
 test/T350-crypto.sh | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
index 720a2225..4a2c4c85 100755
--- a/test/T350-crypto.sh
+++ b/test/T350-crypto.sh
@@ -68,6 +68,45 @@ test_expect_equal_json \
     "$output" \
     "$expected"
 
+test_begin_subtest "detection of modified signed contents"
+emacs_fcc_message \
+    "bad signed message 001" \
+    "Incriminating stuff. This is a test signed message." \
+    "(mml-secure-message-sign)"
+
+file=$(notmuch search --output=files subject:"bad signed message 001")
+
+sed -i 's/Incriminating stuff. //' ${file}
+
+output=$(notmuch show --format=json --verify subject:"bad signed message 001" \
+    | notmuch_json_show_sanitize \
+    | sed -e 's|"created": [1234567890]*|"created": 946728000|')
+expected='[[[{"id": "XXXXX",
+ "match": true,
+ "excluded": false,
+ "filename": ["YYYYY"],
+ "timestamp": 946728000,
+ "date_relative": "2000-01-01",
+ "tags": ["inbox","signed"],
+ "headers": {"Subject": "bad signed message 001",
+ "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
+ "To": "test_suite@notmuchmail.org",
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
+ "body": [{"id": 1,
+ "sigstatus": [{"status": "bad",
+ "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}],
+ "content-type": "multipart/signed",
+ "content": [{"id": 2,
+ "content-type": "text/plain",
+ "content": "This is a test signed message.\n"},
+ {"id": 3,
+ "content-type": "application/pgp-signature",
+ "content-length": "NONZERO"}]}]},
+ []]]]'
+test_expect_equal_json \
+    "$output" \
+    "$expected"
+
 test_begin_subtest "signature verification with full owner trust"
 test_subtest_broken_gmime_2
 # give the key full owner trust
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 09/23] test/crypto: add test for corrupted signatures
  2017-06-03 17:47 David Bremner
                   ` (7 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 08/23] test: add test for modified pgp/mime signed message David Bremner
@ 2017-06-03 17:47 ` 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
                   ` (13 subsequent siblings)
  22 siblings, 1 reply; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

Have an empty list of signatures is not the nicest mechanism to signal
complete failure to verify, but it's the one we currently have.
---
 test/T350-crypto.sh | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
index 4a2c4c85..7dab39a2 100755
--- a/test/T350-crypto.sh
+++ b/test/T350-crypto.sh
@@ -107,6 +107,49 @@ test_expect_equal_json \
     "$output" \
     "$expected"
 
+test_begin_subtest "corrupted pgp/mime signature"
+emacs_fcc_message \
+    "bad signed message 002" \
+    "Incriminating stuff. This is a test signed message." \
+    "(mml-secure-message-sign)"
+
+file=$(notmuch search --output=files subject:"bad signed message 002")
+
+awk '/-----BEGIN PGP SIGNATURE-----/{flag=1;print;next} \
+     /-----END PGP SIGNATURE-----/{flag=0;print;next} \
+     flag{gsub(/[A-Za-z]/,"0");print}!flag{print}' $file > $file.new
+
+rm $file
+mv $file.new $file
+
+output=$(notmuch show --format=json --verify subject:"bad signed message 002" \
+    | notmuch_json_show_sanitize \
+    | sed -e 's|"created": [1234567890]*|"created": 946728000|')
+expected='[[[{"id": "XXXXX",
+ "match": true,
+ "excluded": false,
+ "filename": ["YYYYY"],
+ "timestamp": 946728000,
+ "date_relative": "2000-01-01",
+ "tags": ["inbox","signed"],
+ "headers": {"Subject": "bad signed message 002",
+ "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
+ "To": "test_suite@notmuchmail.org",
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
+ "body": [{"id": 1,
+ "sigstatus": [],
+ "content-type": "multipart/signed",
+ "content": [{"id": 2,
+ "content-type": "text/plain",
+ "content": "Incriminating stuff. This is a test signed message.\n"},
+ {"id": 3,
+ "content-type": "application/pgp-signature",
+ "content-length": "NONZERO"}]}]},
+ []]]]'
+test_expect_equal_json \
+    "$output" \
+    "$expected"
+
 test_begin_subtest "signature verification with full owner trust"
 test_subtest_broken_gmime_2
 # give the key full owner trust
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 10/23] test: test parsing of malformed from addresses
  2017-06-03 17:47 David Bremner
                   ` (8 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 09/23] test/crypto: add test for corrupted signatures David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 11/23] cli: replace use of g_mime_message_get_date_as_string David Bremner
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

This was previously tested in T200-thread-naming.sh, but failures due
to changes in address parsing were confusing because they had nothing
to do with threads.
---
 test/T050-new.sh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/test/T050-new.sh b/test/T050-new.sh
index ffa303ef..66235306 100755
--- a/test/T050-new.sh
+++ b/test/T050-new.sh
@@ -140,6 +140,13 @@ ln -s "$external_msg_filename" "$gen_msg_filename"
 output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 1 new message to the database."
 
+test_begin_subtest "Index malformed from address."
+test_subtest_broken_gmime_3
+add_message '[subject]="test subject"' \
+            '[date]="Sat, 13 Jan 2001 15:43:45 -0000"' \
+            '[from]="Malformed From \<malformed_from@notmuchmail.org\>"'
+output=$(notmuch search --sort=newest-first from:malformed_from@notmuchmail.org | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX   2001-01-13 [1/1] Malformed From; test subject (inbox unread)"
 
 test_begin_subtest "Broken symlink aborts"
 ln -s does-not-exist "${MAIL_DIR}/broken"
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 11/23] cli: replace use of g_mime_message_get_date_as_string
  2017-06-03 17:47 David Bremner
                   ` (9 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 10/23] test: test parsing of malformed from addresses David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 12/23] cli: replace use of g_mime_message_get_reply_to David Bremner
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

This function goes away in gmime-3.0. Also, the memory management is
apparently error prone, witness the memory leak in notmuch-reply.
---
 notmuch-reply.c    |  2 +-
 notmuch-show.c     |  8 ++------
 util/gmime-extra.c | 35 +++++++++++++++++++++++++++++++++++
 util/gmime-extra.h |  8 ++++++++
 4 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index b88f1d31..65753c18 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -61,7 +61,7 @@ format_part_reply (GMimeStream *stream, mime_node_t *node)
 				  recipients_string);
 	g_free (recipients_string);
 	g_mime_stream_printf (stream, "> Subject: %s\n", g_mime_message_get_subject (message));
-	g_mime_stream_printf (stream, "> Date: %s\n", g_mime_message_get_date_as_string (message));
+	g_mime_stream_printf (stream, "> Date: %s\n", g_mime_message_get_date_string (node, message));
 	g_mime_stream_printf (stream, ">\n");
     } else if (GMIME_IS_PART (node->part)) {
 	GMimeContentType *content_type = g_mime_object_get_content_type (node->part);
diff --git a/notmuch-show.c b/notmuch-show.c
index 1614547b..62275923 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -204,7 +204,6 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     InternetAddressList *recipients;
     char *recipients_string;
     const char *reply_to_string;
-    char *date_string;
 
     sp->begin_map (sp);
 
@@ -252,9 +251,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
 	sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "References"));
     } else {
 	sp->map_key (sp, "Date");
-	date_string = g_mime_message_get_date_as_string (message);
-	sp->string (sp, date_string);
-	g_free (date_string);
+	sp->string (sp, g_mime_message_get_date_string (sp, message));
     }
 
     sp->end (sp);
@@ -532,9 +529,8 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "Cc: %s\n", recipients_string);
 	g_free (recipients_string);
-	date_string = g_mime_message_get_date_as_string (message);
+	date_string = g_mime_message_get_date_string (node, message);
 	g_mime_stream_printf (stream, "Date: %s\n", date_string);
-	g_free (date_string);
 	g_mime_stream_printf (stream, "\fheader}\n");
 
 	g_mime_stream_printf (stream, "\fbody{\n");
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
index f1538587..01fe9e35 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -18,3 +18,38 @@ g_mime_stream_stdout_new()
 
     return stream_buffered;
 }
+
+/**
+ * copy a glib string into a talloc context, and free it.
+ */
+static char*
+g_string_talloc_strdup (void *ctx, char *g_string)
+{
+    char *new_str = talloc_strdup (ctx, g_string);
+    g_free (g_string);
+    return new_str;
+}
+
+#if (GMIME_MAJOR_VERSION < 3)
+
+char *
+g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
+{
+    char *date = g_mime_message_get_date_as_string (message);
+    return g_string_talloc_strdup (ctx, date);
+}
+
+#else /* GMime >= 3.0 */
+
+char *
+g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
+{
+    GDateTime* parsed_date = g_mime_message_get_date (message);
+    if (parsed_date) {
+	char *date = g_mime_utils_header_format_date (parsed_date);
+	return g_string_talloc_strdup (ctx, date);
+    } else {
+	return talloc_strdup(ctx, "Thu, 01 Jan 1970 00:00:00 +0000");
+    }
+}
+#endif
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index e0432a94..6e2f6ca5 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -3,4 +3,12 @@
 #include <gmime/gmime.h>
 
 GMimeStream *g_mime_stream_stdout_new(void);
+
+#include <talloc.h>
+
+/**
+ * return talloc allocated date string
+ */
+char *g_mime_message_get_date_string (void *ctx, GMimeMessage *message);
+
 #endif
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 12/23] cli: replace use of g_mime_message_get_reply_to
  2017-06-03 17:47 David Bremner
                   ` (10 preceding siblings ...)
  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 ` David Bremner
  2017-06-03 17:47 ` [PATCH 13/23] lib/cli: replace use of g_mime_message_get_sender David Bremner
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

This function changes signature in gmime 3.0, so we provide two new
functions, one for each signature.
---
 notmuch-reply.c    | 10 ++++------
 notmuch-show.c     |  4 +++-
 util/gmime-extra.c | 37 +++++++++++++++++++++++++++++++++++++
 util/gmime-extra.h | 12 ++++++++++++
 4 files changed, 56 insertions(+), 7 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 65753c18..12439284 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -268,12 +268,11 @@ reply_to_header_is_redundant (GMimeMessage *message,
 
 static InternetAddressList *get_sender(GMimeMessage *message)
 {
-    const char *reply_to;
-
-    reply_to = g_mime_message_get_reply_to (message);
-    if (reply_to && *reply_to) {
-	InternetAddressList *reply_to_list;
+    InternetAddressList *reply_to_list;
 
+    reply_to_list = g_mime_message_get_reply_to_list (message);
+    if (reply_to_list &&
+	internet_address_list_length (reply_to_list) > 0) {
         /*
 	 * Some mailing lists munge the Reply-To header despite it
 	 * being A Bad Thing, see
@@ -287,7 +286,6 @@ static InternetAddressList *get_sender(GMimeMessage *message)
 	 * to the list. Note that the address in the Reply-To header
 	 * will always appear in the reply if reply_all is true.
 	 */
-	reply_to_list = internet_address_list_parse_string (reply_to);
 	if (! reply_to_header_is_redundant (message, reply_to_list))
 	    return reply_to_list;
 
diff --git a/notmuch-show.c b/notmuch-show.c
index 62275923..b4339abe 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -204,6 +204,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     InternetAddressList *recipients;
     char *recipients_string;
     const char *reply_to_string;
+    void *local = talloc_new (sp);
 
     sp->begin_map (sp);
 
@@ -237,7 +238,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
 	g_free (recipients_string);
     }
 
-    reply_to_string = g_mime_message_get_reply_to (message);
+    reply_to_string = g_mime_message_get_reply_to_string (local, message);
     if (reply_to_string) {
 	sp->map_key (sp, "Reply-To");
 	sp->string (sp, reply_to_string);
@@ -255,6 +256,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     }
 
     sp->end (sp);
+    talloc_free (local);
 }
 
 /* Write a MIME text part out to the given stream.
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
index 01fe9e35..33751de7 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -39,6 +39,28 @@ g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
     return g_string_talloc_strdup (ctx, date);
 }
 
+InternetAddressList *
+g_mime_message_get_reply_to_list (GMimeMessage *message)
+{
+    const char *reply_to;
+
+    reply_to = g_mime_message_get_reply_to (message);
+    if (reply_to && *reply_to)
+	return internet_address_list_parse_string (reply_to);
+    else
+	return NULL;
+}
+
+/**
+ * return talloc allocated reply-to string
+ */
+char *
+g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
+{
+    return talloc_strdup(ctx, g_mime_message_get_reply_to (message));
+}
+
+
 #else /* GMime >= 3.0 */
 
 char *
@@ -52,4 +74,19 @@ g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
 	return talloc_strdup(ctx, "Thu, 01 Jan 1970 00:00:00 +0000");
     }
 }
+
+InternetAddressList *
+g_mime_message_get_reply_to_list(GMimeMessage *message)
+{
+    return g_mime_message_get_reply_to (message);
+}
+
+char *
+g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
+{
+    InternetAddressList *list = g_mime_message_get_reply_to (message);
+    return g_string_talloc_strdup (ctx, internet_address_list_to_string (list, NULL, 0));
+}
+
+
 #endif
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 6e2f6ca5..794ffbfd 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -10,5 +10,17 @@ GMimeStream *g_mime_stream_stdout_new(void);
  * return talloc allocated date string
  */
 char *g_mime_message_get_date_string (void *ctx, GMimeMessage *message);
+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);
+
+
+/**
+ * Return glib allocated reply-to list
+ */
+InternetAddressList * g_mime_message_get_reply_to_list (GMimeMessage *message);
 
 #endif
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 13/23] lib/cli: replace use of g_mime_message_get_sender
  2017-06-03 17:47 David Bremner
                   ` (11 preceding siblings ...)
  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 ` David Bremner
  2017-06-03 17:47 ` [PATCH 14/23] cli: replace use of g_mime_message_get_recipients David Bremner
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

This function changes semantics in gmime-3.0 so make a new function
that provides the same functionality in both
---
 lib/index.cc          |  6 ++----
 lib/notmuch-private.h |  2 +-
 notmuch-reply.c       |  5 ++---
 notmuch-show.c        |  4 ++--
 util/gmime-extra.c    | 17 +++++++++++++++++
 util/gmime-extra.h    | 17 +++++++++++++----
 6 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/lib/index.cc b/lib/index.cc
index 8c145540..d2472896 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -439,7 +439,7 @@ _notmuch_message_index_file (notmuch_message_t *message,
 {
     GMimeMessage *mime_message;
     InternetAddressList *addresses;
-    const char *from, *subject;
+    const char *subject;
     notmuch_status_t status;
 
     status = _notmuch_message_file_get_mime_message (message_file,
@@ -447,9 +447,7 @@ _notmuch_message_index_file (notmuch_message_t *message,
     if (status)
 	return status;
 
-    from = g_mime_message_get_sender (mime_message);
-
-    addresses = internet_address_list_parse_string (from);
+    addresses = g_mime_message_get_from (mime_message);
     if (addresses) {
 	_index_address_list (message, "from", addresses);
 	g_object_unref (addresses);
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index ac315e4c..5dfebf5d 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -46,7 +46,7 @@ NOTMUCH_BEGIN_DECLS
 
 #include <talloc.h>
 
-#include <gmime/gmime.h>
+#include "gmime-extra.h"
 
 #include "xutil.h"
 #include "error_util.h"
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 12439284..29a5ab6c 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -47,9 +47,9 @@ format_part_reply (GMimeStream *stream, mime_node_t *node)
 	InternetAddressList *recipients;
 	char *recipients_string;
 
-	g_mime_stream_printf (stream, "> From: %s\n", g_mime_message_get_sender (message));
 	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
 	recipients_string = internet_address_list_to_string (recipients, 0);
+	g_mime_stream_printf (stream, "> From: %s\n", g_mime_message_get_from_string (message));
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "> To: %s\n",
 				  recipients_string);
@@ -292,8 +292,7 @@ static InternetAddressList *get_sender(GMimeMessage *message)
 	g_object_unref (G_OBJECT (reply_to_list));
     }
 
-    return internet_address_list_parse_string (
-	g_mime_message_get_sender (message));
+    return g_mime_message_get_from (message);
 }
 
 static InternetAddressList *get_to(GMimeMessage *message)
diff --git a/notmuch-show.c b/notmuch-show.c
index b4339abe..edc0537c 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -212,7 +212,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     sp->string (sp, g_mime_message_get_subject (message));
 
     sp->map_key (sp, "From");
-    sp->string (sp, g_mime_message_get_sender (message));
+    sp->string (sp, g_mime_message_get_from_string (message));
 
     recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
     recipients_string = internet_address_list_to_string (recipients, 0);
@@ -520,9 +520,9 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
 	if (node->envelope_file)
 	    g_mime_stream_printf (stream, "%s\n", _get_one_line_summary (ctx, node->envelope_file));
 	g_mime_stream_printf (stream, "Subject: %s\n", g_mime_message_get_subject (message));
-	g_mime_stream_printf (stream, "From: %s\n", g_mime_message_get_sender (message));
 	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
 	recipients_string = internet_address_list_to_string (recipients, 0);
+	g_mime_stream_printf (stream, "From: %s\n", g_mime_message_get_from_string (message));
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "To: %s\n", recipients_string);
 	g_free (recipients_string);
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
index 33751de7..8590c55d 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -40,6 +40,17 @@ g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
 }
 
 InternetAddressList *
+g_mime_message_get_from (GMimeMessage *message)
+{
+    return internet_address_list_parse_string (g_mime_message_get_sender (message));
+}
+
+const char *
+g_mime_message_get_from_string (GMimeMessage *message) {
+    return  g_mime_message_get_sender (message);
+}
+
+InternetAddressList *
 g_mime_message_get_reply_to_list (GMimeMessage *message)
 {
     const char *reply_to;
@@ -81,6 +92,12 @@ g_mime_message_get_reply_to_list(GMimeMessage *message)
     return g_mime_message_get_reply_to (message);
 }
 
+const char *
+g_mime_message_get_from_string (GMimeMessage *message)
+{
+    return g_mime_object_get_header (GMIME_OBJECT (message), "From");
+}
+
 char *
 g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
 {
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 794ffbfd..04d63026 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -9,18 +9,27 @@ GMimeStream *g_mime_stream_stdout_new(void);
 /**
  * return talloc allocated date string
  */
+
 char *g_mime_message_get_date_string (void *ctx, GMimeMessage *message);
-InternetAddressList * g_mime_message_get_reply_to_list (GMimeMessage *message);
 
 /**
- * return talloc allocated reply-to string
+ * glib allocated list of From: addresses
  */
-char * g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message);
 
+InternetAddressList * g_mime_message_get_from (GMimeMessage *message);
 
 /**
- * Return glib allocated reply-to list
+ * return string for From: address
+ * (owned by gmime)
  */
+const char * g_mime_message_get_from_string (GMimeMessage *message);
+
 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);
+
+
 #endif
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 14/23] cli: replace use of g_mime_message_get_recipients
  2017-06-03 17:47 David Bremner
                   ` (12 preceding siblings ...)
  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 ` David Bremner
  2017-06-03 17:47 ` [PATCH 15/23] util: fake gmime-2.6 compatible API for gmime-3.0 David Bremner
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

This function, and associated enum, have been renamed and generalized
in gmime-3.0.
---
 notmuch-reply.c    | 21 +++++++++------------
 notmuch-show.c     | 17 +++++------------
 util/gmime-extra.c | 20 ++++++++++++++++++++
 util/gmime-extra.h | 22 ++++++++++++++++++++--
 4 files changed, 54 insertions(+), 26 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 29a5ab6c..f9e8431f 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -44,18 +44,15 @@ format_part_reply (GMimeStream *stream, mime_node_t *node)
 			      notmuch_message_get_header (node->envelope_file, "from"));
     } else if (GMIME_IS_MESSAGE (node->part)) {
 	GMimeMessage *message = GMIME_MESSAGE (node->part);
-	InternetAddressList *recipients;
 	char *recipients_string;
 
-	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
-	recipients_string = internet_address_list_to_string (recipients, 0);
 	g_mime_stream_printf (stream, "> From: %s\n", g_mime_message_get_from_string (message));
+	recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_TO);
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "> To: %s\n",
 				  recipients_string);
 	g_free (recipients_string);
-	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
-	recipients_string = internet_address_list_to_string (recipients, 0);
+	recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_CC);
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "> Cc: %s\n",
 				  recipients_string);
@@ -297,17 +294,17 @@ static InternetAddressList *get_sender(GMimeMessage *message)
 
 static InternetAddressList *get_to(GMimeMessage *message)
 {
-    return g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
+    return g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_TO);
 }
 
 static InternetAddressList *get_cc(GMimeMessage *message)
 {
-    return g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
+    return g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_CC);
 }
 
 static InternetAddressList *get_bcc(GMimeMessage *message)
 {
-    return g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_BCC);
+    return g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_BCC);
 }
 
 /* Augment the recipients of 'reply' from the "Reply-to:", "From:",
@@ -338,10 +335,10 @@ add_recipients_from_message (GMimeMessage *reply,
 	InternetAddressList * (*get_header)(GMimeMessage *message);
 	GMimeRecipientType recipient_type;
     } reply_to_map[] = {
-	{ get_sender,	GMIME_RECIPIENT_TYPE_TO },
-	{ get_to,	GMIME_RECIPIENT_TYPE_TO },
-	{ get_cc,	GMIME_RECIPIENT_TYPE_CC },
-	{ get_bcc,	GMIME_RECIPIENT_TYPE_BCC },
+	{ get_sender,	GMIME_ADDRESS_TYPE_TO },
+	{ get_to,	GMIME_ADDRESS_TYPE_TO },
+	{ get_cc,	GMIME_ADDRESS_TYPE_CC },
+	{ get_bcc,	GMIME_ADDRESS_TYPE_BCC },
     };
     const char *from_addr = NULL;
     unsigned int i;
diff --git a/notmuch-show.c b/notmuch-show.c
index edc0537c..8afc5273 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -201,7 +201,6 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     /* Any changes to the JSON or S-Expression format should be
      * reflected in the file devel/schemata. */
 
-    InternetAddressList *recipients;
     char *recipients_string;
     const char *reply_to_string;
     void *local = talloc_new (sp);
@@ -214,24 +213,21 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     sp->map_key (sp, "From");
     sp->string (sp, g_mime_message_get_from_string (message));
 
-    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
-    recipients_string = internet_address_list_to_string (recipients, 0);
+    recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_TO);
     if (recipients_string) {
 	sp->map_key (sp, "To");
 	sp->string (sp, recipients_string);
 	g_free (recipients_string);
     }
 
-    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
-    recipients_string = internet_address_list_to_string (recipients, 0);
+    recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_CC);
     if (recipients_string) {
 	sp->map_key (sp, "Cc");
 	sp->string (sp, recipients_string);
 	g_free (recipients_string);
     }
 
-    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_BCC);
-    recipients_string = internet_address_list_to_string (recipients, 0);
+    recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_BCC);
     if (recipients_string) {
 	sp->map_key (sp, "Bcc");
 	sp->string (sp, recipients_string);
@@ -512,7 +508,6 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
 
     if (GMIME_IS_MESSAGE (node->part)) {
 	GMimeMessage *message = GMIME_MESSAGE (node->part);
-	InternetAddressList *recipients;
 	char *recipients_string;
 	char *date_string;
 
@@ -520,14 +515,12 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
 	if (node->envelope_file)
 	    g_mime_stream_printf (stream, "%s\n", _get_one_line_summary (ctx, node->envelope_file));
 	g_mime_stream_printf (stream, "Subject: %s\n", g_mime_message_get_subject (message));
-	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
-	recipients_string = internet_address_list_to_string (recipients, 0);
 	g_mime_stream_printf (stream, "From: %s\n", g_mime_message_get_from_string (message));
+	recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_TO);
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "To: %s\n", recipients_string);
 	g_free (recipients_string);
-	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
-	recipients_string = internet_address_list_to_string (recipients, 0);
+	recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_CC);
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "Cc: %s\n", recipients_string);
 	g_free (recipients_string);
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
index 8590c55d..8f9e77a1 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -33,6 +33,19 @@ g_string_talloc_strdup (void *ctx, char *g_string)
 #if (GMIME_MAJOR_VERSION < 3)
 
 char *
+g_mime_message_get_address_string (GMimeMessage *message, GMimeRecipientType type)
+{
+    InternetAddressList *list = g_mime_message_get_recipients (message, type);
+    return internet_address_list_to_string (list, 0);
+}
+
+inline InternetAddressList *
+g_mime_message_get_addresses (GMimeMessage *message, GMimeRecipientType type)
+{
+    return g_mime_message_get_recipients (message, type);
+}
+
+char *
 g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
 {
     char *date = g_mime_message_get_date_as_string (message);
@@ -75,6 +88,13 @@ g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
 #else /* GMime >= 3.0 */
 
 char *
+g_mime_message_get_address_string (GMimeMessage *message, GMimeAddressType type)
+{
+    InternetAddressList *list = g_mime_message_get_addresses (message, type);
+    return internet_address_list_to_string (list, NULL, 0);
+}
+
+char *
 g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
 {
     GDateTime* parsed_date = g_mime_message_get_date (message);
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 04d63026..fef4f425 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -6,6 +6,26 @@ GMimeStream *g_mime_stream_stdout_new(void);
 
 #include <talloc.h>
 
+
+#if (GMIME_MAJOR_VERSION < 3)
+
+#define GMIME_ADDRESS_TYPE_TO GMIME_RECIPIENT_TYPE_TO
+#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;
+#endif
+
+/**
+ * Return the contents of the appropriate address header as a string
+ * Should be freed using g_free
+ */
+char *g_mime_message_get_address_string (GMimeMessage *message, GMimeRecipientType type);
+
+InternetAddressList * g_mime_message_get_addresses (GMimeMessage *message, GMimeRecipientType type);
+
 /**
  * return talloc allocated date string
  */
@@ -30,6 +50,4 @@ 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);
-
-
 #endif
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 15/23] util: fake gmime-2.6 compatible API for gmime-3.0
  2017-06-03 17:47 David Bremner
                   ` (13 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 14/23] cli: replace use of g_mime_message_get_recipients David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR, STATUS} to gmime-3 David Bremner
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

Several functions have added arguments which accept NULL and provide
hopefully sensible defaults. Use macros to minimize source changes.
---
 util/gmime-extra.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index fef4f425..3c16e46e 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -16,6 +16,29 @@ GMimeStream *g_mime_stream_stdout_new(void);
 
 #else /* GMime >= 3.0 */
 typedef GMimeAddressType GMimeRecipientType;
+
+#define GMIME_ENABLE_RFC_2047_WORKAROUNDS 0xdeadbeef
+#define g_mime_content_type_to_string(c) g_mime_content_type_get_mime_type (c)
+#define g_mime_filter_crlf_new(encode,dots) g_mime_filter_dos2unix_new (FALSE)
+#define g_mime_gpg_context_new(func,path) g_mime_gpg_context_new ()
+#define g_mime_gpg_context_set_use_agent(ctx,val) /*ignore*/
+#define g_mime_gpg_context_set_always_trust(ctx,val) /*ignore*/
+#define g_mime_init(flags) g_mime_init()
+#define g_mime_message_add_recipient(m,t,n,a) g_mime_message_add_mailbox (m,t,n,a)
+#define g_mime_message_set_subject(m,s) g_mime_message_set_subject(m,s,NULL)
+#define g_mime_multipart_encrypted_decrypt(mpe,ctx,out,err) g_mime_multipart_encrypted_decrypt(mpe, 0, NULL, out, err)
+#define g_mime_multipart_signed_verify(mps,ctx,err) g_mime_multipart_signed_verify(mps, 0, err)
+#define g_mime_object_write_to_stream(o,s) g_mime_object_write_to_stream (o,NULL,s)
+#define g_mime_object_set_header(o,h,v) g_mime_object_set_header (o,h,v,NULL)
+#define g_mime_parser_construct_message(p) g_mime_parser_construct_message (p, g_mime_parser_options_get_default ())
+#define g_mime_part_get_content_object(p) g_mime_part_get_content (p)
+#define g_mime_pkcs7_context_new(arg) g_mime_pkcs7_context_new()
+#define g_mime_pkcs7_context_set_always_trust(ctx,val) /*ignore*/
+#define g_mime_signature_get_errors(sig) g_mime_signature_get_status (sig)
+#define g_mime_utils_header_decode_text(txt) g_mime_utils_header_decode_text (NULL, txt)
+#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;
 #endif
 
 /**
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR, STATUS} to gmime-3
  2017-06-03 17:47 David Bremner
                   ` (14 preceding siblings ...)
  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
  2017-07-07 22:18   ` Daniel Kahn Gillmor
  2017-06-03 17:47 ` [PATCH 17/23] cli: hide rename of GMimeCertificateTrust David Bremner
                   ` (6 subsequent siblings)
  22 siblings, 1 reply; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

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

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 17/23] cli: hide rename of GMimeCertificateTrust
  2017-06-03 17:47 David Bremner
                   ` (15 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR, STATUS} to gmime-3 David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 18/23] lib: wrap use of g_mime_utils_header_decode_date David Bremner
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

Both the enum and the values are renamed in GMime 3.0.
---
 util/gmime-extra.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 90f230c1..6b74724e 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -37,10 +37,20 @@ typedef GMimeAddressType GMimeRecipientType;
 #define g_mime_utils_header_decode_text(txt) g_mime_utils_header_decode_text (NULL, txt)
 #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;
 
+typedef GMimeTrust GMimeCertificateTrust;
+
+#define GMIME_CERTIFICATE_TRUST_UNKNOWN GMIME_TRUST_UNKNOWN
+#define GMIME_CERTIFICATE_TRUST_UNDEFINED GMIME_TRUST_UNDEFINED
+#define GMIME_CERTIFICATE_TRUST_NEVER GMIME_TRUST_NEVER
+#define GMIME_CERTIFICATE_TRUST_MARGINAL GMIME_TRUST_MARGINAL
+#define GMIME_CERTIFICATE_TRUST_FULLY GMIME_TRUST_FULL
+#define GMIME_CERTIFICATE_TRUST_ULTIMATE GMIME_TRUST_ULTIMATE
+
 #endif
 
 /**
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 18/23] lib: wrap use of g_mime_utils_header_decode_date
  2017-06-03 17:47 David Bremner
                   ` (16 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 17/23] cli: hide rename of GMimeCertificateTrust David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 19/23] lib: refactor _notmuch_messsage_file_get_combined_header David Bremner
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

This changes return type in gmime 3.0
---
 lib/message.cc     |  2 +-
 util/gmime-extra.c | 19 +++++++++++++++++++
 util/gmime-extra.h |  2 ++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/message.cc b/lib/message.cc
index b330dcce..f78e5a9d 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1037,7 +1037,7 @@ _notmuch_message_set_header_values (notmuch_message_t *message,
     if (date == NULL || *date == '\0') {
 	time_value = 0;
     } else {
-	time_value = g_mime_utils_header_decode_date (date, NULL);
+	time_value = g_mime_utils_header_decode_date_unix (date);
 	/*
 	 * Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=779923
 	 */
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
index 350f75ea..3c50a293 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -99,6 +99,11 @@ g_mime_signature_status_error (GMimeSignatureError error) {
     return (error != GMIME_SIGNATURE_ERROR_NONE);
 }
 
+time_t
+g_mime_utils_header_decode_date_unix (const char *date) {
+    return g_mime_utils_header_decode_date (date, NULL);
+}
+
 #else /* GMime >= 3.0 */
 
 char *
@@ -166,5 +171,19 @@ g_mime_signature_status_error (GMimeSignatureStatus status) {
     return (status & GMIME_SIGNATURE_STATUS_ERROR_MASK);
 }
 
+gint64
+g_mime_utils_header_decode_date_unix (const char *date) {
+    GDateTime* parsed_date = g_mime_utils_header_decode_date (date);
+    time_t ret;
+
+    if (parsed_date) {
+	ret = g_date_time_to_unix (parsed_date);
+	g_date_time_unref (parsed_date);
+    } else {
+	ret = 0;
+    }
+
+    return ret;
+}
 
 #endif
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 6b74724e..d744c4e4 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -94,4 +94,6 @@ gboolean g_mime_signature_status_good (GMimeSignatureStatus status);
 gboolean g_mime_signature_status_bad (GMimeSignatureStatus status);
 
 gboolean g_mime_signature_status_error (GMimeSignatureError status);
+
+gint64 g_mime_utils_header_decode_date_unix (const char *date);
 #endif
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 19/23] lib: refactor _notmuch_messsage_file_get_combined_header
  2017-06-03 17:47 David Bremner
                   ` (17 preceding siblings ...)
  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 ` 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
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

We need to rewrite the loop for gmime-3.0; move the loop body to its
own function to avoid code duplication.  Keep the common exit via
"goto DONE" to make this pure code movement.  It's important to note
that the existing exit path only deallocates the iterator.
---
 lib/message-file.c | 57 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 32 insertions(+), 25 deletions(-)

diff --git a/lib/message-file.c b/lib/message-file.c
index db18b163..7d38ebd0 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -201,6 +201,37 @@ _notmuch_message_file_get_mime_message (notmuch_message_file_t *message,
  *
  * Return NULL on errors, empty string for non-existing headers.
  */
+
+static char *
+_extend_header (char *combined, const char *value) {
+    char *decoded;
+
+    decoded = g_mime_utils_header_decode_text (value);
+    if (! decoded) {
+	if (combined) {
+	    g_free (combined);
+	    combined = NULL;
+	}
+	goto DONE;
+    }
+
+    if (combined) {
+	char *tmp = g_strdup_printf ("%s %s", combined, decoded);
+	g_free (decoded);
+	g_free (combined);
+	if (! tmp) {
+	    combined = NULL;
+	    goto DONE;
+	}
+
+	combined = tmp;
+    } else {
+	combined = decoded;
+    }
+ DONE:
+    return combined;
+}
+
 static char *
 _notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
 					   const char *header)
@@ -222,37 +253,13 @@ _notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
 
     do {
 	const char *value;
-	char *decoded;
-
 	if (strcasecmp (g_mime_header_iter_get_name (iter), header) != 0)
 	    continue;
 
 	/* Note that GMime retains ownership of value... */
 	value = g_mime_header_iter_get_value (iter);
 
-	/* ... while decoded needs to be freed with g_free(). */
-	decoded = g_mime_utils_header_decode_text (value);
-	if (! decoded) {
-	    if (combined) {
-		g_free (combined);
-		combined = NULL;
-	    }
-	    goto DONE;
-	}
-
-	if (combined) {
-	    char *tmp = g_strdup_printf ("%s %s", combined, decoded);
-	    g_free (decoded);
-	    g_free (combined);
-	    if (! tmp) {
-		combined = NULL;
-		goto DONE;
-	    }
-
-	    combined = tmp;
-	} else {
-	    combined = decoded;
-	}
+	combined = _extend_header (combined, value);
     } while (g_mime_header_iter_next (iter));
 
     /* Return empty string for non-existing headers. */
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 20/23] lib: add version of _n_m_f_get_combinded_header for gmime 3.0
  2017-06-03 17:47 David Bremner
                   ` (18 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 19/23] lib: refactor _notmuch_messsage_file_get_combined_header David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 21/23] lib: paper over allocation difference David Bremner
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

The iterator is gone, so we need a new loop structure.
---
 lib/message-file.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/lib/message-file.c b/lib/message-file.c
index 7d38ebd0..d7acf0d5 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -232,6 +232,7 @@ _extend_header (char *combined, const char *value) {
     return combined;
 }
 
+#if (GMIME_MAJOR_VERSION < 3)
 static char *
 _notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
 					   const char *header)
@@ -271,6 +272,39 @@ _notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
 
     return combined;
 }
+#else
+static char *
+_notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
+					   const char *header)
+{
+    char *combined = NULL;
+    GMimeHeaderList *headers;
+
+    headers = g_mime_object_get_header_list (GMIME_OBJECT (message->message));
+    if (! headers)
+	return NULL;
+
+
+    for (int i=0; i < g_mime_header_list_get_count (headers); i++) {
+	const char *value;
+	GMimeHeader *g_header = g_mime_header_list_get_header_at (headers, i);
+
+	if (strcasecmp (g_mime_header_get_name (g_header), header) != 0)
+	    continue;
+
+	/* GMime retains ownership of value, we hope */
+	value = g_mime_header_get_value (g_header);
+
+	combined = _extend_header (combined, value);
+    }
+
+    /* Return empty string for non-existing headers. */
+    if (! combined)
+	combined = g_strdup ("");
+
+    return combined;
+}
+#endif
 
 const char *
 _notmuch_message_file_get_header (notmuch_message_file_t *message,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 21/23] lib: paper over allocation difference
  2017-06-03 17:47 David Bremner
                   ` (19 preceding siblings ...)
  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 ` 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
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

In gmime 3.0 this function is "transfer none", so no deallocation is
needed (or permitted)
---
 lib/index.cc       | 2 +-
 util/gmime-extra.h | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/index.cc b/lib/index.cc
index d2472896..70607069 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -450,7 +450,7 @@ _notmuch_message_index_file (notmuch_message_t *message,
     addresses = g_mime_message_get_from (mime_message);
     if (addresses) {
 	_index_address_list (message, "from", addresses);
-	g_object_unref (addresses);
+	g_mime_2_6_unref (addresses);
     }
 
     addresses = g_mime_message_get_all_recipients (mime_message);
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index d744c4e4..7688129a 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -13,6 +13,8 @@ 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
 
+#define g_mime_2_6_unref(obj) g_object_unref (obj)
+
 #else /* GMime >= 3.0 */
 typedef GMimeAddressType GMimeRecipientType;
 
@@ -51,6 +53,7 @@ typedef GMimeTrust GMimeCertificateTrust;
 #define GMIME_CERTIFICATE_TRUST_FULLY GMIME_TRUST_FULL
 #define GMIME_CERTIFICATE_TRUST_ULTIMATE GMIME_TRUST_ULTIMATE
 
+#define g_mime_2_6_unref(obj) /*ignore*/
 #endif
 
 /**
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 22/23] cli: make keyid from fingerprint in gmime 3.0
  2017-06-03 17:47 David Bremner
                   ` (20 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 21/23] lib: paper over allocation difference David Bremner
@ 2017-06-03 17:47 ` David Bremner
  2017-06-03 17:47 ` [PATCH 23/23] cli: wrap getting uid David Bremner
  22 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

The "key_id" field seems to used for userid in gmime-3.0, while the
keyid is dropped in the fingerprint field if the full fingerprint is
not available.
---
 notmuch-show.c     |  2 +-
 util/gmime-extra.c | 10 ++++++++++
 util/gmime-extra.h |  5 +++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 3234ab95..b1f58428 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -461,7 +461,7 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
 		}
 	    }
 	} else if (certificate) {
-	    const char *key_id = g_mime_certificate_get_key_id (certificate);
+	    const char *key_id = g_mime_certificate_get_fpr16 (certificate);
 	    if (key_id) {
 		sp->map_key (sp, "keyid");
 		sp->string (sp, key_id);
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
index 3c50a293..ed53e0ab 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -1,4 +1,5 @@
 #include "gmime-extra.h"
+#include <string.h>
 
 GMimeStream *
 g_mime_stream_stdout_new()
@@ -106,6 +107,15 @@ g_mime_utils_header_decode_date_unix (const char *date) {
 
 #else /* GMime >= 3.0 */
 
+const char*
+g_mime_certificate_get_fpr16 (GMimeCertificate *cert) {
+    const char *fpr = g_mime_certificate_get_fingerprint (cert);
+    if (!fpr || strlen (fpr) < 16)
+	return fpr;
+
+    return fpr + (strlen (fpr) - 16);
+}
+
 char *
 g_mime_message_get_address_string (GMimeMessage *message, GMimeAddressType type)
 {
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 7688129a..4407be33 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -14,6 +14,7 @@ GMimeStream *g_mime_stream_stdout_new(void);
 #define GMIME_ADDRESS_TYPE_BCC GMIME_RECIPIENT_TYPE_BCC
 
 #define g_mime_2_6_unref(obj) g_object_unref (obj)
+#define g_mime_certificate_get_fpr16(cert) g_mime_certificate_get_key_id (cert)
 
 #else /* GMime >= 3.0 */
 typedef GMimeAddressType GMimeRecipientType;
@@ -57,6 +58,10 @@ typedef GMimeTrust GMimeCertificateTrust;
 #endif
 
 /**
+ * Get last 16 hex digits of fingerprint ("keyid")
+ */
+const char *g_mime_certificate_get_fpr16 (GMimeCertificate *cert);
+/**
  * Return the contents of the appropriate address header as a string
  * Should be freed using g_free
  */
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 23/23] cli: wrap getting uid
  2017-06-03 17:47 David Bremner
                   ` (21 preceding siblings ...)
  2017-06-03 17:47 ` [PATCH 22/23] cli: make keyid from fingerprint in gmime 3.0 David Bremner
@ 2017-06-03 17:47 ` 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
  22 siblings, 1 reply; 44+ messages in thread
From: David Bremner @ 2017-06-03 17:47 UTC (permalink / raw)
  To: notmuch, notmuch

Apparently it moved from "name" to "key_id" in gmime-3.0
---
 notmuch-show.c     | 2 +-
 util/gmime-extra.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index b1f58428..4407a8cb 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -453,7 +453,7 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
 	    /* note that gmime is using the term "trust" here, which
 	     * is WRONG.  It's actually user id "validity". */
 	    if (certificate) {
-		const char *name = g_mime_certificate_get_name (certificate);
+		const char *name = g_mime_certificate_get_uid (certificate);
 		GMimeCertificateTrust trust = g_mime_certificate_get_trust (certificate);
 		if (name && (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE)) {
 		    sp->map_key (sp, "userid");
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 4407be33..cf8d9a2d 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -15,11 +15,12 @@ GMimeStream *g_mime_stream_stdout_new(void);
 
 #define g_mime_2_6_unref(obj) g_object_unref (obj)
 #define g_mime_certificate_get_fpr16(cert) g_mime_certificate_get_key_id (cert)
-
+#define g_mime_certificate_get_uid(cert) g_mime_certificate_get_name (cert);
 #else /* GMime >= 3.0 */
 typedef GMimeAddressType GMimeRecipientType;
 
 #define GMIME_ENABLE_RFC_2047_WORKAROUNDS 0xdeadbeef
+#define g_mime_certificate_get_uid(cert) g_mime_certificate_get_key_id (cert);
 #define g_mime_content_type_to_string(c) g_mime_content_type_get_mime_type (c)
 #define g_mime_filter_crlf_new(encode,dots) g_mime_filter_dos2unix_new (FALSE)
 #define g_mime_gpg_context_new(func,path) g_mime_gpg_context_new ()
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [PATCH 03/23] cli: implement structured output version 4
  2017-06-03 17:47 ` [PATCH 03/23] cli: implement structured output " David Bremner
@ 2017-07-04 11:37   ` David Bremner
  0 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-07-04 11:37 UTC (permalink / raw)
  To: notmuch, notmuch

David Bremner <david@tethera.net> writes:

> Since the error field is unused by the emacs front end, no changes are
> needed other than bumping the format version number.
>
> As it is, this is a bit overengineered, but it will reduce duplication
> when we support gmime 3.0

pushed the first 3 patches.

I know I said I was waiting for more review on this series, I guess I
mean the second half of the series. The first half is mostly test suite
stuff.

d

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 09/23] test/crypto: add test for corrupted signatures
  2017-06-03 17:47 ` [PATCH 09/23] test/crypto: add test for corrupted signatures David Bremner
@ 2017-07-05 11:03   ` David Bremner
  0 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-07-05 11:03 UTC (permalink / raw)
  To: notmuch, notmuch

[-- Attachment #1: Type: text/plain, Size: 355 bytes --]

David Bremner <david@tethera.net> writes:

> Have an empty list of signatures is not the nicest mechanism to signal
> complete failure to verify, but it's the one we currently have.

merged patches 4,5,6, 8&9 to master.

I'm nerving myself up to push 7 (it's a bit traumatic to see BROKEN
messages from crypto tests), and I think I'll skip 10 for now.

d

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 658 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 07/23] test/crypto: mark extra space in userid as a bug in gmime-2.6
  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
  0 siblings, 1 reply; 44+ messages in thread
From: Tomi Ollila @ 2017-07-05 20:26 UTC (permalink / raw)
  To: David Bremner, notmuch, notmuch

On Sat, Jun 03 2017, David Bremner wrote:

> I can't see the space in the output of gpg -K --with-colons
> ---
>  test/T350-crypto.sh | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
> index 0753acf3..720a2225 100755
> --- a/test/T350-crypto.sh
> +++ b/test/T350-crypto.sh
> @@ -69,6 +69,7 @@ test_expect_equal_json \
>      "$expected"
>  
>  test_begin_subtest "signature verification with full owner trust"
> +test_subtest_broken_gmime_2
>  # give the key full owner trust
>  echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
>  gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
> @@ -90,7 +91,7 @@ expected='[[[{"id": "XXXXX",
>   "sigstatus": [{"status": "good",
>   "fingerprint": "'$FINGERPRINT'",
>   "created": 946728000,
> - "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
> + "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],


You could add a variable which is set to ' ' when gmime_2 is used and ''
when gmime_3 is used and insert that just like '"$FINGERPRINT"' is added
-- that change would not need to live there forever -- just couple of
years until we drop support for gmime_2... ( ;) )

e.e. "userid: "'"$GM2SPC"'Notmuch Test Suite..."

(if nimed as such, T350-crypto.sh -local variable)

Tomi

>   "content-type": "multipart/signed",
>   "content": [{"id": 2,
>   "content-type": "text/plain",
> @@ -276,6 +277,7 @@ test_expect_success \
>      "(mml-secure-message-sign-encrypt)"'
>  
>  test_begin_subtest "decryption + signature verification"
> +test_subtest_broken_gmime_2
>  output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
>      | notmuch_json_show_sanitize \
>      | sed -e 's|"created": [1234567890]*|"created": 946728000|')
> @@ -295,7 +297,7 @@ expected='[[[{"id": "XXXXX",
>   "sigstatus": [{"status": "good",
>   "fingerprint": "'$FINGERPRINT'",
>   "created": 946728000,
> - "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
> + "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
>   "content-type": "multipart/encrypted",
>   "content": [{"id": 2,
>   "content-type": "application/pgp-encrypted",
> -- 
> 2.11.0
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 07/23] test/crypto: mark extra space in userid as a bug in gmime-2.6
  2017-07-05 20:26   ` Tomi Ollila
@ 2017-07-06 14:15     ` Daniel Kahn Gillmor
  0 siblings, 0 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-06 14:15 UTC (permalink / raw)
  To: Tomi Ollila, David Bremner, notmuch, notmuch

[-- Attachment #1: Type: text/plain, Size: 776 bytes --]

On Wed 2017-07-05 23:26:18 +0300, Tomi Ollila wrote:
> On Sat, Jun 03 2017, David Bremner wrote:
>
>> I can't see the space in the output of gpg -K --with-colons
 [...]
> You could add a variable which is set to ' ' when gmime_2 is used and ''
> when gmime_3 is used and insert that just like '"$FINGERPRINT"' is added
> -- that change would not need to live there forever -- just couple of
> years until we drop support for gmime_2... ( ;) )
>
> e.e. "userid: "'"$GM2SPC"'Notmuch Test Suite..."
>
> (if nimed as such, T350-crypto.sh -local variable)

I think this would be a mistake.  This is clearly a bug in gmime 2.6,
and we should be marking it as such.  the User ID does not have a
leading space (see test/gnupg-secret-key.NOTE for how it was generated).

        --dkg

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR, STATUS} to gmime-3
  2017-06-03 17:47 ` [PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR, STATUS} to gmime-3 David Bremner
@ 2017-07-07 22:18   ` Daniel Kahn Gillmor
  0 siblings, 0 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-07 22:18 UTC (permalink / raw)
  To: David Bremner, notmuch, notmuch

On Sat 2017-06-03 14:47:47 -0300, David Bremner wrote:
> @@ -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[] = {


I think this should be:

 struct key_map_struct key_map

rather than an anonymous struct.

       --dkg

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH 1/3] config: deprecate/drop crypto.gpg_path under gmime 2.6/3.0
  2017-06-03 17:47 ` [PATCH 23/23] cli: wrap getting uid David Bremner
@ 2017-07-14 13:12   ` Daniel Kahn Gillmor
  2017-07-14 13:12     ` [PATCH 2/3] clean up use of constants in g_mime_multipart_ wrappers Daniel Kahn Gillmor
                       ` (2 more replies)
  0 siblings, 3 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-14 13:12 UTC (permalink / raw)
  To: Notmuch Mail

gmime 3.0 no longer offers a means to set the path for gpg.

Users can set $PATH anyway if they want to pick a
differently-installed gpg (e.g. /usr/local/bin/gpg), so this isn't
much of a reduction in functionality.

The one main difference is for people who have tried to use "gpg2" to
make use of gpg 2.1, but that isn't usefully co-installable anyway.
---
 doc/man1/notmuch-config.rst |  4 +++-
 notmuch-client.h            |  4 ++++
 notmuch-config.c            | 20 +++++++++++++++++---
 notmuch-reply.c             |  2 ++
 notmuch-show.c              |  2 ++
 test/T030-config.sh         |  9 +++++++--
 test/T040-setup.sh          |  8 +++++++-
 7 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index 7483b75f..6a51e64f 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -128,7 +128,9 @@ The available configuration items are described below.
     **crypto.gpg_path**
 
         Name (or full path) of gpg binary to use in verification and
-        decryption of PGP/MIME messages.
+        decryption of PGP/MIME messages.  NOTE: This configuration
+        item is deprecated, and will be ignored if notmuch is built
+        against GMime 3.0 or later.
 
         Default: ``gpg``.
 
diff --git a/notmuch-client.h b/notmuch-client.h
index 77b34184..11aefbb4 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -76,7 +76,9 @@ typedef struct notmuch_crypto {
     notmuch_crypto_context_t* pkcs7ctx;
     notmuch_bool_t verify;
     notmuch_bool_t decrypt;
+#if (GMIME_MAJOR_VERSION < 3)
     const char *gpgpath;
+#endif
 } notmuch_crypto_t;
 
 typedef struct notmuch_show_params {
@@ -289,12 +291,14 @@ void
 notmuch_config_set_database_path (notmuch_config_t *config,
 				  const char *database_path);
 
+#if (GMIME_MAJOR_VERSION < 3)
 const char *
 notmuch_config_get_crypto_gpg_path (notmuch_config_t *config);
 
 void
 notmuch_config_set_crypto_gpg_path (notmuch_config_t *config,
 				  const char *gpg_path);
+#endif
 
 const char *
 notmuch_config_get_user_name (notmuch_config_t *config);
diff --git a/notmuch-config.c b/notmuch-config.c
index e4aaef61..cb9529b9 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -104,10 +104,20 @@ static const char search_config_comment[] =
 static const char crypto_config_comment[] =
     " Cryptography related configuration\n"
     "\n"
-    " The following option is supported here:\n"
+#if (GMIME_MAJOR_VERSION < 3)
+    " The following *deprecated* option is currently supported:\n"
     "\n"
     "\tgpg_path\n"
-    "\t\tbinary name or full path to invoke gpg.\n";
+    "\t\tbinary name or full path to invoke gpg.\n"
+    "\t\tNOTE: In a future build, this option will be ignored.\n"
+#else
+    " The following old option is now ignored:\n"
+    "\n"
+    "\tgpgpath\n"
+    "\t\tThis option was used by older builds of notmuch to choose\n"
+    "\t\tthe version of gpg to use.\n"
+#endif
+    "\t\tSetting $PATH is a better approach.\n";
 
 struct _notmuch_config {
     char *filename;
@@ -460,10 +470,12 @@ notmuch_config_open (void *ctx,
 	g_error_free (error);
     }
 
+#if (GMIME_MAJOR_VERSION < 3)
     if (notmuch_config_get_crypto_gpg_path (config) == NULL) {
 	notmuch_config_set_crypto_gpg_path (config, "gpg");
     }
-    
+#endif
+
     /* Whenever we know of configuration sections that don't appear in
      * the configuration file, we add some comments to help the user
      * understand what can be done. */
@@ -752,6 +764,7 @@ notmuch_config_set_search_exclude_tags (notmuch_config_t *config,
 		      &(config->search_exclude_tags));
 }
 
+#if (GMIME_MAJOR_VERSION < 3)
 const char *
 notmuch_config_get_crypto_gpg_path (notmuch_config_t *config)
 {
@@ -764,6 +777,7 @@ notmuch_config_set_crypto_gpg_path (notmuch_config_t *config,
 {
     _config_set (config, &config->crypto_gpg_path, "crypto", "gpg_path", gpg_path);
 }
+#endif
 
 
 /* Given a configuration item of the form <group>.<key> return the
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 4c1dd560..b4a55362 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -740,7 +740,9 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
 	return EXIT_FAILURE;
     }
 
+#if (GMIME_MAJOR_VERSION < 3)
     params.crypto.gpgpath = notmuch_config_get_crypto_gpg_path (config);
+#endif
 
     if (notmuch_database_open (notmuch_config_get_database_path (config),
 			       NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
diff --git a/notmuch-show.c b/notmuch-show.c
index 71799c75..6c135278 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1199,7 +1199,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	return EXIT_FAILURE;
     }
 
+#if (GMIME_MAJOR_VERSION < 3)
     params.crypto.gpgpath = notmuch_config_get_crypto_gpg_path (config);
+#endif
 
     if (notmuch_database_open (notmuch_config_get_database_path (config),
 			       NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
diff --git a/test/T030-config.sh b/test/T030-config.sh
index 0915abdb..2cee6ed0 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -44,6 +44,12 @@ test_expect_equal "$(notmuch config get foo.nonexistent)" ""
 
 test_begin_subtest "List all items"
 notmuch config list 2>&1 | notmuch_config_sanitize > OUTPUT
+
+if [ "${NOTMUCH_GMIME_MAJOR}" -lt 3 ]; then
+    config_gpg_path="crypto.gpg_path=gpg
+"
+fi
+
 cat <<EOF > EXPECTED
 Error opening database at MAIL_DIR/.notmuch: No such file or directory
 database.path=MAIL_DIR
@@ -54,8 +60,7 @@ new.tags=unread;inbox;
 new.ignore=
 search.exclude_tags=
 maildir.synchronize_flags=true
-crypto.gpg_path=gpg
-foo.string=this is another string value
+${config_gpg_path}foo.string=this is another string value
 foo.list=this;is another;list value;
 built_with.compact=something
 built_with.field_processor=something
diff --git a/test/T040-setup.sh b/test/T040-setup.sh
index 021f2d0b..8e0e3b13 100755
--- a/test/T040-setup.sh
+++ b/test/T040-setup.sh
@@ -19,6 +19,12 @@ another.suite@example.com
 foo bar
 baz
 EOF
+
+if [ "${NOTMUCH_GMIME_MAJOR}" -lt 3 ]; then
+    config_gpg_path="crypto.gpg_path=gpg
+"
+fi
+
 output=$(notmuch --config=new-notmuch-config config list | notmuch_built_with_sanitize)
 test_expect_equal "$output" "\
 database.path=/path/to/maildir
@@ -29,7 +35,7 @@ new.tags=foo;bar;
 new.ignore=
 search.exclude_tags=baz;
 maildir.synchronize_flags=true
-crypto.gpg_path=gpg
+"${config_gpg_path}"\
 built_with.compact=something
 built_with.field_processor=something
 built_with.retry_lock=something"
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 2/3] clean up use of constants in g_mime_multipart_ wrappers
  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     ` 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-14 13:19     ` [PATCH 1/3] config: deprecate/drop crypto.gpg_path under gmime 2.6/3.0 Daniel Kahn Gillmor
  2 siblings, 0 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-14 13:12 UTC (permalink / raw)
  To: Notmuch Mail

When compiling as C code (instead of C++) against gmime 3.0, gcc gives
errors like the following:

    error: invalid conversion from ‘int’ to ‘GMimeDecryptFlags’ [-fpermissive]

so use explicit *_NONE values instead.
---
 util/gmime-extra.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index cf8d9a2d..8096dbe3 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -29,8 +29,8 @@ typedef GMimeAddressType GMimeRecipientType;
 #define g_mime_init(flags) g_mime_init()
 #define g_mime_message_add_recipient(m,t,n,a) g_mime_message_add_mailbox (m,t,n,a)
 #define g_mime_message_set_subject(m,s) g_mime_message_set_subject(m,s,NULL)
-#define g_mime_multipart_encrypted_decrypt(mpe,ctx,out,err) g_mime_multipart_encrypted_decrypt(mpe, 0, NULL, out, err)
-#define g_mime_multipart_signed_verify(mps,ctx,err) g_mime_multipart_signed_verify(mps, 0, err)
+#define g_mime_multipart_encrypted_decrypt(mpe,ctx,out,err) g_mime_multipart_encrypted_decrypt(mpe, GMIME_DECRYPT_NONE, NULL, out, err)
+#define g_mime_multipart_signed_verify(mps,ctx,err) g_mime_multipart_signed_verify(mps, GMIME_ENCRYPT_NONE, err)
 #define g_mime_object_write_to_stream(o,s) g_mime_object_write_to_stream (o,NULL,s)
 #define g_mime_object_set_header(o,h,v) g_mime_object_set_header (o,h,v,NULL)
 #define g_mime_parser_construct_message(p) g_mime_parser_construct_message (p, g_mime_parser_options_get_default ())
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 3/3] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3.0
  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     ` 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-14 13:19     ` [PATCH 1/3] config: deprecate/drop crypto.gpg_path under gmime 2.6/3.0 Daniel Kahn Gillmor
  2 siblings, 2 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-14 13:12 UTC (permalink / raw)
  To: Notmuch Mail

gmime 3.0 knows how to select the correct GMimeCryptoContext
automatically, so a bunch of the code in notmuch can be dropped in
that case.

The #ifdef removal of the crypto stuff is better than #define aliasing
in gmime-extra.h for this stuff.  When built against gmime 3.0:

 * it reduces compiled code,
 * it avoids initializing unused gpgme contexts, and
 * it avoids compiled-time warnings about passing unnecessary
   notmuch_cryptoctx_t*s.
---
 crypto.c         |  2 ++
 mime-node.c      | 28 ++++++++++++++++++++++++----
 notmuch-client.h |  8 ++++++--
 notmuch-reply.c  |  2 ++
 notmuch-show.c   |  2 ++
 5 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/crypto.c b/crypto.c
index 3e8ce7ca..ab1fb77a 100644
--- a/crypto.c
+++ b/crypto.c
@@ -20,6 +20,7 @@
 
 #include "notmuch-client.h"
 
+#if (GMIME_MAJOR_VERSION < 3)
 /* Create a GPG context (GMime 2.6) */
 static notmuch_crypto_context_t *
 create_gpg_context (notmuch_crypto_t *crypto)
@@ -132,3 +133,4 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto)
 
     return 0;
 }
+#endif
diff --git a/mime-node.c b/mime-node.c
index f719422e..226e9c2f 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -150,8 +150,11 @@ set_signature_list_destructor (mime_node_t *node)
 
 /* Verify a signed mime node (GMime 2.6) */
 static void
-node_verify (mime_node_t *node, GMimeObject *part,
-	     notmuch_crypto_context_t *cryptoctx)
+node_verify (mime_node_t *node, GMimeObject *part
+#if (GMIME_MAJOR_VERSION < 3)
+	     , notmuch_crypto_context_t *cryptoctx
+#endif
+    )
 {
     GError *err = NULL;
 
@@ -171,8 +174,11 @@ node_verify (mime_node_t *node, GMimeObject *part,
 
 /* Decrypt and optionally verify an encrypted mime node (GMime 2.6) */
 static void
-node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
-			 notmuch_crypto_context_t *cryptoctx)
+node_decrypt_and_verify (mime_node_t *node, GMimeObject *part
+#if (GMIME_MAJOR_VERSION < 3)
+	     , notmuch_crypto_context_t *cryptoctx
+#endif
+    )
 {
     GError *err = NULL;
     GMimeDecryptResult *decrypt_result = NULL;
@@ -207,7 +213,11 @@ static mime_node_t *
 _mime_node_create (mime_node_t *parent, GMimeObject *part)
 {
     mime_node_t *node = talloc_zero (parent, mime_node_t);
+#if (GMIME_MAJOR_VERSION < 3)
     notmuch_crypto_context_t *cryptoctx = NULL;
+#else
+    notmuch_bool_t cryptoctx = TRUE;
+#endif
 
     /* Set basic node properties */
     node->part = part;
@@ -240,12 +250,14 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	return NULL;
     }
 
+#if (GMIME_MAJOR_VERSION < 3)
     if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt)
 	|| (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {
 	GMimeContentType *content_type = g_mime_object_get_content_type (part);
 	const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");
 	cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);
     }
+#endif
 
     /* Handle PGP/MIME parts */
     if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt && cryptoctx) {
@@ -255,7 +267,11 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 		     "message (must be exactly 2)\n",
 		     node->nchildren);
 	} else {
+#if (GMIME_MAJOR_VERSION < 3)
 	    node_decrypt_and_verify (node, part, cryptoctx);
+#else
+	    node_decrypt_and_verify (node, part);
+#endif
 	}
     } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify && cryptoctx) {
 	if (node->nchildren != 2) {
@@ -264,7 +280,11 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 		     "(must be exactly 2)\n",
 		     node->nchildren);
 	} else {
+#if (GMIME_MAJOR_VERSION < 3)
 	    node_verify (node, part, cryptoctx);
+#else
+	    node_verify (node, part);
+#endif
 	}
     }
 
diff --git a/notmuch-client.h b/notmuch-client.h
index 11aefbb4..c520089e 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -31,7 +31,9 @@
 
 #include "gmime-extra.h"
 
+#if (GMIME_MAJOR_VERSION < 3)
 typedef GMimeCryptoContext notmuch_crypto_context_t;
+#endif
 /* This is automatically included only since gmime 2.6.10 */
 #include <gmime/gmime-pkcs7-context.h>
 
@@ -72,11 +74,11 @@ typedef struct notmuch_show_format {
 } notmuch_show_format_t;
 
 typedef struct notmuch_crypto {
-    notmuch_crypto_context_t* gpgctx;
-    notmuch_crypto_context_t* pkcs7ctx;
     notmuch_bool_t verify;
     notmuch_bool_t decrypt;
 #if (GMIME_MAJOR_VERSION < 3)
+    notmuch_crypto_context_t* gpgctx;
+    notmuch_crypto_context_t* pkcs7ctx;
     const char *gpgpath;
 #endif
 } notmuch_crypto_t;
@@ -180,11 +182,13 @@ typedef struct _notmuch_config notmuch_config_t;
 void
 notmuch_exit_if_unsupported_format (void);
 
+#if (GMIME_MAJOR_VERSION < 3)
 notmuch_crypto_context_t *
 notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);
 
 int
 notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
+#endif
 
 int
 notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]);
diff --git a/notmuch-reply.c b/notmuch-reply.c
index b4a55362..69c26359 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -759,7 +759,9 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
     if (do_reply (config, query, &params, format, reply_all) != 0)
 	return EXIT_FAILURE;
 
+#if (GMIME_MAJOR_VERSION < 3)
     notmuch_crypto_cleanup (&params.crypto);
+#endif
     notmuch_query_destroy (query);
     notmuch_database_destroy (notmuch);
 
diff --git a/notmuch-show.c b/notmuch-show.c
index 6c135278..626bca80 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1257,7 +1257,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     g_mime_stream_flush (params.out_stream);
     g_object_unref (params.out_stream);
 
+#if (GMIME_MAJOR_VERSION < 3)
     notmuch_crypto_cleanup (&params.crypto);
+#endif
     notmuch_query_destroy (query);
     notmuch_database_destroy (notmuch);
 
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [PATCH 1/3] config: deprecate/drop crypto.gpg_path under gmime 2.6/3.0
  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-14 13:19     ` Daniel Kahn Gillmor
  2 siblings, 0 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-14 13:19 UTC (permalink / raw)
  To: Notmuch Mail

[-- Attachment #1: Type: text/plain, Size: 846 bytes --]

On Fri 2017-07-14 15:12:00 +0200, Daniel Kahn Gillmor wrote:
> gmime 3.0 no longer offers a means to set the path for gpg.
>
> Users can set $PATH anyway if they want to pick a
> differently-installed gpg (e.g. /usr/local/bin/gpg), so this isn't
> much of a reduction in functionality.

see also:

  https://github.com/jstedfast/gmime/pull/7

> The one main difference is for people who have tried to use "gpg2" to
> make use of gpg 2.1, but that isn't usefully co-installable anyway.

I think the recommendation for those folks would be something like:

    mkdir -p ~/bin
    ln -s $(which gpg2) ~/bin/gpg
    PATH=~/bin:$PATH

though i'm inclined to just suggest that people don't do the "gpg2"
co-installable thing at all, since gpg 1.4 and 2.1 diverge on both
public keyrings and secret keyrings, and 2.0 is EOL in < 6 months.

       --dkg

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH 3/3] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3.0
  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
  1 sibling, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-07-15 11:55 UTC (permalink / raw)
  To: Daniel Kahn Gillmor, Notmuch Mail

Daniel Kahn Gillmor <dkg@fifthhorseman.net> writes:

> gmime 3.0 knows how to select the correct GMimeCryptoContext
> automatically, so a bunch of the code in notmuch can be dropped in
> that case.
>
> The #ifdef removal of the crypto stuff is better than #define aliasing
> in gmime-extra.h for this stuff.  When built against gmime 3.0:
>
>  * it reduces compiled code,
>  * it avoids initializing unused gpgme contexts, and
>  * it avoids compiled-time warnings about passing unnecessary
>    notmuch_cryptoctx_t*s.
>  /* Decrypt and optionally verify an encrypted mime node (GMime 2.6) */
>  static void
> -node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
> -			 notmuch_crypto_context_t *cryptoctx)
> +node_decrypt_and_verify (mime_node_t *node, GMimeObject *part
> +#if (GMIME_MAJOR_VERSION < 3)
> +	     , notmuch_crypto_context_t *cryptoctx
> +#endif
> +    )

The amount of ifdef-ery here rises to a level that we usually try to
avoid. Overall I need some more time to think about different ways to do
this, and see if any of them are better.  I haven't coded it up yet, but
I'm think a macro that expands to unused() for gmime-3.0 might be a
cleaner solution than some of the inline ifdefs here.

d

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH 1/4] cli/crypto: treat failure to create a crypto context as fatal.
  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       ` David Bremner
  2017-07-15 18:57         ` [PATCH 2/4] cli/crypto: eliminated compiler warnings about unused arguments David Bremner
                           ` (2 more replies)
  1 sibling, 3 replies; 44+ messages in thread
From: David Bremner @ 2017-07-15 18:57 UTC (permalink / raw)
  To: Daniel Kahn Gillmor, Notmuch Mail

Silently ignoring signed/encrypted parts seems like the wrong idea,
and it also complicates future gmime-3.0 compatibility changes.
---
 mime-node.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mime-node.c b/mime-node.c
index f719422e..7363e222 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -245,10 +245,12 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	GMimeContentType *content_type = g_mime_object_get_content_type (part);
 	const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");
 	cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);
+	if (!cryptoctx)
+	    return NULL;
     }
 
     /* Handle PGP/MIME parts */
-    if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt && cryptoctx) {
+    if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) {
 	if (node->nchildren != 2) {
 	    /* this violates RFC 3156 section 4, so we won't bother with it. */
 	    fprintf (stderr, "Error: %d part(s) for a multipart/encrypted "
@@ -257,7 +259,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	} else {
 	    node_decrypt_and_verify (node, part, cryptoctx);
 	}
-    } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify && cryptoctx) {
+    } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify) {
 	if (node->nchildren != 2) {
 	    /* this violates RFC 3156 section 5, so we won't bother with it. */
 	    fprintf (stderr, "Error: %d part(s) for a multipart/signed message "
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 2/4] cli/crypto: eliminated compiler warnings about unused arguments
  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         ` David Bremner
  2017-07-15 18:57         ` [PATCH 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3 David Bremner
  2017-07-15 18:57         ` [PATCH 4/4] crypto: clean up unused definitions in gmime 3.0 David Bremner
  2 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-07-15 18:57 UTC (permalink / raw)
  To: Daniel Kahn Gillmor, Notmuch Mail

These are due to (excessively?) fancy macro definitions in gmime-extra.h
---
 mime-node.c        | 4 ++--
 util/gmime-extra.h | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mime-node.c b/mime-node.c
index 7363e222..bc41b752 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -151,7 +151,7 @@ set_signature_list_destructor (mime_node_t *node)
 /* Verify a signed mime node (GMime 2.6) */
 static void
 node_verify (mime_node_t *node, GMimeObject *part,
-	     notmuch_crypto_context_t *cryptoctx)
+	     g_mime_3_unused(notmuch_crypto_context_t *cryptoctx))
 {
     GError *err = NULL;
 
@@ -172,7 +172,7 @@ node_verify (mime_node_t *node, GMimeObject *part,
 /* Decrypt and optionally verify an encrypted mime node (GMime 2.6) */
 static void
 node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
-			 notmuch_crypto_context_t *cryptoctx)
+			 g_mime_3_unused(notmuch_crypto_context_t *cryptoctx))
 {
     GError *err = NULL;
     GMimeDecryptResult *decrypt_result = NULL;
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 8096dbe3..de275bc1 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -14,6 +14,7 @@ GMimeStream *g_mime_stream_stdout_new(void);
 #define GMIME_ADDRESS_TYPE_BCC GMIME_RECIPIENT_TYPE_BCC
 
 #define g_mime_2_6_unref(obj) g_object_unref (obj)
+#define g_mime_3_unused(arg) arg
 #define g_mime_certificate_get_fpr16(cert) g_mime_certificate_get_key_id (cert)
 #define g_mime_certificate_get_uid(cert) g_mime_certificate_get_name (cert);
 #else /* GMime >= 3.0 */
@@ -56,6 +57,7 @@ typedef GMimeTrust GMimeCertificateTrust;
 #define GMIME_CERTIFICATE_TRUST_ULTIMATE GMIME_TRUST_ULTIMATE
 
 #define g_mime_2_6_unref(obj) /*ignore*/
+#define g_mime_3_unused(arg) unused(arg)
 #endif
 
 /**
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3
  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         ` David Bremner
  2017-07-15 22:45           ` Daniel Kahn Gillmor
  2017-07-15 18:57         ` [PATCH 4/4] crypto: clean up unused definitions in gmime 3.0 David Bremner
  2 siblings, 1 reply; 44+ messages in thread
From: David Bremner @ 2017-07-15 18:57 UTC (permalink / raw)
  To: Daniel Kahn Gillmor, Notmuch Mail

gmime 3.0 knows how to select the correct GMimeCryptoContext
automatically, so a bunch of the code in notmuch can be dropped in
that case.

The #ifdef removal of the crypto stuff is better than #define aliasing
in gmime-extra.h for this stuff.  When built against gmime 3.0:

    * it reduces compiled code, and
    * it avoids initializing unused gpgme contexts

(based on a patch from dkg)
---
 crypto.c        | 3 ++-
 mime-node.c     | 2 ++
 notmuch-reply.c | 2 ++
 notmuch-show.c  | 2 ++
 4 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/crypto.c b/crypto.c
index 3e8ce7ca..05c05a47 100644
--- a/crypto.c
+++ b/crypto.c
@@ -19,7 +19,7 @@
  */
 
 #include "notmuch-client.h"
-
+#if (GMIME_MAJOR_VERSION < 3)
 /* Create a GPG context (GMime 2.6) */
 static notmuch_crypto_context_t *
 create_gpg_context (notmuch_crypto_t *crypto)
@@ -132,3 +132,4 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto)
 
     return 0;
 }
+#endif
diff --git a/mime-node.c b/mime-node.c
index bc41b752..bb0870d0 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -240,6 +240,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	return NULL;
     }
 
+#if (GMIME_MAJOR_VERSION < 3)
     if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt)
 	|| (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {
 	GMimeContentType *content_type = g_mime_object_get_content_type (part);
@@ -248,6 +249,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	if (!cryptoctx)
 	    return NULL;
     }
+#endif
 
     /* Handle PGP/MIME parts */
     if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) {
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 40201b80..4df29b82 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -759,7 +759,9 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
     if (do_reply (config, query, &params, format, reply_all) != 0)
 	return EXIT_FAILURE;
 
+#if (GMIME_MAJOR_VERSION < 3)
     notmuch_crypto_cleanup (&params.crypto);
+#endif
     notmuch_query_destroy (query);
     notmuch_database_destroy (notmuch);
 
diff --git a/notmuch-show.c b/notmuch-show.c
index 74e77249..4feba07b 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1241,7 +1241,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     g_mime_stream_flush (params.out_stream);
     g_object_unref (params.out_stream);
 
+#if (GMIME_MAJOR_VERSION < 3)
     notmuch_crypto_cleanup (&params.crypto);
+#endif
     notmuch_query_destroy (query);
     notmuch_database_destroy (notmuch);
 
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH 4/4] crypto: clean up unused definitions in gmime 3.0
  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 18:57         ` David Bremner
  2 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-07-15 18:57 UTC (permalink / raw)
  To: Daniel Kahn Gillmor, Notmuch Mail

based on the same patch from dkg as the previous commit.
---
 notmuch-client.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 11aefbb4..b2692166 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -72,11 +72,11 @@ typedef struct notmuch_show_format {
 } notmuch_show_format_t;
 
 typedef struct notmuch_crypto {
-    notmuch_crypto_context_t* gpgctx;
-    notmuch_crypto_context_t* pkcs7ctx;
     notmuch_bool_t verify;
     notmuch_bool_t decrypt;
 #if (GMIME_MAJOR_VERSION < 3)
+    notmuch_crypto_context_t* gpgctx;
+    notmuch_crypto_context_t* pkcs7ctx;
     const char *gpgpath;
 #endif
 } notmuch_crypto_t;
@@ -180,11 +180,13 @@ typedef struct _notmuch_config notmuch_config_t;
 void
 notmuch_exit_if_unsupported_format (void);
 
+#if (GMIME_MAJOR_VERSION <3)
 notmuch_crypto_context_t *
 notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);
 
 int
 notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
+#endif
 
 int
 notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]);
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [PATCH 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3
  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
  0 siblings, 1 reply; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-15 22:45 UTC (permalink / raw)
  To: David Bremner, Notmuch Mail

[-- Attachment #1: Type: text/plain, Size: 1450 bytes --]

Thanks for trying to talk me down from my ifdefery, Bremner :)

I think this subseries looks reasonable, though:

On Sat 2017-07-15 15:57:43 -0300, David Bremner wrote:
> diff --git a/notmuch-reply.c b/notmuch-reply.c
> index 40201b80..4df29b82 100644
> --- a/notmuch-reply.c
> +++ b/notmuch-reply.c
> @@ -759,7 +759,9 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
>      if (do_reply (config, query, &params, format, reply_all) != 0)
>  	return EXIT_FAILURE;
>  
> +#if (GMIME_MAJOR_VERSION < 3)
>      notmuch_crypto_cleanup (&params.crypto);
> +#endif
>      notmuch_query_destroy (query);
>      notmuch_database_destroy (notmuch);
>  
> diff --git a/notmuch-show.c b/notmuch-show.c
> index 74e77249..4feba07b 100644
> --- a/notmuch-show.c
> +++ b/notmuch-show.c
> @@ -1241,7 +1241,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
>      g_mime_stream_flush (params.out_stream);
>      g_object_unref (params.out_stream);
>  
> +#if (GMIME_MAJOR_VERSION < 3)
>      notmuch_crypto_cleanup (&params.crypto);
> +#endif
>      notmuch_query_destroy (query);
>      notmuch_database_destroy (notmuch);

If you prefer to reduce #ifdefery, we can also just make
notmuch_crypto_cleanup a no-op in gmime 3.0, right?  that might be
simpler (because maybe something happens in notmuch_crypto that we do
ultimately want to clean up later anyway?)

      --dkg

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v2 1/4] cli/crypto: treat failure to create a crypto context as fatal.
  2017-07-15 22:45           ` Daniel Kahn Gillmor
@ 2017-07-15 23:01             ` Daniel Kahn Gillmor
  2017-07-15 23:01               ` [PATCH v2 2/4] cli/crypto: eliminated compiler warnings about unused arguments Daniel Kahn Gillmor
                                 ` (3 more replies)
  0 siblings, 4 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-15 23:01 UTC (permalink / raw)
  To: Notmuch Mail

From: David Bremner <david@tethera.net>

Silently ignoring signed/encrypted parts seems like the wrong idea,
and it also complicates future gmime-3.0 compatibility changes.
---
 mime-node.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mime-node.c b/mime-node.c
index f719422e..7363e222 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -245,10 +245,12 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	GMimeContentType *content_type = g_mime_object_get_content_type (part);
 	const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");
 	cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);
+	if (!cryptoctx)
+	    return NULL;
     }
 
     /* Handle PGP/MIME parts */
-    if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt && cryptoctx) {
+    if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) {
 	if (node->nchildren != 2) {
 	    /* this violates RFC 3156 section 4, so we won't bother with it. */
 	    fprintf (stderr, "Error: %d part(s) for a multipart/encrypted "
@@ -257,7 +259,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	} else {
 	    node_decrypt_and_verify (node, part, cryptoctx);
 	}
-    } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify && cryptoctx) {
+    } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify) {
 	if (node->nchildren != 2) {
 	    /* this violates RFC 3156 section 5, so we won't bother with it. */
 	    fprintf (stderr, "Error: %d part(s) for a multipart/signed message "
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v2 2/4] cli/crypto: eliminated compiler warnings about unused arguments
  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               ` Daniel Kahn Gillmor
  2017-07-15 23:01               ` [PATCH v2 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3 Daniel Kahn Gillmor
                                 ` (2 subsequent siblings)
  3 siblings, 0 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-15 23:01 UTC (permalink / raw)
  To: Notmuch Mail

From: David Bremner <david@tethera.net>

These are due to (excessively?) fancy macro definitions in gmime-extra.h
---
 mime-node.c        | 4 ++--
 util/gmime-extra.h | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mime-node.c b/mime-node.c
index 7363e222..bc41b752 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -151,7 +151,7 @@ set_signature_list_destructor (mime_node_t *node)
 /* Verify a signed mime node (GMime 2.6) */
 static void
 node_verify (mime_node_t *node, GMimeObject *part,
-	     notmuch_crypto_context_t *cryptoctx)
+	     g_mime_3_unused(notmuch_crypto_context_t *cryptoctx))
 {
     GError *err = NULL;
 
@@ -172,7 +172,7 @@ node_verify (mime_node_t *node, GMimeObject *part,
 /* Decrypt and optionally verify an encrypted mime node (GMime 2.6) */
 static void
 node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
-			 notmuch_crypto_context_t *cryptoctx)
+			 g_mime_3_unused(notmuch_crypto_context_t *cryptoctx))
 {
     GError *err = NULL;
     GMimeDecryptResult *decrypt_result = NULL;
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 8096dbe3..de275bc1 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -14,6 +14,7 @@ GMimeStream *g_mime_stream_stdout_new(void);
 #define GMIME_ADDRESS_TYPE_BCC GMIME_RECIPIENT_TYPE_BCC
 
 #define g_mime_2_6_unref(obj) g_object_unref (obj)
+#define g_mime_3_unused(arg) arg
 #define g_mime_certificate_get_fpr16(cert) g_mime_certificate_get_key_id (cert)
 #define g_mime_certificate_get_uid(cert) g_mime_certificate_get_name (cert);
 #else /* GMime >= 3.0 */
@@ -56,6 +57,7 @@ typedef GMimeTrust GMimeCertificateTrust;
 #define GMIME_CERTIFICATE_TRUST_ULTIMATE GMIME_TRUST_ULTIMATE
 
 #define g_mime_2_6_unref(obj) /*ignore*/
+#define g_mime_3_unused(arg) unused(arg)
 #endif
 
 /**
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v2 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3
  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               ` 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
  3 siblings, 0 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-15 23:01 UTC (permalink / raw)
  To: Notmuch Mail

From: David Bremner <david@tethera.net>

gmime 3.0 knows how to select the correct GMimeCryptoContext
automatically, so a bunch of the code in notmuch can be dropped in
that case.

The #ifdef removal of the crypto stuff is better than #define aliasing
in gmime-extra.h for this stuff.  When built against gmime 3.0:

    * it reduces compiled code, and
    * it avoids initializing unused gpgme contexts

(based on a patch from dkg)
---
 crypto.c    | 8 +++++++-
 mime-node.c | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/crypto.c b/crypto.c
index 3e8ce7ca..cc45b885 100644
--- a/crypto.c
+++ b/crypto.c
@@ -19,7 +19,7 @@
  */
 
 #include "notmuch-client.h"
-
+#if (GMIME_MAJOR_VERSION < 3)
 /* Create a GPG context (GMime 2.6) */
 static notmuch_crypto_context_t *
 create_gpg_context (notmuch_crypto_t *crypto)
@@ -132,3 +132,9 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto)
 
     return 0;
 }
+#else
+int notmuch_crypto_cleanup (unused(notmuch_crypto_t *crypto))
+{
+    return 0;
+}
+#endif
diff --git a/mime-node.c b/mime-node.c
index bc41b752..bb0870d0 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -240,6 +240,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	return NULL;
     }
 
+#if (GMIME_MAJOR_VERSION < 3)
     if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt)
 	|| (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {
 	GMimeContentType *content_type = g_mime_object_get_content_type (part);
@@ -248,6 +249,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
 	if (!cryptoctx)
 	    return NULL;
     }
+#endif
 
     /* Handle PGP/MIME parts */
     if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) {
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v2 4/4] crypto: clean up unused definitions in gmime 3.0
  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               ` 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
  3 siblings, 0 replies; 44+ messages in thread
From: Daniel Kahn Gillmor @ 2017-07-15 23:01 UTC (permalink / raw)
  To: Notmuch Mail

From: David Bremner <david@tethera.net>

based on the same patch from dkg as the previous commit.
---
 notmuch-client.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 11aefbb4..ae37360b 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -72,11 +72,11 @@ typedef struct notmuch_show_format {
 } notmuch_show_format_t;
 
 typedef struct notmuch_crypto {
-    notmuch_crypto_context_t* gpgctx;
-    notmuch_crypto_context_t* pkcs7ctx;
     notmuch_bool_t verify;
     notmuch_bool_t decrypt;
 #if (GMIME_MAJOR_VERSION < 3)
+    notmuch_crypto_context_t* gpgctx;
+    notmuch_crypto_context_t* pkcs7ctx;
     const char *gpgpath;
 #endif
 } notmuch_crypto_t;
@@ -180,8 +180,10 @@ typedef struct _notmuch_config notmuch_config_t;
 void
 notmuch_exit_if_unsupported_format (void);
 
+#if (GMIME_MAJOR_VERSION <3)
 notmuch_crypto_context_t *
 notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);
+#endif
 
 int
 notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [PATCH v2 1/4] cli/crypto: treat failure to create a crypto context as fatal.
  2017-07-15 23:01             ` [PATCH v2 1/4] cli/crypto: treat failure to create a crypto context as fatal Daniel Kahn Gillmor
                                 ` (2 preceding siblings ...)
  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               ` David Bremner
  3 siblings, 0 replies; 44+ messages in thread
From: David Bremner @ 2017-07-16 10:53 UTC (permalink / raw)
  To: Daniel Kahn Gillmor, Notmuch Mail

Daniel Kahn Gillmor <dkg@fifthhorseman.net> writes:

> From: David Bremner <david@tethera.net>
>
> Silently ignoring signed/encrypted parts seems like the wrong idea,
> and it also complicates future gmime-3.0 compatibility changes.

I have merged these 4 patches to master.

d

^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2017-07-16 10:53 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR, STATUS} to gmime-3 David Bremner
2017-07-07 22:18   ` 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

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).