aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-part.c
diff options
context:
space:
mode:
authorbertrand <Bertrand.Guiheneuf@aful.org>1999-08-26 23:29:40 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>1999-08-26 23:29:40 +0800
commite826255bf13255f2b5c626192de4fd10a3885b6f (patch)
tree7280cb551648d126c30162f28779503a9b1b6eeb /camel/camel-mime-part.c
parent2a912b33018b0389672d9a4f09496b6a57071388 (diff)
downloadgsoc2013-evolution-e826255bf13255f2b5c626192de4fd10a3885b6f.tar.gz
gsoc2013-evolution-e826255bf13255f2b5c626192de4fd10a3885b6f.tar.zst
gsoc2013-evolution-e826255bf13255f2b5c626192de4fd10a3885b6f.zip
contruct the content from the buffer before calling CamelMedium
1999-08-26 bertrand <Bertrand.Guiheneuf@aful.org> * camel/camel-mime-part.c (_get_content_object): contruct the content from the buffer before calling CamelMedium implementation. (_construct_from_stream): Do not construct the content by default, just store the content bytes in a temporary buffer. Content will be constructed only at caller request (when calling CamelMedium::get_content_object) Providers with better access to the messages (mbox/MH ...) will have to provider lighter implementation, that is shall not read content at all unless the caller asks for it (again with get_content). * camel/camel-mime-part-utils.c: new file, groups mime-part related utils. Meant to be used by providers subclassing MimeMessage. (camel_mime_part_construct_headers_from_stream): (camel_mime_part_construct_content_from_stream): no more useless temporary hash table. * camel/camel-mime-part.c (_construct_from_stream): calls mime-part-utils functions now. * camel/gmime-utils.c (_store_header_pair_from_string): do not use hash table to store header, use an array instead. svn path=/trunk/; revision=1145
Diffstat (limited to 'camel/camel-mime-part.c')
-rw-r--r--camel/camel-mime-part.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index ef01a54ba4..8f5255ccb4 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -29,7 +29,8 @@
#include "camel-log.h"
#include "gmime-utils.h"
#include "camel-simple-data-wrapper.h"
-
+#include "hash-table-utils.h"
+#include "camel-stream-mem.h"
typedef enum {
HEADER_UNKNOWN,
@@ -62,6 +63,7 @@ void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream
static void _add_header (CamelMedium *medium, gchar *header_name, gchar *header_value);
static void _set_content_object (CamelMedium *medium, CamelDataWrapper *content);
+static CamelDataWrapper *_get_content_object (CamelMedium *medium);
/* CamelMimePart methods */
static void _set_description (CamelMimePart *mime_part, const gchar *description);
@@ -93,7 +95,7 @@ static gboolean _parse_header_pair (CamelMimePart *mime_part, gchar *header_name
static void
_init_header_name_table()
{
- header_name_table = g_hash_table_new (g_str_hash, g_str_equal);
+ header_name_table = g_hash_table_new (g_strcase_hash, g_strcase_equal);
g_hash_table_insert (header_name_table, "Content-Description", (gpointer)HEADER_DESCRIPTION);
g_hash_table_insert (header_name_table, "Content-Disposition", (gpointer)HEADER_DISPOSITION);
g_hash_table_insert (header_name_table, "Content-id", (gpointer)HEADER_CONTENT_ID);
@@ -138,6 +140,7 @@ camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class)
/* virtual method overload */
camel_medium_class->add_header = _add_header;
camel_medium_class->set_content_object = _set_content_object;
+ camel_medium_class->get_content_object = _get_content_object;
camel_data_wrapper_class->write_to_stream = _write_to_stream;
camel_data_wrapper_class->construct_from_stream = _construct_from_stream;
@@ -159,6 +162,9 @@ camel_mime_part_init (gpointer object, gpointer klass)
camel_mime_part->encoding = NULL;
camel_mime_part->filename = NULL;
camel_mime_part->header_lines = NULL;
+
+ camel_mime_part->temp_message_buffer = NULL;
+
}
@@ -208,8 +214,9 @@ _finalize (GtkObject *object)
if (mime_part->encoding) g_free (mime_part->encoding);
if (mime_part->filename) g_free (mime_part->filename);
if (mime_part->header_lines) string_list_free (mime_part->header_lines);
-
+
if (mime_part->content_type) gmime_content_field_unref (mime_part->content_type);
+ if (mime_part->temp_message_buffer) g_byte_array_free (mime_part->temp_message_buffer, TRUE);
GTK_OBJECT_CLASS (parent_class)->finalize (object);
CAMEL_LOG_FULL_DEBUG ("Leaving CamelMimePart::finalize\n");
@@ -562,6 +569,31 @@ _set_content_object (CamelMedium *medium, CamelDataWrapper *content)
}
+static CamelDataWrapper *
+_get_content_object (CamelMedium *medium)
+{
+ CamelMimePart *mime_part = CAMEL_MIME_PART (medium);
+ CamelStream *stream;
+
+ /*
+ * test if there is not pending content stored in the
+ * temporary buffer
+ */
+ if ((!medium->content ) || (mime_part->temp_message_buffer)) {
+ stream = camel_stream_mem_new_with_buffer (mime_part->temp_message_buffer,
+ CAMEL_STREAM_MEM_READ);
+ camel_mime_part_construct_content_from_stream (mime_part, stream);
+ /*
+ * Beware : this will destroy the temp buffer as well
+ */
+ gtk_object_unref (GTK_OBJECT (stream));
+ }
+
+ return parent_class->get_content_object (medium);
+
+}
+
+
/* **** */
@@ -725,10 +757,10 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMimePart *mime_part = CAMEL_MIME_PART (data_wrapper);
-
+
camel_mime_part_construct_headers_from_stream (mime_part, stream);
- camel_mime_part_construct_content_from_stream (mime_part, stream);
-
+
+ camel_mime_part_store_stream_in_buffer (mime_part, stream);
CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving _construct_from_stream\n");
}