X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.c;h=98c0bf377553b00cb8d3232e1bb5353bf3ab8d17;hp=201910841e717292f3973967c560fafe4c49f09b;hb=d4c4318fb95ba2ed86823389cf82b11a2bcae073;hpb=ab317ca474d2e6bade79eebc00c5e548b8df0c24 diff --git a/notmuch.c b/notmuch.c index 20191084..98c0bf37 100644 --- a/notmuch.c +++ b/notmuch.c @@ -899,11 +899,14 @@ _get_one_line_summary (void *ctx, notmuch_message_t *message) } static void -show_message_part (GMimeObject *part) +show_message_part (GMimeObject *part, int *part_count) { GMimeStream *stream; GMimeDataWrapper *wrapper; GMimeContentDisposition *disposition; + GMimeContentType *content_type; + + *part_count = *part_count + 1; if (GMIME_IS_MULTIPART (part)) { GMimeMultipart *multipart = GMIME_MULTIPART (part); @@ -917,7 +920,8 @@ show_message_part (GMimeObject *part) if (i > 1) 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; } @@ -927,7 +931,8 @@ show_message_part (GMimeObject *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; } @@ -943,19 +948,35 @@ show_message_part (GMimeObject *part) strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) { const char *filename = g_mime_part_get_filename (GMIME_PART (part)); + content_type = g_mime_object_get_content_type (GMIME_OBJECT (part)); + + printf ("%%attachment{ ID: %d, Content-type: %s, ", + *part_count, + g_mime_content_type_to_string (content_type)); + printf ("Filename: %s ", filename); + printf ("%%attachment}\n"); - /* XXX: Need to print content type here as well. */ - printf ("%%attachment{ %s %%attachment}\n", filename); return; } - /* Stream the MIME part out to stdout. */ - stream = g_mime_stream_file_new (stdout); - g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream), FALSE); + content_type = g_mime_object_get_content_type (GMIME_OBJECT (part)); + + printf ("%%part{ ID: %d, Content-type: %s\n", + *part_count, + g_mime_content_type_to_string (content_type)); + + if (g_mime_content_type_is_type (content_type, "text", "*") && + !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)); + if (wrapper) + g_mime_data_wrapper_write_to_stream (wrapper, stream); + } - wrapper = g_mime_part_get_content_object (GMIME_PART (part)); - if (wrapper) - g_mime_data_wrapper_write_to_stream (wrapper, stream); + printf ("%%part}\n"); g_object_unref (stream); } @@ -969,6 +990,7 @@ show_message_body (const char *filename) notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; static int initialized = 0; FILE *file = NULL; + int part_count = 0; if (! initialized) { g_mime_init (0); @@ -989,7 +1011,8 @@ show_message_body (const char *filename) 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: if (mime_message)