From: David Bremner <david@tethera.net>
To: Hannu Hartikainen <hannu@hrtk.in>, notmuch@notmuchmail.org
Cc: Hannu Hartikainen <hannu@hrtk.in>
Subject: Re: [PATCH v3 1/2] cli/show: add --format=pretty
Date: Mon, 12 Jul 2021 20:40:24 -0300 [thread overview]
Message-ID: <87bl7785jr.fsf@tethera.net> (raw)
In-Reply-To: <20210712083821.442587-2-hannu@hrtk.in>
Hannu Hartikainen <hannu@hrtk.in> 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 <alex.boterolowry@gmail.com>
> +To: notmuch@notmuchmail.org
> +Date: Tue, 17 Nov 2009 11:36:14 -0800
> +Message-ID: <cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com>
> +
I would prefer the
cat <<EOF > EXPECTED
...
EOF
style here rather then the multiline strings, finishing with
"test_expect_equal_file EXPECTED OUTPUT".
next prev parent reply other threads:[~2021-07-12 23:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-19 20:38 [PATCH] cli/show: add --format=pretty Hannu Hartikainen
2021-06-22 12:34 ` [PATCH] cli/show: add --color/--no-color Hannu Hartikainen
2021-07-12 8:38 ` Yet another revision of --format=pretty Hannu Hartikainen
2021-07-12 8:38 ` [PATCH v3 1/2] cli/show: add --format=pretty Hannu Hartikainen
2021-07-12 23:40 ` David Bremner [this message]
2021-07-13 10:24 ` David Bremner
2021-07-13 11:50 ` Hannu Hartikainen
2021-07-12 8:38 ` [PATCH v3 2/2] cli/show: add color for --format=pretty Hannu Hartikainen
2021-07-12 23:19 ` Yet another revision of --format=pretty David Bremner
2021-07-13 12:07 ` Hannu Hartikainen
2021-07-02 20:31 ` [PATCH v2] cli/show: add --format=pretty Hannu Hartikainen
2021-07-04 9:40 ` Tomi Ollila
2021-07-04 11:54 ` Hannu Hartikainen
2021-07-04 14:38 ` [PATCH] " David Bremner
2021-07-05 13:31 ` Hannu Hartikainen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bl7785jr.fsf@tethera.net \
--to=david@tethera.net \
--cc=hannu@hrtk.in \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).