From: David Bremner <david@tethera.net>
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 [thread overview]
Message-ID: <20170523004130.15090-1-david@tethera.net> (raw)
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 +++++++++++++++++++++++++++++++++++++++++++++++++
| 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()
{
--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
next reply other threads:[~2017-05-23 0:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-23 0:41 David Bremner [this message]
2017-08-20 13:04 ` [PATCH] util: add utility routine to dump the structure of a gmime part Jani Nikula
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170523004130.15090-1-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@freelists.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).