* [PATCH] util: add utility routine to dump the structure of a gmime part
@ 2017-05-23 0:41 David Bremner
2017-08-20 13:04 ` Jani Nikula
0 siblings, 1 reply; 2+ messages in thread
From: David Bremner @ 2017-05-23 0:41 UTC (permalink / raw)
To: notmuch, notmuch
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] util: add utility routine to dump the structure of a gmime part
2017-05-23 0:41 [PATCH] util: add utility routine to dump the structure of a gmime part David Bremner
@ 2017-08-20 13:04 ` Jani Nikula
0 siblings, 0 replies; 2+ messages in thread
From: Jani Nikula @ 2017-08-20 13:04 UTC (permalink / raw)
To: David Bremner, notmuch, notmuch
On Mon, 22 May 2017, David Bremner <david@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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-08-20 13:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-23 0:41 [PATCH] util: add utility routine to dump the structure of a gmime part David Bremner
2017-08-20 13:04 ` Jani Nikula
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).