unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] Add --emit-message-id flag to notmuch-insert.
@ 2024-09-10 20:33 Brennan Vincent
  2024-09-11 15:00 ` [PATCH v2] " Brennan Vincent
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Brennan Vincent @ 2024-09-10 20:33 UTC (permalink / raw)
  To: notmuch

---
 doc/man1/notmuch-insert.rst |  5 +++++
 notmuch-insert.c            | 26 +++++++++++++++++++++-----
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst
index e05bd0b5..3848b8f6 100644
--- a/doc/man1/notmuch-insert.rst
+++ b/doc/man1/notmuch-insert.rst
@@ -66,6 +66,11 @@ Supported options for **insert** include
    umask.  By default, delivered mail is only readable by the current
    user.
 
+.. option:: --emit-message-id
+
+   On successful exit (or with ``--keep``),
+   print the message ID of the newly indexed message.
+
 .. option:: --decrypt=(true|nostash|auto|false)
 
    If ``true`` and the message is encrypted, try to decrypt the
diff --git a/notmuch-insert.c b/notmuch-insert.c
index e44607ad..cbc88240 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -399,9 +399,10 @@ maildir_write_new (const void *ctx, int fdin, const char *maildir, bool world_re
  * database results in error status regardless of keep.
  */
 static notmuch_status_t
-add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
+add_file (const void *ctx, notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
 	  bool synchronize_flags, bool keep,
-	  notmuch_indexopts_t *indexopts)
+	  notmuch_indexopts_t *indexopts,
+	  char **message_id_out)
 {
     notmuch_message_t *message;
     notmuch_status_t status;
@@ -441,8 +442,6 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
     }
 
   DONE:
-    notmuch_message_destroy (message);
-
     if (status) {
 	if (keep) {
 	    status = NOTMUCH_STATUS_SUCCESS;
@@ -458,6 +457,15 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
 	    }
 	}
     }
+    if (message_id_out) {
+	if (!status) {
+	    *message_id_out = talloc_strdup(ctx, notmuch_message_get_message_id(message));
+	} else {
+	    *message_id_out = NULL;
+	}
+    }
+    notmuch_message_destroy (message);
+
 
   FAIL:
     return status;
@@ -477,10 +485,12 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
     bool keep = false;
     bool hooks = true;
     bool world_readable = false;
+    bool emit_message_id = true;
     notmuch_bool_t synchronize_flags;
     char *maildir;
     char *newpath;
     int opt_index;
+    char *message_id;
     notmuch_indexopts_t *indexopts = notmuch_database_get_default_indexopts (notmuch);
 
     void *local = talloc_new (NULL);
@@ -491,6 +501,7 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
 	{ .opt_bool = &keep, .name = "keep" },
 	{ .opt_bool = &hooks, .name = "hooks" },
 	{ .opt_bool = &world_readable, .name = "world-readable" },
+	{ .opt_bool = &emit_message_id, .name = "emit-message-id" },
 	{ .opt_inherit = notmuch_shared_indexing_options },
 	{ .opt_inherit = notmuch_shared_options },
 	{ }
@@ -580,7 +591,8 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
     }
 
     /* Index the message. */
-    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts);
+    status = add_file (local, notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts,
+		       emit_message_id ? &message_id : NULL);
 
     /* Commit changes. */
     close_status = notmuch_database_close (notmuch);
@@ -606,6 +618,10 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
 	}
     }
 
+    if (!status && emit_message_id && message_id) {
+	printf("%s\n", message_id);
+    }
+
     if (hooks && status == NOTMUCH_STATUS_SUCCESS) {
 	/* Ignore hook failures. */
 	notmuch_run_hook (notmuch, "post-insert");
-- 
2.45.2


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

* [PATCH v2] Add --emit-message-id flag to notmuch-insert.
  2024-09-10 20:33 [PATCH] Add --emit-message-id flag to notmuch-insert Brennan Vincent
@ 2024-09-11 15:00 ` Brennan Vincent
  2024-09-25 21:51   ` David Bremner
  2024-09-11 16:09 ` [PATCH] emacs: Introduce notmuch-draftify-buffer command Brennan Vincent
  2024-09-26 20:25 ` [PATCH v3] Add --emit-message-id flag to notmuch-insert Brennan Vincent
  2 siblings, 1 reply; 9+ messages in thread
From: Brennan Vincent @ 2024-09-11 15:00 UTC (permalink / raw)
  To: notmuch

---
 doc/man1/notmuch-insert.rst |  5 +++++
 notmuch-insert.c            | 26 +++++++++++++++++++++-----
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst
index e05bd0b5..3848b8f6 100644
--- a/doc/man1/notmuch-insert.rst
+++ b/doc/man1/notmuch-insert.rst
@@ -66,6 +66,11 @@ Supported options for **insert** include
    umask.  By default, delivered mail is only readable by the current
    user.
 
+.. option:: --emit-message-id
+
+   On successful exit (or with ``--keep``),
+   print the message ID of the newly indexed message.
+
 .. option:: --decrypt=(true|nostash|auto|false)
 
    If ``true`` and the message is encrypted, try to decrypt the
diff --git a/notmuch-insert.c b/notmuch-insert.c
index e44607ad..5554245b 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -399,9 +399,10 @@ maildir_write_new (const void *ctx, int fdin, const char *maildir, bool world_re
  * database results in error status regardless of keep.
  */
 static notmuch_status_t
-add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
+add_file (const void *ctx, notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
 	  bool synchronize_flags, bool keep,
-	  notmuch_indexopts_t *indexopts)
+	  notmuch_indexopts_t *indexopts,
+	  char **message_id_out)
 {
     notmuch_message_t *message;
     notmuch_status_t status;
@@ -441,8 +442,6 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
     }
 
   DONE:
-    notmuch_message_destroy (message);
-
     if (status) {
 	if (keep) {
 	    status = NOTMUCH_STATUS_SUCCESS;
@@ -458,6 +457,15 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
 	    }
 	}
     }
+    if (message_id_out) {
+	if (!status) {
+	    *message_id_out = talloc_strdup(ctx, notmuch_message_get_message_id(message));
+	} else {
+	    *message_id_out = NULL;
+	}
+    }
+    notmuch_message_destroy (message);
+
 
   FAIL:
     return status;
@@ -477,10 +485,12 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
     bool keep = false;
     bool hooks = true;
     bool world_readable = false;
+    bool emit_message_id = false;
     notmuch_bool_t synchronize_flags;
     char *maildir;
     char *newpath;
     int opt_index;
+    char *message_id;
     notmuch_indexopts_t *indexopts = notmuch_database_get_default_indexopts (notmuch);
 
     void *local = talloc_new (NULL);
@@ -491,6 +501,7 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
 	{ .opt_bool = &keep, .name = "keep" },
 	{ .opt_bool = &hooks, .name = "hooks" },
 	{ .opt_bool = &world_readable, .name = "world-readable" },
+	{ .opt_bool = &emit_message_id, .name = "emit-message-id" },
 	{ .opt_inherit = notmuch_shared_indexing_options },
 	{ .opt_inherit = notmuch_shared_options },
 	{ }
@@ -580,7 +591,8 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
     }
 
     /* Index the message. */
-    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts);
+    status = add_file (local, notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts,
+		       emit_message_id ? &message_id : NULL);
 
     /* Commit changes. */
     close_status = notmuch_database_close (notmuch);
@@ -606,6 +618,10 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
 	}
     }
 
+    if (!status && emit_message_id && message_id) {
+	printf("%s\n", message_id);
+    }
+
     if (hooks && status == NOTMUCH_STATUS_SUCCESS) {
 	/* Ignore hook failures. */
 	notmuch_run_hook (notmuch, "post-insert");
-- 
2.45.2


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

* [PATCH] emacs: Introduce notmuch-draftify-buffer command.
  2024-09-10 20:33 [PATCH] Add --emit-message-id flag to notmuch-insert Brennan Vincent
  2024-09-11 15:00 ` [PATCH v2] " Brennan Vincent
@ 2024-09-11 16:09 ` Brennan Vincent
  2024-09-25 22:09   ` David Bremner
  2024-09-26 20:25 ` [PATCH v3] Add --emit-message-id flag to notmuch-insert Brennan Vincent
  2 siblings, 1 reply; 9+ messages in thread
From: Brennan Vincent @ 2024-09-11 16:09 UTC (permalink / raw)
  To: notmuch

This command inserts the current buffer as a draft. It optionally
begins editing the draft.

This can be useful for email-based Git contribution workflows. For
example, one can use git format-patch to generate a patch, then
notmuch-draftify-buffer on the generated patch to immediately begin
editing a message for submission to an appropriate mailing list.
---
 emacs/notmuch-draft.el       | 10 ++++++++++
 emacs/notmuch-lib.el         | 12 ++++++++----
 emacs/notmuch-maildir-fcc.el | 16 ++++++++++------
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index fcc45503..4bff68f2 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -278,6 +278,16 @@ applied to newly inserted messages)."
       ;; message is resaved or sent.
       (setq notmuch-draft-id (and draft id)))))
 
+(defun notmuch-draftify-buffer (arg)
+  "Inserts the current buffer as a draft. With prefix argument, begins editing the draft."
+  (interactive "P")
+  (let ((message-id (notmuch-maildir-notmuch-insert-current-buffer
+                     notmuch-draft-folder
+                     t
+                     notmuch-draft-tags)))
+    (when (and arg message-id)
+      (notmuch-draft-resume (format "id:%s" message-id)))))
+
 ;;; _
 
 (add-hook 'message-send-hook 'notmuch-draft--mark-deleted)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index bf9c4a53..1e371f67 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -935,11 +935,15 @@ supported keyword arguments are:
 
 If notmuch exits with a non-zero status, output from the process
 will appear in a buffer named \"*Notmuch errors*\" and an error
-will be signaled."
+will be signaled.
+
+Otherwise, returns the output from the process as a string."
   (with-temp-buffer
-    (let ((status (notmuch-call-notmuch--helper t args)))
-      (notmuch-check-exit-status status (cons notmuch-command args)
-				 (buffer-string)))))
+    (let ((status (notmuch-call-notmuch--helper t args))
+	  (output (buffer-string)))
+      (and (notmuch-check-exit-status status (cons notmuch-command args)
+				      output)
+	   output))))
 
 (defun notmuch-call-notmuch-sexp (&rest args)
   "Invoke `notmuch-command' with ARGS and return the parsed S-exp output.
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index c7b403cf..09fc832d 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -215,12 +215,16 @@ normal fcc."
 This inserts the current buffer as a message into the notmuch
 database in folder FOLDER. If CREATE is non-nil it will supply
 the --create-folder flag to create the folder if necessary. TAGS
-should be a list of tag changes to apply to the inserted message."
-  (apply 'notmuch-call-notmuch-process
-	 :stdin-string (buffer-string) "insert"
-	 (append (and create (list "--create-folder"))
-		 (list (concat "--folder=" folder))
-		 tags)))
+should be a list of tag changes to apply to the inserted message.
+
+Returns the message ID of the inserted message."
+  (let ((output (apply 'notmuch-call-notmuch-process
+		       :stdin-string (buffer-string) "insert"
+		       (append (and create (list "--create-folder"))
+			       (list (concat "--folder=" folder)
+				     "--emit-message-id")
+			       tags))))
+    (string-trim output)))
 
 (defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
   "Store message with notmuch insert.
-- 
2.45.2


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

* Re: [PATCH v2] Add --emit-message-id flag to notmuch-insert.
  2024-09-11 15:00 ` [PATCH v2] " Brennan Vincent
@ 2024-09-25 21:51   ` David Bremner
  2024-10-03 17:35     ` When exactly is the post-insert hook called? Ralph Seichter
  0 siblings, 1 reply; 9+ messages in thread
From: David Bremner @ 2024-09-25 21:51 UTC (permalink / raw)
  To: Brennan Vincent, notmuch

Brennan Vincent <brennan@umanwizard.com> writes:

First, thanks for sending a contribution to notmuch.

Usually we insist on a bit more verbose (see
https://notmuchmail.org/contributing/#index5h2 for details).

Here it's probably enough to mention the overall goal of the patch
series, that this feature will be used to add a draftify feature, but
maybe you have a more general "why" to discuss.


> ---
>  doc/man1/notmuch-insert.rst |  5 +++++
>  notmuch-insert.c            | 26 +++++++++++++++++++++-----
>  2 files changed, 26 insertions(+), 5 deletions(-)
>
> diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst
> index e05bd0b5..3848b8f6 100644
> --- a/doc/man1/notmuch-insert.rst
> +++ b/doc/man1/notmuch-insert.rst
> @@ -66,6 +66,11 @@ Supported options for **insert** include
>     umask.  By default, delivered mail is only readable by the current
>     user.
>  
> +.. option:: --emit-message-id
> +
> +   On successful exit (or with ``--keep``),
> +   print the message ID of the newly indexed message.
> +

I'm a bit confused here. If indexing fails with --keep, the
printed id will not exist in the database, right? So how is the user
supposed to detect that kind of failure?

> -add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
> +add_file (const void *ctx, notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,

Since notmuch is already a talloc context, you should address the need
for a new context somewhere (either a comment or the commit message).
>  
>    DONE:
> -    notmuch_message_destroy (message);
> -
>      if (status) {
>  	if (keep) {
>  	    status = NOTMUCH_STATUS_SUCCESS;
> @@ -458,6 +457,15 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
>  	    }
>  	}
>      }
> +    if (message_id_out) {
> +	if (!status) {
I can't quite explain why I don't mind if (status), but find "if
(!status)" for success a bit jarring/confusing, but an explicit test
against NOTMUCH_STATUS_SUCCESS would be nicer, IMHO.


A more substantial comment is that for new CLI features we need at least one
or two tests. Hopefully test/T070-insert.sh gives you enough clues, but
feel free to ask for help.

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

* Re: [PATCH] emacs: Introduce notmuch-draftify-buffer command.
  2024-09-11 16:09 ` [PATCH] emacs: Introduce notmuch-draftify-buffer command Brennan Vincent
@ 2024-09-25 22:09   ` David Bremner
  2024-09-29  0:36     ` Brennan Vincent
  0 siblings, 1 reply; 9+ messages in thread
From: David Bremner @ 2024-09-25 22:09 UTC (permalink / raw)
  To: Brennan Vincent, notmuch

Brennan Vincent <brennan@umanwizard.com> writes:

> This command inserts the current buffer as a draft. It optionally
> begins editing the draft.

[nice commit message snipped]

Here again, if possible we would like a test. For emacs tests it is a
bit more laborious, but there are several options outlined in
test/

>  will appear in a buffer named \"*Notmuch errors*\" and an error
> -will be signaled."
> +will be signaled.
> +
> +Otherwise, returns the output from the process as a string."
>    (with-temp-buffer
> -    (let ((status (notmuch-call-notmuch--helper t args)))
> -      (notmuch-check-exit-status status (cons notmuch-command args)
> -				 (buffer-string)))))
> +    (let ((status (notmuch-call-notmuch--helper t args))
> +	  (output (buffer-string)))
> +      (and (notmuch-check-exit-status status (cons notmuch-command args)
> +				      output)
> +	   output))))

Is it clear / documented what the return value of
notmuch-check-exit-status is? If all you mean is that it completes
without error, I think "progn" is clearer than "and"

> +Returns the message ID of the inserted message."
> +  (let ((output (apply 'notmuch-call-notmuch-process
> +		       :stdin-string (buffer-string) "insert"
> +		       (append (and create (list "--create-folder"))
> +			       (list (concat "--folder=" folder)
> +				     "--emit-message-id")
> +			       tags))))
> +    (string-trim output)))

One problem we have is that people merrily upgrade the emacs front end
without updating the CLI. Recently (see devel/schemata) we have started
bumping the output version for new command arguments, so at least the
error reporting is clear.

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

* [PATCH v3] Add --emit-message-id flag to notmuch-insert.
  2024-09-10 20:33 [PATCH] Add --emit-message-id flag to notmuch-insert Brennan Vincent
  2024-09-11 15:00 ` [PATCH v2] " Brennan Vincent
  2024-09-11 16:09 ` [PATCH] emacs: Introduce notmuch-draftify-buffer command Brennan Vincent
@ 2024-09-26 20:25 ` Brennan Vincent
  2 siblings, 0 replies; 9+ messages in thread
From: Brennan Vincent @ 2024-09-26 20:25 UTC (permalink / raw)
  To: notmuch

It may be the case that a user (or script) wants to take some action
on a message immediately after inserting it. This can be done if one
knows the Message-ID with which the message was inserted. In order to
facilitate this use case, we add a flag "--emit-message-id" to notmuch
insert.

One example of a possible usecase (which is part of an upcoming patch)
is an emacs command to begin editing the current buffer as a draft.
---
 doc/man1/notmuch-insert.rst |  5 +++++
 notmuch-insert.c            | 24 ++++++++++++++++++++----
 test/T070-insert.sh         | 31 +++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst
index e05bd0b5..141e5cb9 100644
--- a/doc/man1/notmuch-insert.rst
+++ b/doc/man1/notmuch-insert.rst
@@ -66,6 +66,11 @@ Supported options for **insert** include
    umask.  By default, delivered mail is only readable by the current
    user.
 
+.. option:: --emit-message-id
+
+   If the message was successfully inserted into the database,
+   print the message ID of the newly indexed message.
+
 .. option:: --decrypt=(true|nostash|auto|false)
 
    If ``true`` and the message is encrypted, try to decrypt the
diff --git a/notmuch-insert.c b/notmuch-insert.c
index e44607ad..05945a99 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -401,7 +401,8 @@ maildir_write_new (const void *ctx, int fdin, const char *maildir, bool world_re
 static notmuch_status_t
 add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
 	  bool synchronize_flags, bool keep,
-	  notmuch_indexopts_t *indexopts)
+	  notmuch_indexopts_t *indexopts,
+	  char **message_id_out)
 {
     notmuch_message_t *message;
     notmuch_status_t status;
@@ -441,8 +442,6 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
     }
 
   DONE:
-    notmuch_message_destroy (message);
-
     if (status) {
 	if (keep) {
 	    status = NOTMUCH_STATUS_SUCCESS;
@@ -458,6 +457,15 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,
 	    }
 	}
     }
+    if (message_id_out) {
+	if (status == NOTMUCH_STATUS_SUCCESS) {
+	    *message_id_out = talloc_strdup(notmuch, notmuch_message_get_message_id(message));
+	} else {
+	    *message_id_out = NULL;
+	}
+    }
+    notmuch_message_destroy (message);
+
 
   FAIL:
     return status;
@@ -477,10 +485,12 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
     bool keep = false;
     bool hooks = true;
     bool world_readable = false;
+    bool emit_message_id = false;
     notmuch_bool_t synchronize_flags;
     char *maildir;
     char *newpath;
     int opt_index;
+    char *message_id;
     notmuch_indexopts_t *indexopts = notmuch_database_get_default_indexopts (notmuch);
 
     void *local = talloc_new (NULL);
@@ -491,6 +501,7 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
 	{ .opt_bool = &keep, .name = "keep" },
 	{ .opt_bool = &hooks, .name = "hooks" },
 	{ .opt_bool = &world_readable, .name = "world-readable" },
+	{ .opt_bool = &emit_message_id, .name = "emit-message-id" },
 	{ .opt_inherit = notmuch_shared_indexing_options },
 	{ .opt_inherit = notmuch_shared_options },
 	{ }
@@ -580,7 +591,8 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
     }
 
     /* Index the message. */
-    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts);
+    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts,
+		       emit_message_id ? &message_id : NULL);
 
     /* Commit changes. */
     close_status = notmuch_database_close (notmuch);
@@ -606,6 +618,10 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[])
 	}
     }
 
+    if (emit_message_id && message_id && status == NOTMUCH_STATUS_SUCCESS) {
+	printf("%s\n", message_id);
+    }
+
     if (hooks && status == NOTMUCH_STATUS_SUCCESS) {
 	/* Ignore hook failures. */
 	notmuch_run_hook (notmuch, "post-insert");
diff --git a/test/T070-insert.sh b/test/T070-insert.sh
index 73953272..6ae6abd0 100755
--- a/test/T070-insert.sh
+++ b/test/T070-insert.sh
@@ -257,6 +257,33 @@ test_expect_code 1 "notmuch insert < $gen_msg_filename 2>&1"
 
 notmuch config set new.tags $OLDCONFIG
 
+gen_insert_msg
+test_begin_subtest "--emit-message-id works"
+output=$(notmuch insert --emit-message-id < $gen_msg_filename)
+expected_msg_id=$(< $gen_msg_filename grep Message-Id | sed -E 's/^Message-Id: <(.*)>$/\1/')
+test_expect_equal "$output" "$expected_msg_id"
+
+test_begin_subtest "--emit-message-id works even when the message already exists"
+output=$(notmuch insert --emit-message-id < $gen_msg_filename)
+expected_msg_id=$(< $gen_msg_filename grep Message-Id | sed -E 's/^Message-Id: <(.*)>$/\1/')
+test_expect_equal "$output" "$expected_msg_id"
+
+gen_insert_msg
+test_begin_subtest "--keep --emit-message-id works when maildir flag sync fails"
+make_shim shim-failed-sync <<EOF
+#include <notmuch.h>
+notmuch_status_t
+notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)
+{
+  return NOTMUCH_STATUS_OUT_OF_MEMORY;
+}
+EOF
+notmuch config set maildir.synchronize_flags true
+output=$(notmuch_with_shim shim-failed-sync insert --keep --emit-message-id < $gen_msg_filename)
+expected_msg_id=$(< $gen_msg_filename grep Message-Id | sed -E 's/^Message-Id: <(.*)>$/\1/')
+test_expect_equal "$output" "$expected_msg_id"
+notmuch config set maildir.synchronize_flags false
+
 # DUPLICATE_MESSAGE_ID is not tested here, because it should actually pass.
 # pregenerate all of the test shims
 for code in FILE_NOT_EMAIL READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR OUT_OF_MEMORY XAPIAN_EXCEPTION; do
@@ -282,6 +309,10 @@ for code in FILE_NOT_EMAIL READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do
 
     test_begin_subtest "success exit with --keep when index_file returns $code"
     test_expect_code 0 "notmuch_with_shim shim-$code insert --keep < \"$gen_msg_filename\""
+
+    test_begin_subtest "nothing printed even with --keep --emit-message-id  when index_file returns $code"
+    output=$(notmuch_with_shim shim-$code insert --keep --emit-message-id < $gen_msg_filename)
+    test_expect_equal "$output" ""
 done
 
 for code in OUT_OF_MEMORY XAPIAN_EXCEPTION ; do
-- 
2.46.0


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

* Re: [PATCH] emacs: Introduce notmuch-draftify-buffer command.
  2024-09-25 22:09   ` David Bremner
@ 2024-09-29  0:36     ` Brennan Vincent
  0 siblings, 0 replies; 9+ messages in thread
From: Brennan Vincent @ 2024-09-29  0:36 UTC (permalink / raw)
  To: David Bremner, notmuch

David Bremner <david@tethera.net> writes:

> Brennan Vincent <brennan@umanwizard.com> writes:
>
>> This command inserts the current buffer as a draft. It optionally
>> begins editing the draft.
>
> [nice commit message snipped]
>
> Here again, if possible we would like a test. For emacs tests it is a
> bit more laborious, but there are several options outlined in
> test/
Done, will be in the next revision of the patch series.
>
>>  will appear in a buffer named \"*Notmuch errors*\" and an error
>> -will be signaled."
>> +will be signaled.
>> +
>> +Otherwise, returns the output from the process as a string."
>>    (with-temp-buffer
>> -    (let ((status (notmuch-call-notmuch--helper t args)))
>> -      (notmuch-check-exit-status status (cons notmuch-command args)
>> -				 (buffer-string)))))
>> +    (let ((status (notmuch-call-notmuch--helper t args))
>> +	  (output (buffer-string)))
>> +      (and (notmuch-check-exit-status status (cons notmuch-command args)
>> +				      output)
>> +	   output))))
>
> Is it clear / documented what the return value of
> notmuch-check-exit-status is? If all you mean is that it completes
> without error, I think "progn" is clearer than "and"
Done, will be in the next revision of the patch series.
>
>> +Returns the message ID of the inserted message."
>> +  (let ((output (apply 'notmuch-call-notmuch-process
>> +		       :stdin-string (buffer-string) "insert"
>> +		       (append (and create (list "--create-folder"))
>> +			       (list (concat "--folder=" folder)
>> +				     "--emit-message-id")
>> +			       tags))))
>> +    (string-trim output)))
>
> One problem we have is that people merrily upgrade the emacs front end
> without updating the CLI. Recently (see devel/schemata) we have started
> bumping the output version for new command arguments, so at least the
> error reporting is clear.
That won't work here, since `notmuch insert` doesn't accept
--format-version at all, so people using older versions of the CLI would
just get an obscure error about --format-version being an unrecognized
arg.

What we can do is in notmuch-check-exit-status, search the error output
for "Unrecognized option: --emit-message-id" and translate it to
something friendlier. Searching for specific strings in error message is
a bit unsatisfying to me, but at least it works (and correct me if I'm
wrong, but I don't think notmuch has been localized to languages other
than English which would break it).

What do you think?

(Btw, I think in the future it would be good to make all commands accept
--format-version, even those whose output doesn't change today, to avoid
this sort of issue).
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

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

* When exactly is the post-insert hook called?
  2024-09-25 21:51   ` David Bremner
@ 2024-10-03 17:35     ` Ralph Seichter
  2024-10-03 17:59       ` Ralph Seichter
  0 siblings, 1 reply; 9+ messages in thread
From: Ralph Seichter @ 2024-10-03 17:35 UTC (permalink / raw)
  To: notmuch

I have been using a post-new hook for ages without problems, and today I
got curious about post-insert. I set up ~/.maildir/.notmuch/hooks/post-insert
like I previously did with post-new. Whenever invoked manually, post-insert
notes an event in a log file.

The issue is that I don't see post-insert ever being called by notmuch.
Should not both post-new and post-insert be called when "notmuch new" is
invoked after new mail has arrived?

The manual page notmuch-hooks(5) states:

  The hook will not be run if there have been any errors during the
  message delivery; what is regarded as successful delivery depends on
  the --keep option.

What is the --keep option and where is it documented? I have not yet
been able find a source, so I am asking here.

-Ralph

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

* Re: When exactly is the post-insert hook called?
  2024-10-03 17:35     ` When exactly is the post-insert hook called? Ralph Seichter
@ 2024-10-03 17:59       ` Ralph Seichter
  0 siblings, 0 replies; 9+ messages in thread
From: Ralph Seichter @ 2024-10-03 17:59 UTC (permalink / raw)
  To: notmuch

Oops, looks like I somehow hijacked a thread instead of creating a new
one. Sorry, my bad. I guess switching one's MUA is not easily done
without small hiccups along the way.

-Ralph

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

end of thread, other threads:[~2024-10-03 18:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-10 20:33 [PATCH] Add --emit-message-id flag to notmuch-insert Brennan Vincent
2024-09-11 15:00 ` [PATCH v2] " Brennan Vincent
2024-09-25 21:51   ` David Bremner
2024-10-03 17:35     ` When exactly is the post-insert hook called? Ralph Seichter
2024-10-03 17:59       ` Ralph Seichter
2024-09-11 16:09 ` [PATCH] emacs: Introduce notmuch-draftify-buffer command Brennan Vincent
2024-09-25 22:09   ` David Bremner
2024-09-29  0:36     ` Brennan Vincent
2024-09-26 20:25 ` [PATCH v3] Add --emit-message-id flag to notmuch-insert Brennan Vincent

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