static void format_part_reply (mime_node_t *node) { int i; if (node->envelope_file) { printf ("On %s, %s wrote:\n", notmuch_message_get_header (node->envelope_file, "date"), notmuch_message_get_header (node->envelope_file, "from")); } else if (GMIME_IS_MESSAGE (node->part)) { GMimeMessage *message = GMIME_MESSAGE (node->part); InternetAddressList *recipients; const char *recipients_string; printf ("> From: %s\n", g_mime_message_get_sender (message)); recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO); recipients_string = internet_address_list_to_string (recipients, 0); if (recipients_string) printf ("> To: %s\n", recipients_string); recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC); recipients_string = internet_address_list_to_string (recipients, 0); if (recipients_string) printf ("> Cc: %s\n", recipients_string); printf ("> Subject: %s\n", g_mime_message_get_subject (message)); printf ("> Date: %s\n", g_mime_message_get_date_as_string (message)); printf (">\n"); } else if (GMIME_IS_PART (node->part)) { GMimeContentType *content_type = g_mime_object_get_content_type (node->part); GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (node->part); if (g_mime_content_type_is_type (content_type, "application", "pgp-encrypted") || g_mime_content_type_is_type (content_type, "application", "pgp-signature")) { /* Ignore PGP/MIME cruft parts */ } else if (g_mime_content_type_is_type (content_type, "text", "*") && !g_mime_content_type_is_type (content_type, "text", "html")) { GMimeStream *stream_stdout = g_mime_stream_file_new (stdout); g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE); show_text_part_content (node->part, stream_stdout, NOTMUCH_SHOW_TEXT_PART_REPLY); g_object_unref(stream_stdout); } else if (disposition && strcasecmp (g_mime_content_disposition_get_disposition (disposition), GMIME_DISPOSITION_ATTACHMENT) == 0) { const char *filename = g_mime_part_get_filename (GMIME_PART (node->part)); printf ("Attachment: %s (%s)\n", filename, g_mime_content_type_to_string (content_type)); } else { printf ("Non-text part: %s\n", g_mime_content_type_to_string (content_type)); } } for (i = 0; i < node->nchildren; i++) format_part_reply (mime_node_child (node, i)); }
/** * Output a list of the parts included in the current message. */ void dump_mail( char *filename ) { std::string result; GMimeMessage *m_message; GMimeParser *parser; GMimeStream *stream; int fd; std::cout << "File: " << filename << std::endl; if ((fd = open( filename, O_RDONLY, 0)) == -1) { std::cout << "Opening failed ..." << std::endl; return; } stream = g_mime_stream_fs_new (fd); parser = g_mime_parser_new_with_stream (stream); g_object_unref (stream); m_message = g_mime_parser_construct_message (parser); g_object_unref (parser); /** * Create an iterator */ GMimePartIter *iter = g_mime_part_iter_new ((GMimeObject *) m_message); int count = 1; /** * Iterate over the message. */ do { GMimeObject *part = g_mime_part_iter_get_current (iter); if ( ( GMIME_IS_OBJECT( part ) ) && ( GMIME_IS_PART(part) ) ) { /** * Get the content-type */ GMimeContentType *content_type = g_mime_object_get_content_type (part); const char *filename = g_mime_object_get_content_disposition_parameter(part, "filename"); gchar *type = g_mime_content_type_to_string ( content_type ); std::cout << count << " " << type << std::endl; if ( filename ) std::cout << "\t[This is an attachment with file-name " << filename << "]" << std::endl; } /** * Highlight inline parts - which are not attachments. */ GMimeContentDisposition *disp = g_mime_object_get_content_disposition(part); if ( disp != NULL ) { const char *str = g_mime_content_disposition_get_disposition (disp); std::cout << "\tNOTE: Content-Disposition: " << str << std::endl; } count += 1; } while (g_mime_part_iter_next (iter)); g_mime_part_iter_free (iter); g_object_unref(m_message); }