[PATCH] util: add utility routine to dump the structure of a gmime part

Jani Nikula jani at nikula.org
Sun Aug 20 06:04:14 PDT 2017


On Mon, 22 May 2017, David Bremner <david at tethera.net> wrote:
> For debugging. From the gmime 3.0 test suite.
> ---
>
> I'm not sure this is really in the source tree, but I remember
> rumblings from Jani about maybe providing some kind of C equivalent
> for the python printmimestructure script. So in case this proves
> useful to someone, here it is.

I've got an implementation that adds a MIME structure display option to
'notmuch show'. I self-bikeshedded the output format long enough that it
doesn't cleanly rebase on top of current git master anymore. Perhaps
I'll get it rebased one of these days...

BR,
Jani.


>
> util/gmime-extra.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
>  util/gmime-extra.h |  2 ++
>  2 files changed, 51 insertions(+)
>
> diff --git a/util/gmime-extra.c b/util/gmime-extra.c
> index 81f3fce9..d1c55623 100644
> --- a/util/gmime-extra.c
> +++ b/util/gmime-extra.c
> @@ -1,5 +1,54 @@
>  #include "gmime-extra.h"
>  
> +static void
> +print_mime_part_info (const char *path, GMimeObject *object)
> +{
> +    const GMimeContentType *type;
> +    gboolean has_md5;
> +
> +    type = g_mime_object_get_content_type (object);
> +
> +    if (GMIME_IS_PART (object))
> +	has_md5 = g_mime_object_get_header (object, "Content-Md5") != NULL;
> +    else
> +	has_md5 = FALSE;
> +
> +    fprintf (stdout, "%s\t%s/%s%s", path,
> +	     type->type, type->subtype, has_md5 ? "; md5sum=" : "\n");
> +
> +    if (has_md5) {
> +	/* validate the Md5 sum */
> +	if (g_mime_part_verify_content_md5 ((GMimePart *) object))
> +	    fprintf (stdout, "GOOD\n");
> +	else
> +	    fprintf (stdout, "BAD\n");
> +    }
> +}
> +
> +void
> +g_mime_object_print_struct (GMimeObject *part)
> +{
> +    GMimePartIter *iter;
> +    GMimeObject *parent;
> +    char *path;
> +
> +    iter = g_mime_part_iter_new (part);
> +    if (g_mime_part_iter_is_valid (iter)) {
> +	if ((parent = g_mime_part_iter_get_parent (iter)))
> +	    print_mime_part_info ("TEXT", parent);
> +
> +	do {
> +	    part = g_mime_part_iter_get_current (iter);
> +	    path = g_mime_part_iter_get_path (iter);
> +	    print_mime_part_info (parent ? path : "TEXT", part);
> +	    g_free (path);
> +	} while (g_mime_part_iter_next (iter));
> +
> +    }
> +
> +    g_mime_part_iter_free (iter);
> +}
> +
>  GMimeStream *
>  g_mime_stream_stdout_new()
>  {
> diff --git a/util/gmime-extra.h b/util/gmime-extra.h
> index eb28cf06..2300dfb0 100644
> --- a/util/gmime-extra.h
> +++ b/util/gmime-extra.h
> @@ -4,6 +4,8 @@
>  
>  GMimeStream *g_mime_stream_stdout_new(void);
>  
> +void g_mime_object_print_struct(GMimeObject *part);
> +
>  #include <talloc.h>
>  
>  
> -- 
> 2.11.0


More information about the notmuch mailing list