unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [RFC PATCH v2 4/7] CLI/show: WIP support --duplicate for raw output
Date: Sun, 19 Jun 2022 20:21:50 -0300	[thread overview]
Message-ID: <20220619232152.846823-5-david@tethera.net> (raw)
In-Reply-To: <20220619232152.846823-1-david@tethera.net>

---
 notmuch-client.h |  1 +
 notmuch-show.c   | 21 ++++++++++++++++++++-
 test/T210-raw.sh | 11 +++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 9f57ac5e..f8f987e7 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -75,6 +75,7 @@ typedef struct notmuch_show_params {
     bool entire_thread;
     bool omit_excluded;
     bool output_body;
+    int duplicate;
     int part;
     _notmuch_crypto_t crypto;
     bool include_html;
diff --git a/notmuch-show.c b/notmuch-show.c
index 6a54d9c1..7b57aab3 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -23,6 +23,20 @@
 #include "sprinter.h"
 #include "zlib-extra.h"
 
+static const char *
+_get_filename (notmuch_message_t *message, int index) {
+    notmuch_filenames_t *filenames = notmuch_message_get_filenames (message);
+    int i=1;
+
+    for (;
+	 notmuch_filenames_valid (filenames);
+	 notmuch_filenames_move_to_next (filenames), i++) {
+	if (i >= index)
+	    return notmuch_filenames_get (filenames);
+    }
+    return NULL;
+}
+
 static const char *
 _get_tags_as_string (const void *ctx, notmuch_message_t *message)
 {
@@ -925,7 +939,7 @@ format_part_raw (unused (const void *ctx), unused (sprinter_t *sp),
 	char buf[4096];
 	notmuch_status_t ret = NOTMUCH_STATUS_FILE_ERROR;
 
-	filename = notmuch_message_get_filename (node->envelope_file);
+	filename = _get_filename (node->envelope_file, params->duplicate);
 	if (filename == NULL) {
 	    fprintf (stderr, "Error: Cannot get message filename.\n");
 	    goto DONE;
@@ -1266,6 +1280,7 @@ notmuch_show_command (notmuch_database_t *notmuch, int argc, char *argv[])
     sprinter_t *sprinter;
     notmuch_show_params_t params = {
 	.part = -1,
+	.duplicate = 0,
 	.omit_excluded = true,
 	.output_body = true,
 	.crypto = { .decrypt = NOTMUCH_DECRYPT_AUTO },
@@ -1306,6 +1321,7 @@ notmuch_show_command (notmuch_database_t *notmuch, int argc, char *argv[])
 	{ .opt_bool = &params.crypto.verify, .name = "verify" },
 	{ .opt_bool = &params.output_body, .name = "body" },
 	{ .opt_bool = &params.include_html, .name = "include-html" },
+	{ .opt_int = &params.duplicate, .name = "duplicate" },
 	{ .opt_inherit = notmuch_shared_options },
 	{ }
     };
@@ -1324,6 +1340,9 @@ notmuch_show_command (notmuch_database_t *notmuch, int argc, char *argv[])
     /* specifying a part implies single message display */
     single_message = params.part >= 0;
 
+    /* specifying a duplicate also implies single message display */
+    single_message = single_message || (params.duplicate>0);
+
     if (format == NOTMUCH_FORMAT_NOT_SPECIFIED) {
 	/* if part was requested and format was not specified, use format=raw */
 	if (params.part >= 0)
diff --git a/test/T210-raw.sh b/test/T210-raw.sh
index e1d50bf9..f4990b6d 100755
--- a/test/T210-raw.sh
+++ b/test/T210-raw.sh
@@ -64,4 +64,15 @@ for pow in {10..20}; do
     test_expect_success "notmuch show --format=raw subject:$size > /dev/null"
 done
 
+add_email_corpus duplicate
+ID3=87r2ecrr6x.fsf@zephyr.silentflame.com 
+test_begin_subtest "raw content, duplicate files"
+rm -f OUTPUT.raw
+for dup in {1..5}; do
+    notmuch show --format=raw --duplicate=${dup} --format=raw id:${ID3} | md5sum | cut -f1 -d' '  >> OUTPUT.raw
+done
+sort OUTPUT.raw > OUTPUT
+notmuch search --output=files id:${ID3} | xargs md5sum | cut -f1 -d ' ' | sort > EXPECTED
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
 test_done
-- 
2.35.2

  parent reply	other threads:[~2022-06-19 23:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-19 23:21 v2 WIP commands to choose duplicates in emacs interface David Bremner
2022-06-19 23:21 ` [RFC PATCH v2 1/7] test: use notmuch_json_show_sanitize more places David Bremner
2022-06-19 23:21 ` [RFC PATCH v2 2/7] test: define and use notmuch_sexp_*_sanitize functions David Bremner
2022-06-19 23:21 ` [RFC PATCH v2 3/7] test: add new corpus of duplicate messages David Bremner
2022-06-19 23:21 ` David Bremner [this message]
2022-06-19 23:21 ` [RFC PATCH v2 5/7] WIP: support show --duplicate for structured output David Bremner
2022-06-19 23:21 ` [RFC PATCH v2 6/7] WIP/emacs: replace message with different duplicate David Bremner
2022-06-19 23:21 ` [RFC PATCH v2 7/7] WIP/emacs: display count of duplicates in headerline David Bremner
2022-06-29 12:15 ` v2 WIP commands to choose duplicates in emacs interface David Bremner

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=20220619232152.846823-5-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).