unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 8/9] CLI/reply: support --duplicate argument
Date: Fri,  1 Jul 2022 18:45:47 -0300	[thread overview]
Message-ID: <20220701214548.461943-9-david@tethera.net> (raw)
In-Reply-To: <20220701214548.461943-1-david@tethera.net>

We want the reply used to match that shown e.g. in the emacs
interface. As a first step provide that functionality on the command
line.

Schema does not need updating as the duplicate key was already
present (with a constant value of 1).
---
 doc/man1/notmuch-reply.rst |  6 ++++++
 emacs/notmuch-show.el      |  2 +-
 notmuch-reply.c            |  6 ++++--
 test/T220-reply.sh         | 36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/doc/man1/notmuch-reply.rst b/doc/man1/notmuch-reply.rst
index fa0371f9..4f39a959 100644
--- a/doc/man1/notmuch-reply.rst
+++ b/doc/man1/notmuch-reply.rst
@@ -38,6 +38,12 @@ Supported options for **reply** include
 
 .. program:: reply
 
+.. option:: --duplicate=N
+
+   Reply to duplicate number N. The numbering starts from 1, and
+   matches the order used by :option:`show --duplicate` and
+   :option:`search --output=files <search --output>`.
+
 .. option:: --format=(default|json|sexp|headers-only)
 
    default
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index edf39674..ee01e470 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -555,7 +555,7 @@ message at DEPTH in the current thread."
      (if (> file-count 1)
 	 (let ((txt (format "%d/%d\n" duplicate file-count)))
 	   (concat
-	    (notmuch-show-spaces-n (- (window-width) (+ (current-column) (length txt))))
+	    (notmuch-show-spaces-n (max 0 (- (window-width) (+ (current-column) (length txt)))))
 	    txt))
        "\n"))
     (overlay-put (make-overlay start (point))
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 40576f19..44297251 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -663,7 +663,7 @@ do_reply (notmuch_database_t *notmuch,
 	 notmuch_messages_move_to_next (messages)) {
 	message = notmuch_messages_get (messages);
 
-	if (mime_node_open (notmuch, message, -1, &params->crypto, &node))
+	if (mime_node_open (notmuch, message, params->duplicate, &params->crypto, &node))
 	    return 1;
 
 	reply = create_reply_message (notmuch, message,
@@ -683,7 +683,7 @@ do_reply (notmuch_database_t *notmuch,
 
 	    /* Start the original */
 	    sp->map_key (sp, "original");
-	    format_part_sprinter (notmuch, sp, node, -1, true, false);
+	    format_part_sprinter (notmuch, sp, node, params->duplicate, true, false);
 
 	    /* End */
 	    sp->end (sp);
@@ -715,6 +715,7 @@ notmuch_reply_command (notmuch_database_t *notmuch, int argc, char *argv[])
     int opt_index;
     notmuch_show_params_t params = {
 	.part = -1,
+	.duplicate = 0,
 	.crypto = { .decrypt = NOTMUCH_DECRYPT_AUTO },
     };
     int format = FORMAT_DEFAULT;
@@ -739,6 +740,7 @@ notmuch_reply_command (notmuch_database_t *notmuch, int argc, char *argv[])
 				      { "auto", NOTMUCH_DECRYPT_AUTO },
 				      { "true", NOTMUCH_DECRYPT_NOSTASH },
 				      { 0, 0 } } },
+	{ .opt_int = &params.duplicate, .name = "duplicate" },
 	{ .opt_inherit = notmuch_shared_options },
 	{ }
     };
diff --git a/test/T220-reply.sh b/test/T220-reply.sh
index 50179efc..207f5788 100755
--- a/test/T220-reply.sh
+++ b/test/T220-reply.sh
@@ -353,4 +353,40 @@ On Thu, 16 Jun 2016 22:14:41 -0400, Alice <alice@example.org> wrote:
 > Note the Cc: and cc: headers.
 OK"
 
+add_email_corpus duplicate
+
+ID1=debian/2.6.1.dfsg-4-1-g87ea161@87ea161e851dfb1ea324af00e4ecfccc18875e15
+
+test_begin_subtest "format json, --duplicate=2, duplicate key"
+output=$(notmuch reply --format=json --duplicate=2 id:${ID1})
+test_json_nodes <<<"$output" "dup:['original']['duplicate']=2"
+
+test_begin_subtest "format json, subject, --duplicate=1"
+output=$(notmuch reply --format=json --duplicate=1 id:${ID1})
+file=$(notmuch search --output=files id:${ID1} | head -n 1)
+subject=$(sed -n 's/^Subject: \(.*\)$/\1/p' < $file)
+test_json_nodes <<<"$output" "subject:['reply-headers']['Subject']=\"Re: $subject\""
+
+test_begin_subtest "format json, subject, --duplicate=2"
+output=$(notmuch reply --format=json --duplicate=2 id:${ID1})
+file=$(notmuch search --output=files id:${ID1} | tail -n 1)
+subject=$(sed -n 's/^Subject: \(.*\)$/\1/p' < $file)
+test_json_nodes <<<"$output" "subject:['reply-headers']['Subject']=\"Re: $subject\""
+
+ID2=87r2geywh9.fsf@tethera.net
+for dup in {1..2}; do
+    test_begin_subtest "format json, body, --duplicate=${dup}"
+    output=$(notmuch reply --format=json --duplicate=${dup} id:${ID2} | \
+	     $NOTMUCH_PYTHON -B "$NOTMUCH_SRCDIR"/test/json_check_nodes.py "body:['original']['body'][0]['content']" | \
+	     grep '^# body')
+    test_expect_equal "$output" "# body ${dup}"
+done
+
+ID3=87r2ecrr6x.fsf@zephyr.silentflame.com
+for dup in {1..5}; do
+    test_begin_subtest "format json, --duplicate=${dup}, 'duplicate' key"
+    output=$(notmuch reply --format=json --duplicate=${dup} id:${ID3})
+    test_json_nodes <<<"$output" "dup:['original']['duplicate']=${dup}"
+done
+
 test_done
-- 
2.35.2

  parent reply	other threads:[~2022-07-01 21:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01 21:45 Display duplicate messages in emacs front-end David Bremner
2022-07-01 21:45 ` [PATCH 1/9] test: use notmuch_json_show_sanitize more places David Bremner
2022-07-01 21:45 ` [PATCH 2/9] test: define and use notmuch_sexp_*_sanitize functions David Bremner
2022-07-01 21:45 ` [PATCH 3/9] test: add new corpus of duplicate messages David Bremner
2022-07-05 10:07   ` David Bremner
2022-07-01 21:45 ` [PATCH 4/9] CLI/show: initial support for --duplicate for (raw output only) David Bremner
2022-07-01 21:45 ` [PATCH 5/9] CLI/show: support --duplicate for structured output David Bremner
2022-07-01 21:45 ` [PATCH 6/9] emacs/show: provide notmuch-show-choose-duplicate David Bremner
2022-07-01 21:45 ` [PATCH 7/9] emacs/show: display count of duplicates in headerline David Bremner
2022-07-01 21:45 ` David Bremner [this message]
2022-07-01 21:45 ` [PATCH 9/9] emacs/reply: reply to correct duplicate David Bremner
2022-07-30 11:50   ` David Bremner
2022-07-02  1:47 ` Display duplicate messages in emacs front-end David Bremner
2022-11-09 14:53 ` Daniel Kahn Gillmor
2022-11-09 16:55   ` Daniel Kahn Gillmor
2022-11-09 20:58     ` Jameson Graef Rollins
2022-11-10  4:57       ` Daniel Kahn Gillmor

Reply instructions:

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

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

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

  List information: https://notmuchmail.org/

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

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

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

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

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

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