]> git.cworth.org Git - notmuch/commitdiff
CLI/reply: support --duplicate argument
authorDavid Bremner <david@tethera.net>
Fri, 1 Jul 2022 21:45:47 +0000 (18:45 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 30 Jul 2022 11:45:15 +0000 (08:45 -0300)
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
emacs/notmuch-show.el
notmuch-reply.c
test/T220-reply.sh

index fa0371f955e81fe49c15fefc5d7ccca5acd43261..4f39a9597e8c13e118e95b34901709e2861be1c7 100644 (file)
@@ -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
index 05524c2eec0a372db4b3097a14488d9428c69516..0d9bf0710d4c58d369f7674e4533279824baea78 100644 (file)
@@ -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))
index 40576f190348ffd5053fe4270c940915c41f5fe3..44297251d02183121685a0cb5bda2cae76cdbea4 100644 (file)
@@ -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 },
        { }
     };
index 50179efc90097875f2f54d6ab2b3139faf77e2c0..207f578810133643491dad884fafb879a8e62312 100755 (executable)
@@ -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