From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 37DA26DE0314 for ; Mon, 22 May 2017 17:41:40 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.001 X-Spam-Level: X-Spam-Status: No, score=-0.001 tagged_above=-999 required=5 tests=[AWL=0.010, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IY_PxceBOcHk for ; Mon, 22 May 2017 17:41:39 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id D412E6DE0191 for ; Mon, 22 May 2017 17:41:38 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1dCxsN-00069c-II; Mon, 22 May 2017 20:40:39 -0400 Received: (nullmailer pid 15141 invoked by uid 1000); Tue, 23 May 2017 00:41:33 -0000 From: David Bremner To: notmuch@notmuchmail.org, notmuch@freelists.org Subject: [PATCH] util: add utility routine to dump the structure of a gmime part Date: Mon, 22 May 2017 21:41:30 -0300 Message-Id: <20170523004130.15090-1-david@tethera.net> X-Mailer: git-send-email 2.11.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 May 2017 00:41:40 -0000 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. 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 -- 2.11.0