mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-04 08:28:15 +01:00
CLI/show: initial support for --duplicate for (raw output only)
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.
This commit is contained in:
parent
f599b8873f
commit
cef5eaaef6
4 changed files with 39 additions and 1 deletions
|
@ -27,6 +27,12 @@ Supported options for **show** include
|
||||||
|
|
||||||
.. program:: show
|
.. 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)
|
.. option:: --entire-thread=(true|false)
|
||||||
|
|
||||||
If true, **notmuch show** outputs all messages in the thread of
|
If true, **notmuch show** outputs all messages in the thread of
|
||||||
|
|
|
@ -75,6 +75,7 @@ typedef struct notmuch_show_params {
|
||||||
bool entire_thread;
|
bool entire_thread;
|
||||||
bool omit_excluded;
|
bool omit_excluded;
|
||||||
bool output_body;
|
bool output_body;
|
||||||
|
int duplicate;
|
||||||
int part;
|
int part;
|
||||||
_notmuch_crypto_t crypto;
|
_notmuch_crypto_t crypto;
|
||||||
bool include_html;
|
bool include_html;
|
||||||
|
|
|
@ -23,6 +23,21 @@
|
||||||
#include "sprinter.h"
|
#include "sprinter.h"
|
||||||
#include "zlib-extra.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 *
|
static const char *
|
||||||
_get_tags_as_string (const void *ctx, notmuch_message_t *message)
|
_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];
|
char buf[4096];
|
||||||
notmuch_status_t ret = NOTMUCH_STATUS_FILE_ERROR;
|
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) {
|
if (filename == NULL) {
|
||||||
fprintf (stderr, "Error: Cannot get message filename.\n");
|
fprintf (stderr, "Error: Cannot get message filename.\n");
|
||||||
goto DONE;
|
goto DONE;
|
||||||
|
@ -1266,6 +1281,7 @@ notmuch_show_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
sprinter_t *sprinter;
|
sprinter_t *sprinter;
|
||||||
notmuch_show_params_t params = {
|
notmuch_show_params_t params = {
|
||||||
.part = -1,
|
.part = -1,
|
||||||
|
.duplicate = 0,
|
||||||
.omit_excluded = true,
|
.omit_excluded = true,
|
||||||
.output_body = true,
|
.output_body = true,
|
||||||
.crypto = { .decrypt = NOTMUCH_DECRYPT_AUTO },
|
.crypto = { .decrypt = NOTMUCH_DECRYPT_AUTO },
|
||||||
|
@ -1306,6 +1322,7 @@ notmuch_show_command (notmuch_database_t *notmuch, int argc, char *argv[])
|
||||||
{ .opt_bool = ¶ms.crypto.verify, .name = "verify" },
|
{ .opt_bool = ¶ms.crypto.verify, .name = "verify" },
|
||||||
{ .opt_bool = ¶ms.output_body, .name = "body" },
|
{ .opt_bool = ¶ms.output_body, .name = "body" },
|
||||||
{ .opt_bool = ¶ms.include_html, .name = "include-html" },
|
{ .opt_bool = ¶ms.include_html, .name = "include-html" },
|
||||||
|
{ .opt_int = ¶ms.duplicate, .name = "duplicate" },
|
||||||
{ .opt_inherit = notmuch_shared_options },
|
{ .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 */
|
/* specifying a part implies single message display */
|
||||||
single_message = params.part >= 0;
|
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 (format == NOTMUCH_FORMAT_NOT_SPECIFIED) {
|
||||||
/* if part was requested and format was not specified, use format=raw */
|
/* if part was requested and format was not specified, use format=raw */
|
||||||
if (params.part >= 0)
|
if (params.part >= 0)
|
||||||
|
|
|
@ -64,4 +64,15 @@ for pow in {10..20}; do
|
||||||
test_expect_success "notmuch show --format=raw subject:$size > /dev/null"
|
test_expect_success "notmuch show --format=raw subject:$size > /dev/null"
|
||||||
done
|
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
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue