[Commits] [SCM] claws branch, master, updated. 3.17.3-123-g38c6e6f
ticho at claws-mail.org
ticho at claws-mail.org
Tue Mar 5 23:00:34 CET 2019
The branch, master has been updated
via 38c6e6f776c906514f5fbeec5259dc9d8382d96b (commit)
from fde39ef20d6cdb37b1863227cafe61aa412ec07a (commit)
Summary of changes:
src/procmime.c | 32 +++++++++++++++++++++++++++++---
src/procmime.h | 7 ++++++-
2 files changed, 35 insertions(+), 4 deletions(-)
- Log -----------------------------------------------------------------
commit 38c6e6f776c906514f5fbeec5259dc9d8382d96b
Author: Andrej Kacian <ticho at claws-mail.org>
Date: Tue Mar 5 22:59:10 2019 +0100
Write procmime_get_part_as_inputstream()
We also change procmime_get_part_as_string() to return
a void* instead of a gchar*, and add an option to not
null-terminate the returned buffer.
diff --git a/src/procmime.c b/src/procmime.c
index e18215f..6c682a6 100644
--- a/src/procmime.c
+++ b/src/procmime.c
@@ -2662,7 +2662,8 @@ gchar *procmime_get_part_file_name(MimeInfo *mimeinfo)
return base;
}
-gchar *procmime_get_part_as_string(MimeInfo *mimeinfo)
+void *procmime_get_part_as_string(MimeInfo *mimeinfo,
+ gboolean null_terminate)
{
FILE *infp;
gchar *data;
@@ -2689,7 +2690,8 @@ gchar *procmime_get_part_as_string(MimeInfo *mimeinfo)
}
length = mimeinfo->length;
- data = g_malloc(length + 1);
+
+ data = g_malloc(null_terminate ? length + 1 : length);
cm_return_val_if_fail(data != NULL, NULL);
readlength = claws_fread(data, length, 1, infp);
@@ -2702,8 +2704,32 @@ gchar *procmime_get_part_as_string(MimeInfo *mimeinfo)
claws_fclose(infp);
- data[length] = '\0';
+ if (null_terminate)
+ data[length] = '\0';
return data;
}
+/* Returns an open GInputStream. The caller should just
+ * read mimeinfo->length bytes from it and then release it. */
+GInputStream *procmime_get_part_as_inputstream(MimeInfo *mimeinfo,
+ GError **error)
+{
+ cm_return_val_if_fail(mimeinfo != NULL, NULL);
+
+ if (mimeinfo->encoding_type != ENC_BINARY &&
+ !procmime_decode_content(mimeinfo))
+ return NULL;
+
+ if (mimeinfo->content == MIMECONTENT_MEM) {
+ /* NULL for destroy func, since we're not copying
+ * the data for the stream. */
+ return g_memory_input_stream_new_from_data(
+ mimeinfo->data.mem,
+ mimeinfo->length, NULL);
+ } else {
+ return g_memory_input_stream_new_from_data(
+ procmime_get_part_as_string(mimeinfo, FALSE),
+ mimeinfo->length, g_free);
+ }
+}
diff --git a/src/procmime.h b/src/procmime.h
index ae8b0e6..b21dc94 100644
--- a/src/procmime.h
+++ b/src/procmime.h
@@ -24,6 +24,8 @@
#include "claws-features.h"
#endif
+#include <gio/gio.h>
+
#include "utils.h"
#include "proctypes.h"
typedef enum
@@ -238,7 +240,10 @@ FILE *procmime_get_binary_content(MimeInfo *mimeinfo);
gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
gboolean (*scan_callback)(const gchar *str, gpointer cb_data),
gpointer cb_data);
-gchar *procmime_get_part_as_string(MimeInfo *mimeinfo);
+void *procmime_get_part_as_string(MimeInfo *mimeinfo,
+ gboolean null_terminate);
+GInputStream *procmime_get_part_as_inputstream(MimeInfo *mimeinfo,
+ GError **error);
#ifdef __cplusplus
}
-----------------------------------------------------------------------
hooks/post-receive
--
Claws Mail
More information about the Commits
mailing list