Re: [gmime-devel] resetting stream after g_mime_object_write_to_stream
- From: Oliver Giles <ogtifs gmail com>
- To: Jeffrey Stedfast <fejj gnome org>
- Cc: gmime-devel-list gnome org
- Subject: Re: [gmime-devel] resetting stream after g_mime_object_write_to_stream
- Date: Wed, 21 Aug 2013 11:45:53 +0003
Hi Jeff,
Thank you for your reply, the earlier call to g_mime_stream_reset was
just what I needed.
Regards,
Oliver
On Wed, Aug 21, 2013 at 2:24 , Jeffrey Stedfast <fejj gnome org> wrote:
Hi Oliver,
I've just fixed this in git master...
[more below]
On 8/20/2013 3:03 PM, Oliver Giles wrote:
I'm using gmime-2.6 on Arch Linux to manipulate a basic multipart
file. Under a particular combination of actions I am no longer able
to read data from the streams obtained from the content objects of
individual parts:
#include <gmime/gmime.h>
#include <stdio.h>
#include <errno.h>
static void each_part(GMimeObject *up, GMimeObject *part, gpointer
user_data) {
if(GMIME_IS_PART(part)) {
GMimeDataWrapper* dw =
g_mime_part_get_content_object(GMIME_PART(part));
GMimeStream* ms = g_mime_data_wrapper_get_stream(dw);
In the meantime, you can put a g_mime_stream_reset() right here.
gint64 l = g_mime_stream_length(ms);
char* s = malloc(g_mime_stream_length(ms));
also, if the content stream is encoded (check
g_mime_data_wrapper_get_encoding()), then the content you get back
will be base64 or quoted-printable and not really readable.
What you really want to do here is use
g_mime_data_wrapper_write_to_stream() so that it gets decoded.
This would actually avoid your issue because
g_mime_data_wrapper_write_to_stream() resets the stream before and
after writing the data.
If you want the content to be in a memory buffer, you can use a
GMimeStreamMem and then just dereference the GByteArray buffer that
backs the GMimeStreamMem.
gint64 r = g_mime_stream_read(ms, s, l);
g_mime_stream_reset(ms);
printf("content object is %lld bytes long, read %lld bytes (%s)\n",
l, r, strerror(errno));
errno = 0;
}
}
Hope that helps,
Jeff
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]