This makes the text formatter take advantage of the new code
structure. The previously duplicated header logic is now unified,
several things that we used to compute repeatedly across different
callbacks are now computed once, and the code is simpler overall and
32% shorter.
Unifying the header logic causes this to format some dates slightly
differently, so the two affected test cases are updated.
GMimeObject *meta = node->envelope_part ?
GMIME_OBJECT (node->envelope_part) : node->part;
GMimeContentType *content_type = g_mime_object_get_content_type (meta);
GMimeObject *meta = node->envelope_part ?
GMIME_OBJECT (node->envelope_part) : node->part;
GMimeContentType *content_type = g_mime_object_get_content_type (meta);
+ const notmuch_bool_t leaf = GMIME_IS_PART (node->part);
+ const char *part_type;
int i;
if (node->envelope_file) {
notmuch_message_t *message = node->envelope_file;
int i;
if (node->envelope_file) {
notmuch_message_t *message = node->envelope_file;
- const char *headers[] = {
- "Subject", "From", "To", "Cc", "Bcc", "Date"
- };
- const char *name, *value;
- unsigned int i;
-
- printf ("\fmessage{ ");
- printf ("id:%s depth:%d match:%d filename:%s\n",
+
+ part_type = "message";
+ printf ("\f%s{ id:%s depth:%d match:%d filename:%s\n",
+ part_type,
notmuch_message_get_message_id (message),
indent,
notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH),
notmuch_message_get_filename (message));
notmuch_message_get_message_id (message),
indent,
notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH),
notmuch_message_get_filename (message));
-
- printf ("\fheader{\n");
-
- printf ("%s\n", _get_one_line_summary (ctx, message));
-
- for (i = 0; i < ARRAY_SIZE (headers); i++) {
- name = headers[i];
- value = notmuch_message_get_header (message, name);
- if (value && strlen (value))
- printf ("%s: %s\n", name, value);
- }
- printf ("\fheader}\n");
} else {
GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta);
const char *cid = g_mime_object_get_content_id (meta);
} else {
GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta);
const char *cid = g_mime_object_get_content_id (meta);
+ const char *filename = leaf ?
+ g_mime_part_get_filename (GMIME_PART (node->part)) : NULL;
if (disposition &&
strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
if (disposition &&
strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
- {
- printf ("\fattachment{ ID: %d", node->part_num);
-
- } else {
-
- printf ("\fpart{ ID: %d", node->part_num);
- }
-
- if (GMIME_IS_PART (node->part))
- {
- const char *filename = g_mime_part_get_filename (GMIME_PART (node->part));
- if (filename)
- printf (", Filename: %s", filename);
- }
+ part_type = "attachment";
+ else
+ part_type = "part";
+ printf ("\f%s{ ID: %d", part_type, node->part_num);
+ if (filename)
+ printf (", Filename: %s", filename);
if (cid)
printf (", Content-id: %s", cid);
if (cid)
printf (", Content-id: %s", cid);
printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
}
printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
}
- if (node->envelope_part) {
+ if (GMIME_IS_MESSAGE (node->part)) {
GMimeMessage *message = GMIME_MESSAGE (node->part);
InternetAddressList *recipients;
const char *recipients_string;
printf ("\fheader{\n");
GMimeMessage *message = GMIME_MESSAGE (node->part);
InternetAddressList *recipients;
const char *recipients_string;
printf ("\fheader{\n");
+ if (node->envelope_file)
+ printf ("%s\n", _get_one_line_summary (ctx, node->envelope_file));
printf ("Subject: %s\n", g_mime_message_get_subject (message));
printf ("From: %s\n", g_mime_message_get_sender (message));
recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
printf ("Subject: %s\n", g_mime_message_get_subject (message));
printf ("From: %s\n", g_mime_message_get_sender (message));
recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
printf ("Cc: %s\n", recipients_string);
printf ("Date: %s\n", g_mime_message_get_date_as_string (message));
printf ("\fheader}\n");
printf ("Cc: %s\n", recipients_string);
printf ("Date: %s\n", g_mime_message_get_date_as_string (message));
printf ("\fheader}\n");
+
+ printf ("\fbody{\n");
- if (!node->envelope_file) {
if (g_mime_content_type_is_type (content_type, "text", "*") &&
!g_mime_content_type_is_type (content_type, "text", "html"))
{
if (g_mime_content_type_is_type (content_type, "text", "*") &&
!g_mime_content_type_is_type (content_type, "text", "html"))
{
g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
show_text_part_content (node->part, stream_stdout);
g_object_unref(stream_stdout);
g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
show_text_part_content (node->part, stream_stdout);
g_object_unref(stream_stdout);
- }
- else if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
- g_mime_content_type_is_type (content_type, "message", "rfc822"))
- {
- /* Do nothing for multipart since its content will be printed
- * when recursing. */
- }
- else
- {
printf ("Non-text part: %s\n",
g_mime_content_type_to_string (content_type));
}
}
printf ("Non-text part: %s\n",
g_mime_content_type_to_string (content_type));
}
}
- if (GMIME_IS_MESSAGE (node->part))
- printf ("\fbody{\n");
-
for (i = 0; i < node->nchildren; i++)
format_part_text (ctx, mime_node_child (node, i), indent, params);
if (GMIME_IS_MESSAGE (node->part))
printf ("\fbody}\n");
for (i = 0; i < node->nchildren; i++)
format_part_text (ctx, mime_node_child (node, i), indent, params);
if (GMIME_IS_MESSAGE (node->part))
printf ("\fbody}\n");
- if (node->envelope_file) {
- printf ("\fmessage}\n");
- } else {
- GMimeContentDisposition *disposition;
-
- disposition = g_mime_object_get_content_disposition (meta);
- if (disposition &&
- strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
- {
- printf ("\fattachment}\n");
- }
- else
- {
- printf ("\fpart}\n");
- }
- }
+ printf ("\f%s}\n", part_type);
Subject: test encrypted message 001
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: test_suite@notmuchmail.org
Subject: test encrypted message 001
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: test_suite@notmuchmail.org
-Date: 01 Jan 2000 12:00:00 -0000
+Date: Sat, 01 Jan 2000 12:00:00 +0000
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: multipart/encrypted
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: multipart/encrypted
Subject: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Fri, 05 Jan 2001 15:43:56 -0000
+Date: Fri, 05 Jan 2001 15:43:56 +0000
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
Subject: thread-naming: Older changed subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: thread-naming: Older changed subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Sat, 06 Jan 2001 15:43:56 -0000
+Date: Sat, 06 Jan 2001 15:43:56 +0000
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
Subject: thread-naming: Newer changed subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: thread-naming: Newer changed subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Sun, 07 Jan 2001 15:43:56 -0000
+Date: Sun, 07 Jan 2001 15:43:56 +0000
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
Subject: thread-naming: Final thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: thread-naming: Final thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Mon, 08 Jan 2001 15:43:56 -0000
+Date: Mon, 08 Jan 2001 15:43:56 +0000
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
Subject: Re: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: Re: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Tue, 09 Jan 2001 15:43:45 -0000
+Date: Tue, 09 Jan 2001 15:43:45 +0000
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
Subject: Aw: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: Aw: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Wed, 10 Jan 2001 15:43:45 -0000
+Date: Wed, 10 Jan 2001 15:43:45 +0000
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
Subject: Vs: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: Vs: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Thu, 11 Jan 2001 15:43:45 -0000
+Date: Thu, 11 Jan 2001 15:43:45 +0000
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
Subject: Sv: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: Sv: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Fri, 12 Jan 2001 15:43:45 -0000
+Date: Fri, 12 Jan 2001 15:43:45 +0000
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain
\fheader}
\fbody{
\fpart{ ID: 1, Content-type: text/plain