notmuch show: Don't print non-text MIME parts.

Additionally, print a part number for each MIME part so that the
client could (conceivably) ask for the contents of a specific
part by part number.
This commit is contained in:
Carl Worth 2009-11-02 14:33:15 -08:00
parent 6a7f4df6f7
commit 8ff934803c

View file

@ -899,13 +899,15 @@ _get_one_line_summary (void *ctx, notmuch_message_t *message)
} }
static void static void
show_message_part (GMimeObject *part) show_message_part (GMimeObject *part, int *part_count)
{ {
GMimeStream *stream; GMimeStream *stream;
GMimeDataWrapper *wrapper; GMimeDataWrapper *wrapper;
GMimeContentDisposition *disposition; GMimeContentDisposition *disposition;
GMimeContentType *content_type; GMimeContentType *content_type;
*part_count = *part_count + 1;
if (GMIME_IS_MULTIPART (part)) { if (GMIME_IS_MULTIPART (part)) {
GMimeMultipart *multipart = GMIME_MULTIPART (part); GMimeMultipart *multipart = GMIME_MULTIPART (part);
int i; int i;
@ -918,7 +920,8 @@ show_message_part (GMimeObject *part)
if (i > 1) if (i > 1)
fprintf (stderr, "Warning: Unexpected extra parts of mutlipart/signed. Continuing.\n"); fprintf (stderr, "Warning: Unexpected extra parts of mutlipart/signed. Continuing.\n");
} }
show_message_part (g_mime_multipart_get_part (multipart, i)); show_message_part (g_mime_multipart_get_part (multipart, i),
part_count);
} }
return; return;
} }
@ -928,7 +931,8 @@ show_message_part (GMimeObject *part)
mime_message = g_mime_message_part_get_message (GMIME_MESSAGE_PART (part)); mime_message = g_mime_message_part_get_message (GMIME_MESSAGE_PART (part));
show_message_part (g_mime_message_get_mime_part (mime_message)); show_message_part (g_mime_message_get_mime_part (mime_message),
part_count);
return; return;
} }
@ -946,26 +950,31 @@ show_message_part (GMimeObject *part)
const char *filename = g_mime_part_get_filename (GMIME_PART (part)); const char *filename = g_mime_part_get_filename (GMIME_PART (part));
content_type = g_mime_object_get_content_type (GMIME_OBJECT (part)); content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
printf ("%%attachment{ Content-type: %s\n", printf ("%%attachment{ ID: %d, Content-type: %s, ",
*part_count,
g_mime_content_type_to_string (content_type)); g_mime_content_type_to_string (content_type));
printf ("%s\n", filename); printf ("Filename: %s ", filename);
printf ("%%attachment}\n"); printf ("%%attachment}\n");
return; return;
} }
/* Stream the MIME part out to stdout. */
content_type = g_mime_object_get_content_type (GMIME_OBJECT (part)); content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
printf ("%%part{ Content-type: %s\n", printf ("%%part{ ID: %d, Content-type: %s\n",
*part_count,
g_mime_content_type_to_string (content_type)); g_mime_content_type_to_string (content_type));
stream = g_mime_stream_file_new (stdout); if (g_mime_content_type_is_type (content_type, "text", "*") &&
g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream), FALSE); !g_mime_content_type_is_type (content_type, "text", "html"))
{
stream = g_mime_stream_file_new (stdout);
g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream), FALSE);
wrapper = g_mime_part_get_content_object (GMIME_PART (part)); wrapper = g_mime_part_get_content_object (GMIME_PART (part));
if (wrapper) if (wrapper)
g_mime_data_wrapper_write_to_stream (wrapper, stream); g_mime_data_wrapper_write_to_stream (wrapper, stream);
}
printf ("%%part}\n"); printf ("%%part}\n");
@ -981,6 +990,7 @@ show_message_body (const char *filename)
notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
static int initialized = 0; static int initialized = 0;
FILE *file = NULL; FILE *file = NULL;
int part_count = 0;
if (! initialized) { if (! initialized) {
g_mime_init (0); g_mime_init (0);
@ -1001,7 +1011,8 @@ show_message_body (const char *filename)
mime_message = g_mime_parser_construct_message (parser); mime_message = g_mime_parser_construct_message (parser);
show_message_part (g_mime_message_get_mime_part (mime_message)); show_message_part (g_mime_message_get_mime_part (mime_message),
&part_count);
DONE: DONE:
if (mime_message) if (mime_message)