Re: [gmime-devel] Extract body with gmime



Hi Matteo,

>>>>> "Matteo" == Matteo Ghezzi <tenyosama gmail com> writes:

    Matteo> Now I need to extract only the body of the message, leaving out
    Matteo> the header, the attachments, and everything that is not plain text
    Matteo> or html text.  I'm a little lost in the api... any help is much
    Matteo> appreciated.

I'm not sure there is a 100% agreed-upon definition of what defines a body
(even though in 99% of the mails it's pretty clear). Anyway, when you define
the 'body' of a message as 'the first mime-part of type text/plain or
text/html which is not an attachment', you can use g_mime_message_foreach.

Ie., in pseudo code:

struct BodyData {
       GMimeObject *body;
};

static void 
find_body_cb  (GMimeObject *parent, GMimeObject *part, BodyData *data)
{
	if ((content type is text/plain or text/html) and
	    (it's not an attachment))
	    	  data->body = part;
}


Now, you could get the body part with something like:

struct BodyData bdata;
bdata.body = NULL;
g_mime_message_foreach (msg, find_body_cb, &bdata);
if (!bdata)
   g_printerr ("body not found!")
else
   /* we found the body */
	
And from the body you can retrieve the data (using a GMimeDataWrapper, writing
to a mremstream, and then from the memstream to a char*.


It'd indeed be nice to have a g mime_message_get_body (msg) :-)


Best wishes,
Dirk.

-- 
Dirk-Jan C. Binnema                  Helsinki, Finland
e:djcb djcbsoftware nl           w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]