]> git.cworth.org Git - notmuch/commitdiff
CLI/show: initial support for --duplicate for (raw output only)
authorDavid Bremner <david@tethera.net>
Fri, 1 Jul 2022 21:45:43 +0000 (18:45 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 30 Jul 2022 11:39:13 +0000 (08:39 -0300)
Add command line argument --duplicate, analogous with that already
supported for notmuch-search.

Use of a seperate function for _get_filename is mainly a form of
documentation at this point.

md5sum is of course a weak hash, but it is good enough for
this (non-adversarial) test suite use.

doc/man1/notmuch-show.rst
notmuch-client.h
notmuch-show.c
test/T210-raw.sh

index 5535392153654b7dcae91585ac002e58d67da54e..2c0a0de6ad1679ccc2d2596acd3c8936a968e49c 100644 (file)
@@ -27,6 +27,12 @@ Supported options for **show** include
 
 .. program:: show
 
+.. option:: --duplicate=N
+
+   Output duplicate number N. The numbering starts from 1, and matches
+   the order used by :option:`search --duplicate` and
+   :option:`search --output=files <search --output>`
+
 .. option:: --entire-thread=(true|false)
 
    If true, **notmuch show** outputs all messages in the thread of
index 9f57ac5e3935c430fb983645860780a8a937986b..f8f987e70e40b19755224557476f921cb61c17e9 100644 (file)
@@ -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;
index 6a54d9c16a0684b28bbc9e98e2c62bed340ba03e..81b37e7cb32d86de75704b84c786aff5ee82bca8 100644 (file)
 #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 +940,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 +1281,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 +1322,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 +1341,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)
index e1d50bf90a0a15881d1a7712b1fad813a13009ee..440820286a00169956aca2101c9a12e60aeb5803 100755 (executable)
@@ -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
+ID=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:${ID} | md5sum | cut -f1 -d' '  >> OUTPUT.raw
+done
+sort OUTPUT.raw > OUTPUT
+notmuch search --output=files id:${ID} | xargs md5sum | cut -f1 -d ' ' | sort > EXPECTED
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
 test_done