Re: [gmime-devel] g_mime_message_foreach_part does not recurse
- From: djcb <djcb bulk gmail com>
- To: Jeffrey Stedfast <fejj novell com>
- Cc: "gmime-devel-list gnome org" <gmime-devel-list gnome org>
- Subject: Re: [gmime-devel] g_mime_message_foreach_part does not recurse
- Date: Sun, 7 Sep 2008 11:51:31 +0300
Hi Jeffrey,
Thanks for the quick reply.
On Sat, 06 Sep 2008, Jeffrey Stedfast wrote:
> On Sat, 2008-09-06 at 14:11 +0300, djcb wrote:
> > Hi,
> >
> > I am writing a maildir index & search program, and I use GMime for
> > parsing the messages. I try to determine the message body using
> > g_mime_message_foreach_part. However, it seems that function only gets
> > the parts on the current level, and does not recurse. Is that expected
> > behaviour. Maybe it should be documented?
>
> The foreach functions (g_mime_message_foreach and
> g_mime_multipart_foreach) weren't designed to be recursive, however I
> can understand how it could be confusing and that my docs could
> certainly use some clarification.
>
> For now, the solution is to check the GMimeObject type in the foreach
> callback function and if the part is a multipart, call
> g_mime_multipart_foreach() on it.
>
> In the meantime, I'll think about changing the behavior of the foreach
> functions for the next stable series.
Yup; I wrote something like below for my app (GPL), maybe it would be a
useful starting point; I am using the 2.2 API though.
static void
mu_g_mime_multipart_foreach_recursive (GMimeMultipart *multipart,
GMimePartFunc callback,
gpointer data)
{
guint i;
g_return_if_fail (GMIME_IS_MULTIPART(multipart));
g_return_if_fail (callback != NULL);
for (i = 0; i < g_mime_multipart_get_number(multipart); ++i) {
GMimeObject *part;
part = g_mime_multipart_get_part (multipart, i);
callback (part, data);
if (GMIME_IS_MULTIPART(part))
mu_g_mime_multipart_foreach_recursive
(GMIME_MULTIPART(part), callback, data);
g_object_unref (part);
}
}
static void
mu_g_mime_message_foreach_part_recursive (GMimeMessage* message,
GMimePartFunc callback,
gpointer data)
{
g_return_if_fail (GMIME_IS_MESSAGE(message));
g_return_if_fail (callback != NULL);
if (GMIME_IS_MULTIPART(message->mime_part))
mu_g_mime_multipart_foreach_recursive
(GMIME_MULTIPART (message->mime_part),
callback, data);
else
callback (message->mime_part, data);
}
Best wishes,
Dirk.
--
-----------------------------------------------
Dirk-Jan C. Binnema <djcb djcbsoftware nl>
blog: http://www.djcbsoftware.nl/ChangeLog (NL)
http://djcbflux.blogspot.com (EN)
chat: djcb jabber org
-----------------------------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]