From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4Kc2BTJrv2LpWwEAbAwnHQ (envelope-from ) for ; Fri, 01 Jul 2022 23:46:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 4BoPBTJrv2KjwAAA9RJhRA (envelope-from ) for ; Fri, 01 Jul 2022 23:46:26 +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 CD85E417D0 for ; Fri, 1 Jul 2022 23:46:25 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 21B8A5F816; Fri, 1 Jul 2022 21:46:04 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 43FC05F807 for ; Fri, 1 Jul 2022 21:46:00 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 54FF15FC11; Fri, 1 Jul 2022 17:45:58 -0400 (EDT) Received: (nullmailer pid 462210 invoked by uid 1000); Fri, 01 Jul 2022 21:45:50 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 4/9] CLI/show: initial support for --duplicate for (raw output only) Date: Fri, 1 Jul 2022 18:45:43 -0300 Message-Id: <20220701214548.461943-5-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: JS2CAGZQNR4B6LZOIR4QB2DDFM466RNP X-Message-ID-Hash: JS2CAGZQNR4B6LZOIR4QB2DDFM466RNP 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=1656711985; 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=xFlGaIh9A+QyfabKQQ0R6fOEDbT6oF/27DUUFYJrV+M=; b=F+Or4yav/1Zc/b1vnGqazkT41XsRX+uDF/eFZ6w7/FVFjDz3jdTerB84H/+e6Ci6QzazmN qLED7EU5UvhqdsvR26zNvZDiKrsJodOCdQZnRtPWaw0L2t3/dTpsS3tNgxzC1l7ZRMXjdI +cQwqh1PyUwwRzFMjpPV+oYlAxqQpr9NuPucPdNpyGRJvWidAocm1mbrxFQjFAqyZJleaq hAyGZBr7um1hKWecpoBcb7NmG1mEmm2bjk+bDAkpT4gTGUE88TegRDRRGY10fjDVjLeAb8 +DcL9kVnIoY2uiGgh6u3P46VJkvzER/UJdaV33O/tFlw3h6SP9WBQC+5YzqRuA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1656711985; a=rsa-sha256; cv=none; b=goXXGCbxexMeYg+xEmQl75/z0OD7UCpqT8Juekz3dqCRSgTSynZXB6WSxtEyk5HSk5bWsX DWYk3dklFqFHZ53o2jc08EGul6Bs+s9xDokUJznTKRTaxPnAbmaZ8opi7bVkxnZUW6I4hj SRSclLbJrJRZrtBREcaocf+kiCLT+vOqlQgaiqXpYtNCBXJYbzXlzAUGhS7Ha2m9coJpjt 6Wq35MYQ6RyXrY4f0O1bd0HPkSnWhcfn1C3QKfinvNRORFT0dAbihj1Jgg4zTmyAm82QD7 tQU11ZD2c3y1xMSy292M/+ljcd8e6c3czG2/aqVoe5I0Y8ER0NruaOqJb3TXdA== 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.70 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: CD85E417D0 X-Spam-Score: -1.70 X-Migadu-Scanner: scn0.migadu.com X-TUID: KlX4oO57kw8C 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 | 6 ++++++ notmuch-client.h | 1 + notmuch-show.c | 21 ++++++++++++++++++++- test/T210-raw.sh | 11 +++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst index 55353921..2c0a0de6 100644 --- a/doc/man1/notmuch-show.rst +++ b/doc/man1/notmuch-show.rst @@ -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 ` + .. option:: --entire-thread=(true|false) If true, **notmuch show** outputs all messages in the thread of 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 = ¶ms.crypto.verify, .name = "verify" }, { .opt_bool = ¶ms.output_body, .name = "body" }, { .opt_bool = ¶ms.include_html, .name = "include-html" }, + { .opt_int = ¶ms.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..44082028 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 +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 -- 2.35.2