From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id H0+SMPDS7GDF9AAAgWs5BA (envelope-from ) for ; Tue, 13 Jul 2021 01:40:32 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id gJukK/DS7GATcAAA1q6Kng (envelope-from ) for ; Mon, 12 Jul 2021 23:40:32 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (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 2A9641B27C for ; Tue, 13 Jul 2021 01:40:32 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id A9767290B4; Mon, 12 Jul 2021 19:40:27 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 42AA829058 for ; Mon, 12 Jul 2021 19:40:25 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 190075FD21; Mon, 12 Jul 2021 19:40:25 -0400 (EDT) Received: (nullmailer pid 107582 invoked by uid 1000); Mon, 12 Jul 2021 23:40:24 -0000 From: David Bremner To: Hannu Hartikainen , notmuch@notmuchmail.org Subject: Re: [PATCH v3 1/2] cli/show: add --format=pretty In-Reply-To: <20210712083821.442587-2-hannu@hrtk.in> References: <20210702203153.47289-1-hannu@hrtk.in> <20210622123410.323216-1-hannu@hrtk.in> <20210712083821.442587-1-hannu@hrtk.in> <20210712083821.442587-2-hannu@hrtk.in> Date: Mon, 12 Jul 2021 20:40:24 -0300 Message-ID: <87bl7785jr.fsf@tethera.net> MIME-Version: 1.0 Message-ID-Hash: X76XEEAEY7TMDSNAZAIAXP3MTF7LXOFD X-Message-ID-Hash: X76XEEAEY7TMDSNAZAIAXP3MTF7LXOFD X-MailFrom: david@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; suspicious-header CC: Hannu Hartikainen X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1626133232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc: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-unsubscribe:list-subscribe:list-post; bh=QaCFKfDdDwNvPNlCO52p77SXEmxVDgMKkJag+b+knec=; b=L8bp+TowuDsAbrGuJ+8jVFWfPhScnv4DBAKz1Sm9MKq0IEIk7GIeFmF3VM/5jQ8GRg/RGd u+L3cZBwDqC+rNpEtNTIVP0uYU7mvqTDwoUOhxisqINZR6QnjEV6bqxOhGLsGz2lgpLV+t kw5LMu0w8AcOfFtqY63uLijG0uXqkhx8ZeLWj0k+NrcCXtZlH7dZsY94bqk1TqBxn2eHZy 9+FDIl4DkYvEMfcClaRWMntcAFgdImCJn1730LKuUzHBk+7NMa7RTjA+Vzr/maNTDRlH9A 0OfOAUtdjAgZufGrjJb+xpwKAC9q40n7EYSx3MCuLnfZJAoz24WJDKJfUup4wA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626133232; a=rsa-sha256; cv=none; b=dhow523H4zX0VXI4UPzSXNONT5LLpjO+Fz5ayKpAIjgTgEsY2YkzJKuxkygSlERaSF6Rhp YChZ3J69ElsA8b9NjpYkm/qQq/LYtDkc6VavO4VGVC5YEYc19jbbKZBFckGffLCP3KrAlQ /5lVnetvEXhp35wXttb/zktuYx+rqf8FeuvHDruAuUeFPdf3DyHYnazOsGIc+Ngw5S+HoV Y5L5Qf9cFrnC1xEB1ve4nKgsy3QzNg4+Dgje3lvXsiK8XLoTf+grxURigGEh7XMjsbdHR+ 6qVm/HvM5QVdmqmTbmD4UpiQ6WlmPIKgxrCq3tMGH6xfX0W07wqjN8RgChdldQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -2.08 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 2A9641B27C X-Spam-Score: -2.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: fwT+6axVuobo Hannu Hartikainen writes: > +static notmuch_status_t > +format_part_pretty (const void *ctx, sprinter_t *sp, mime_node_t *node, > + int indent, const notmuch_show_params_t *params) > +{ > + /* The disposition and content-type metadata are associated with > + * the envelope for message parts */ > + GMimeObject *meta = node->envelope_part ? ( > + GMIME_OBJECT (node->envelope_part) ) : node->part; > + GMimeContentType *content_type = g_mime_object_get_content_type (meta); > + GMimeStream *stream = params->out_stream; > + int i; > + > + if (GMIME_IS_MESSAGE (node->part)) { > + GMimeMessage *message = GMIME_MESSAGE (node->part); > + char *recipients_string; > + char *date_string; > + > + g_mime_stream_printf (stream, "Subject: %s\n", g_mime_message_get_subject (message)); > + g_mime_stream_printf (stream, "From: %s\n", g_mime_message_get_from_string (message)); > + recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_TO); > + if (recipients_string) > + g_mime_stream_printf (stream, "To: %s\n", recipients_string); > + g_free (recipients_string); > + recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_CC); > + if (recipients_string) > + g_mime_stream_printf (stream, "Cc: %s\n", recipients_string); > + g_free (recipients_string); > + date_string = g_mime_message_get_date_string (node, message); > + g_mime_stream_printf (stream, "Date: %s\n", date_string); > + g_mime_stream_printf (stream, "Message-ID: <%s>\n\n", g_mime_message_get_message_id ( > + message)); I don't know what g_mime_message_get_message_id will return if there is no message-id, but that case can and does arise. Notmuch constructs a message-id by sha1 hashing the message. That message-id is in the database, so I think you should probably print out the message-id from the database. > +static const notmuch_show_format_t format_pretty = { > + .new_sprinter = sprinter_text_create, > + .part = format_part_pretty, > +}; I think this deserves a comment to explain briefly why it works. > diff --git a/test/T520-show.sh b/test/T520-show.sh > index 6f42ca12..c9bcf81d 100755 > --- a/test/T520-show.sh > +++ b/test/T520-show.sh > @@ -27,4 +27,36 @@ notmuch show --entire-thread=true --sort=newest-first $QUERY > EXPECTED > notmuch show --entire-thread=true --sort=oldest-first $QUERY > OUTPUT > test_expect_equal_file EXPECTED OUTPUT > > +test_begin_subtest "--format=pretty" > +output=$(notmuch show --format=pretty id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com 2>&1 && echo OK) > +test_expect_equal "$output" "Subject: [notmuch] preliminary FreeBSD support > +From: Alex Botero-Lowry > +To: notmuch@notmuchmail.org > +Date: Tue, 17 Nov 2009 11:36:14 -0800 > +Message-ID: > + I would prefer the cat < EXPECTED ... EOF style here rather then the multiline strings, finishing with "test_expect_equal_file EXPECTED OUTPUT".