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 OEooI+Kvr2JcrQAAbAwnHQ (envelope-from ) for ; Mon, 20 Jun 2022 01:23:14 +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 AMYHI+Kvr2IzDQAA9RJhRA (envelope-from ) for ; Mon, 20 Jun 2022 01:23:14 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 426A53F9D7 for ; Mon, 20 Jun 2022 01:23:14 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 31F845F7DC; Sun, 19 Jun 2022 23:22:45 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id C87F85F428 for ; Sun, 19 Jun 2022 23:22:42 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id E9DB05FBD7; Sun, 19 Jun 2022 19:22:41 -0400 (EDT) Received: (nullmailer pid 847101 invoked by uid 1000); Sun, 19 Jun 2022 23:22:33 -0000 From: David Bremner 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 Message-Id: <20220619232152.846823-5-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220619232152.846823-1-david@tethera.net> References: <20220619232152.846823-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: P3YI5H32ZY2WIJMPWOFGRI3DTMWQXVOW X-Message-ID-Hash: P3YI5H32ZY2WIJMPWOFGRI3DTMWQXVOW 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=1655680994; 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=LDiMH1B+hLocDD4kI+u72l5KdhcWNI7Zx3zpTYkBrKE=; b=fLEpafuMiIYGIxJLK4VDS0/cC5fumKgqXXlitJSH+OPMf9CMPI77ikfL5dx6wQqy4WwV2M JhycnwaB95h06OUvMLATJHkZJ8FiziRsbt96hB2TN45H4K7HXt+wSLaak2hUbsOxVQp1X6 QbuL2WLQCSr5+U8GhOdlyASmlhVRp92haIMlDK9chEzBuSO2JB9URVgAg0kbuA6aFsKMEj 0eNLIrber5Co48cuVKWdG7857Bfpj+2O9JYLLKONhq/7cUB25h6Vv+wZ2SQCCifi7fhosF 7GSx8360VCC3XRpucRaZcTGfOEOGIasizB2rFB2dXPq/EHDBP2xKtWk7rylVxQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1655680994; a=rsa-sha256; cv=none; b=VU6kfdRa6gdGNzDXXqlmfSsyVVZkQRGK525J2HQz1QNFA9HHVIGrRLuqdPecpYJgXIQNE6 ygqyXq+kwssqxeElikoh2mySL1K4V02mQqvb6Y6RDy/RkaC3rji4KZrHXhoazZAVGU7ejj gcbbqiyNCAcuC4tqDvvigYrvyul32jMq6ly8DZz1qjQY+6LwOlDI7QHPll9ZQw+TwxkRnV bYJLIifTnxA3XyxdJMsUv5KBbmla2laICvPZesyGeys5y7gneXavu095GvCS7O4IN1iGiN +MCpIB9vO21SlejV3cjCubRewJUdkRH2J753XFoA2RC69W1w8AlwS4rq1hjKxQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.62 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 426A53F9D7 X-Spam-Score: -1.62 X-Migadu-Scanner: scn0.migadu.com X-TUID: lh6rRNxy1b4h --- 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 = ¶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..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