From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id cOoIHx1rv2K6TAAAbAwnHQ (envelope-from ) for ; Fri, 01 Jul 2022 23:46:05 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id sJ4LHh1rv2KYggAAG6o9tA (envelope-from ) for ; Fri, 01 Jul 2022 23:46:05 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EFF739370 for ; Fri, 1 Jul 2022 23:46:04 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 67E525F7FF; Fri, 1 Jul 2022 21:45:56 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id E7D3E5F7D6 for ; Fri, 1 Jul 2022 21:45:53 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 6CE0B5FBD7; Fri, 1 Jul 2022 17:45:53 -0400 (EDT) Received: (nullmailer pid 462223 invoked by uid 1000); Fri, 01 Jul 2022 21:45:50 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 8/9] CLI/reply: support --duplicate argument Date: Fri, 1 Jul 2022 18:45:47 -0300 Message-Id: <20220701214548.461943-9-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220701214548.461943-1-david@tethera.net> References: <20220701214548.461943-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: STJY3Z37LPZ6YPT5YVVG2UGDJQZKQLJ4 X-Message-ID-Hash: STJY3Z37LPZ6YPT5YVVG2UGDJQZKQLJ4 X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1656711965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=CBJ4tgvAn93O6L/5VttmTV26rQXXwp7u3/X8Zni4yL0=; b=jD2AKKR6LZDdjZg/sqpkzemeCrFkcxYKH0J7klfJ5TxHXRZJ4asr7R1DmkEE/F0DdpW6VL 2jhipkzRaVEJJB61fLp/wAO8rhv5GFr4lPuyY0lMLiwh1P6gxBQYrKDE1UZCVLlItMA/3M Wf8WTRHm1EDVJStlrSpGfwe5v2Kj2l+L3Uu5fi3dfAB3Tp4dsveQeuDvvxZgXYDQIJggYm NZNvUPiPXn4V2KOaSzdIw/BylluMHJPhRt/OQMqVVmAR6X48FxzaaCwFZ5LdMbAmG6n9rO eDZVkM8sufeHu6zPFw3LCk5miu1DmnWKCJZeYgbvWCW8SE66iHW48nGmquFLGQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1656711965; a=rsa-sha256; cv=none; b=kzsgDo4Q8GQjP5M3UXCKvtHu7+AyNRxF+9XO3H2dJbsdZPWklfrOtDOBWSD2rvhv9f70PM fvF7xJxOLjpVp68W7WEYwR9ZGkiCCUIOSQ+6XdXKw+h08x9vNS6VaGS4i2YwfqnGwtaUF5 lVaDdd3O/rC0bDRpL9/WW2Nacj40NxzO0OWm6G9CprclxuvZSuwsqr2/X0CYLJ4ai6XCYw mGPoZPL7L4m7vs3Fc82u3ZAZ3pM/lmFb4JpY+p7122UKcVgTlze0JnP5NrIG3HR2yuMZHW udQ8Qs0J8vZYXfK1w6BH9Yu2qzNqNpFHwbdcShp/5uSoOlqtXwglv28+LI4Icg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.20 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: EFF739370 X-Spam-Score: -1.20 X-Migadu-Scanner: scn0.migadu.com X-TUID: /YofBAge//jo 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 `. + .. 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, ¶ms->crypto, &node)) + if (mime_node_open (notmuch, message, params->duplicate, ¶ms->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 = ¶ms.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 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