From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id qE8xIoFPpmJfLAAAbAwnHQ (envelope-from ) for ; Sun, 12 Jun 2022 22:41:37 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id QEQTIoFPpmI6EgEAauVa8A (envelope-from ) for ; Sun, 12 Jun 2022 22:41:37 +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) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5F29C122BA for ; Sun, 12 Jun 2022 22:41:37 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 140395F5E3; Sun, 12 Jun 2022 20:41:34 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 7C0475F3FE for ; Sun, 12 Jun 2022 20:41:30 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id EA9C65FC0D; Sun, 12 Jun 2022 16:41:28 -0400 (EDT) Received: (nullmailer pid 3806105 invoked by uid 1000); Sun, 12 Jun 2022 19:05:03 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/4] CLI/show: WIP support --duplicate for raw output Date: Sun, 12 Jun 2022 16:04:57 -0300 Message-Id: <20220612190459.3804908-3-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220612190459.3804908-1-david@tethera.net> References: <20220612190459.3804908-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: CRLECG3KCWBTIEMP7NUEUHRZVZUAW3JY X-Message-ID-Hash: CRLECG3KCWBTIEMP7NUEUHRZVZUAW3JY 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=1655066497; 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=PmdIvU/9OTaBVCPSImcXf00BeeKWWHjVBvTO/e7YFBq7l4po7LWoUfrtIJDbwfW8ZLJbMF mugnLifJpyRIOrqgvTIA/FIb1I41vdL5mHJBly4P+B/vZVbh13bi8zID6wwzgul3yc4jQh Pg4BwNl71JeKtCbA5TxiQsLuP173xtRq7ra5zICEZlL00bhQwq3JFzh93Tt7Z3q503ihzY iabJT++xB+LYI1exmX+ENyIJK8W/jfwgTmLzYYbr6VVORY3UgutOM6NxhzRGvNGlhWpKSJ K469sXM6GvJGRboA0W3LHadhWe6//LvHfWY5DLZxYtf4NGKDnph61ikTDbSy7w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1655066497; a=rsa-sha256; cv=none; b=PuJYmgShkc1j6yKhNW0vGIgGrFV3BVRMDGAbJxWF5dl3wWzhoS59+fGs3R1KNcOjVMSaCQ pxX8xCLY3zrako4N60hY2k09a6dUpFxtBCLLcZwqAIdcWPw15D3NmsbNZ8RyT6RN9kNen2 QhF4Rp5Cr1RxWqg4teyChC5V17lv3+Osqv84x38y7fuIDfvmvGVmVj/zeHCX/Z5FUopnz0 oT1852BreGyluYcy+84Py+vwg/Twi74dELih6r5Gyf+K13ds1xWddCIy65Ip+d0fDuGBJu bhjpEMF5koIjdSLX2LpsQAfcTUfmBQqWJ2zufg9vtXB/GD7gv98V7aSbp4GiBw== 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.11 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: 5F29C122BA X-Spam-Score: -1.11 X-Migadu-Scanner: scn1.migadu.com X-TUID: RQdOvnek9N2g --- 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