aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-part.c
diff options
context:
space:
mode:
authorBertrand Guiheneuf <bertrand@src.gnome.org>1999-08-01 21:38:28 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>1999-08-01 21:38:28 +0800
commitcac0ba57e6c47acd94600b5add1930301df33c50 (patch)
treea399fb592b6e5df4afbaa7d1d677d818b3767880 /camel/camel-mime-part.c
parent5709aa9ef61dc720571acec93085f7d2d4ef4758 (diff)
downloadgsoc2013-evolution-cac0ba57e6c47acd94600b5add1930301df33c50.tar.gz
gsoc2013-evolution-cac0ba57e6c47acd94600b5add1930301df33c50.tar.zst
gsoc2013-evolution-cac0ba57e6c47acd94600b5add1930301df33c50.zip
merge a lot of work. Rough ChangeLog will follow
svn path=/trunk/; revision=1052
Diffstat (limited to 'camel/camel-mime-part.c')
-rw-r--r--camel/camel-mime-part.c398
1 files changed, 245 insertions, 153 deletions
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index aa40144acf..913ab31e63 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -25,9 +25,10 @@
#include "camel-mime-part.h"
#include <stdio.h>
#include "gmime-content-field.h"
-#include "gstring-util.h"
+#include "string-utils.h"
#include "camel-log.h"
#include "gmime-utils.h"
+#include "camel-simple-data-wrapper.h"
typedef enum {
@@ -50,32 +51,33 @@ static CamelDataWrapperClass *parent_class=NULL;
/* Returns the class for a CamelMimePart */
#define CMP_CLASS(so) CAMEL_MIME_PART_CLASS (GTK_OBJECT(so)->klass)
-static void _add_header (CamelMimePart *mime_part, GString *header_name, GString *header_value);
-static void _remove_header (CamelMimePart *mime_part, GString *header_name);
-static GString *_get_header (CamelMimePart *mime_part, GString *header_name);
-static void _set_description (CamelMimePart *mime_part, GString *description);
-static GString *_get_description (CamelMimePart *mime_part);
-static void _set_disposition (CamelMimePart *mime_part, GString *disposition);
-static GString *_get_disposition (CamelMimePart *mime_part);
-static void _set_filename (CamelMimePart *mime_part, GString *filename);
-static GString *_get_filename (CamelMimePart *mime_part);
-static void _set_content_id (CamelMimePart *mime_part, GString *content_id);
-static GString *_get_content_id (CamelMimePart *mime_part);
-static void _set_content_MD5 (CamelMimePart *mime_part, GString *content_MD5);
-static GString *_get_content_MD5 (CamelMimePart *mime_part);
-static void _set_encoding (CamelMimePart *mime_part, GString *encoding);
-static GString *_get_encoding (CamelMimePart *mime_part);
+static void _add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value);
+static void _remove_header (CamelMimePart *mime_part, const gchar *header_name);
+static const gchar *_get_header (CamelMimePart *mime_part, const gchar *header_name);
+static void _set_description (CamelMimePart *mime_part, gchar *description);
+static const gchar *_get_description (CamelMimePart *mime_part);
+static void _set_disposition (CamelMimePart *mime_part, gchar *disposition);
+static const gchar *_get_disposition (CamelMimePart *mime_part);
+static void _set_filename (CamelMimePart *mime_part, gchar *filename);
+static const gchar *_get_filename (CamelMimePart *mime_part);
+static void _set_content_id (CamelMimePart *mime_part, gchar *content_id);
+static const gchar *_get_content_id (CamelMimePart *mime_part);
+static void _set_content_MD5 (CamelMimePart *mime_part, gchar *content_MD5);
+static const gchar *_get_content_MD5 (CamelMimePart *mime_part);
+static void _set_encoding (CamelMimePart *mime_part, gchar *encoding);
+static const gchar *_get_encoding (CamelMimePart *mime_part);
static void _set_content_languages (CamelMimePart *mime_part, GList *content_languages);
-static GList *_get_content_languages (CamelMimePart *mime_part);
+static const GList *_get_content_languages (CamelMimePart *mime_part);
static void _set_header_lines (CamelMimePart *mime_part, GList *header_lines);
-static GList *_get_header_lines (CamelMimePart *mime_part);
-static void _set_content_type (CamelMimePart *mime_part, GString *content_type);
-static GString *_get_content_type (CamelMimePart *mime_part);
+static const GList *_get_header_lines (CamelMimePart *mime_part);
+static void _set_content_type (CamelMimePart *mime_part, const gchar *content_type);
+static GMimeContentField *_get_content_type (CamelMimePart *mime_part);
-static CamelDataWrapper *_get_content_object(CamelMimePart *mime_part);
-static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static const CamelDataWrapper *_get_content_object(CamelMimePart *mime_part);
+static void _set_content_object(CamelMimePart *mime_part, CamelDataWrapper *content);
-static gboolean _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value);
+static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static gboolean _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value);
void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
@@ -85,14 +87,14 @@ void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream
static void
_init_header_name_table()
{
- header_name_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash);
- g_hash_table_insert (header_name_table, g_string_new ("Content-Description"), (gpointer)HEADER_DESCRIPTION);
- g_hash_table_insert (header_name_table, g_string_new ("Content-Disposition"), (gpointer)HEADER_DISPOSITION);
- g_hash_table_insert (header_name_table, g_string_new ("Content-id"), (gpointer)HEADER_CONTENT_ID);
- g_hash_table_insert (header_name_table, g_string_new ("Content-Transfer-Encoding"), (gpointer)HEADER_ENCODING);
- g_hash_table_insert (header_name_table, g_string_new ("Content-MD5"), (gpointer)HEADER_CONTENT_MD5);
- g_hash_table_insert (header_name_table, g_string_new ("Content-Type"), (gpointer)HEADER_CONTENT_TYPE);
-
+ header_name_table = g_hash_table_new (g_str_hash, g_str_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);
+ g_hash_table_insert (header_name_table, "Content-Transfer-Encoding", (gpointer)HEADER_ENCODING);
+ g_hash_table_insert (header_name_table, "Content-MD5", (gpointer)HEADER_CONTENT_MD5);
+ g_hash_table_insert (header_name_table, "Content-Type", (gpointer)HEADER_CONTENT_TYPE);
+
}
static void
@@ -124,10 +126,11 @@ camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class)
camel_mime_part_class->get_header_lines =_get_header_lines;
camel_mime_part_class->set_content_type = _set_content_type;
camel_mime_part_class->get_content_type = _get_content_type;
-
+
camel_mime_part_class->parse_header_pair = _parse_header_pair;
camel_mime_part_class->get_content_object = _get_content_object;
-
+ camel_mime_part_class->set_content_object = _set_content_object;
+
/* virtual method overload */
@@ -139,8 +142,8 @@ static void
camel_mime_part_init (gpointer object, gpointer klass)
{
CamelMimePart *camel_mime_part = CAMEL_MIME_PART (object);
-
- camel_mime_part->headers = g_hash_table_new (g_string_hash, g_string_equal_for_hash);
+
+ camel_mime_part->headers = g_hash_table_new (g_str_hash, g_str_equal);
camel_mime_part->content_type = gmime_content_field_new (NULL, NULL);
}
@@ -175,12 +178,12 @@ camel_mime_part_get_type (void)
static void
-_add_header (CamelMimePart *mime_part, GString *header_name, GString *header_value)
+_add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value)
{
gboolean header_exists;
- GString *old_header_name;
- GString *old_header_value;
-
+ gchar *old_header_name;
+ gchar *old_header_value;
+
/* Try to parse the header pair. If it corresponds to something */
/* known, the job is done in the parsing routine. If not, */
/* we simply add the header in a raw fashion */
@@ -190,8 +193,8 @@ _add_header (CamelMimePart *mime_part, GString *header_name, GString *header_val
(gpointer *) &old_header_name,
(gpointer *) &old_header_value);
if (header_exists) {
- g_string_free (old_header_name, TRUE);
- g_string_free (old_header_value, TRUE);
+ g_free (old_header_name);
+ g_free (old_header_value);
}
g_hash_table_insert (mime_part->headers, header_name, header_value);
@@ -199,7 +202,7 @@ _add_header (CamelMimePart *mime_part, GString *header_name, GString *header_val
void
-camel_mime_part_add_header (CamelMimePart *mime_part, GString *header_name, GString *header_value)
+camel_mime_part_add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value)
{
CMP_CLASS(mime_part)->add_header(mime_part, header_name, header_value);
}
@@ -207,19 +210,19 @@ camel_mime_part_add_header (CamelMimePart *mime_part, GString *header_name, GStr
static void
-_remove_header (CamelMimePart *mime_part, GString *header_name)
+_remove_header (CamelMimePart *mime_part, const gchar *header_name)
{
gboolean header_exists;
- GString *old_header_name;
- GString *old_header_value;
-
+ gchar *old_header_name;
+ gchar *old_header_value;
+
header_exists = g_hash_table_lookup_extended (mime_part->headers, header_name,
(gpointer *) &old_header_name,
(gpointer *) &old_header_value);
if (header_exists) {
- g_string_free (old_header_name, TRUE);
- g_string_free (old_header_value, TRUE);
+ g_free (old_header_name);
+ g_free (old_header_value);
}
g_hash_table_remove (mime_part->headers, header_name);
@@ -227,27 +230,27 @@ _remove_header (CamelMimePart *mime_part, GString *header_name)
}
void
-camel_mime_part_remove_header (CamelMimePart *mime_part, GString *header_name)
+camel_mime_part_remove_header (CamelMimePart *mime_part, const gchar *header_name)
{
CMP_CLASS(mime_part)->remove_header(mime_part, header_name);
}
-static GString *
-_get_header (CamelMimePart *mime_part, GString *header_name)
+static const gchar *
+_get_header (CamelMimePart *mime_part, const gchar *header_name)
{
- GString *old_header_name;
- GString *old_header_value;
- GString *header_value;
-
- header_value = (GString *)g_hash_table_lookup (mime_part->headers, header_name);
+ gchar *old_header_name;
+ gchar *old_header_value;
+ gchar *header_value;
+
+ header_value = (gchar *)g_hash_table_lookup (mime_part->headers, header_name);
return header_value;
}
-GString *
-camel_mime_part_get_header (CamelMimePart *mime_part, GString *header_name)
+const gchar *
+camel_mime_part_get_header (CamelMimePart *mime_part, const gchar *header_name)
{
return CMP_CLASS(mime_part)->get_header (mime_part, header_name);
}
@@ -255,14 +258,14 @@ camel_mime_part_get_header (CamelMimePart *mime_part, GString *header_name)
static void
-_set_description (CamelMimePart *mime_part, GString *description)
+_set_description (CamelMimePart *mime_part, gchar *description)
{
- if (mime_part->description) g_free(mime_part->description);
+ if (mime_part->description) g_free (mime_part->description);
mime_part->description = description;
}
void
-camel_mime_part_set_description (CamelMimePart *mime_part, GString *description)
+camel_mime_part_set_description (CamelMimePart *mime_part, gchar *description)
{
CMP_CLASS(mime_part)->set_description (mime_part, description);
}
@@ -270,13 +273,13 @@ camel_mime_part_set_description (CamelMimePart *mime_part, GString *description)
-static GString *
+static const gchar *
_get_description (CamelMimePart *mime_part)
{
return mime_part->description;
}
-GString *
+const gchar *
camel_mime_part_get_description (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_description (mime_part);
@@ -285,8 +288,9 @@ camel_mime_part_get_description (CamelMimePart *mime_part)
static void
-_set_disposition (CamelMimePart *mime_part, GString *disposition)
+_set_disposition (CamelMimePart *mime_part, gchar *disposition)
{
+#warning Do not use MimeContentfield here !!!
//if (mime_part->disposition) g_free(mime_part->disposition);
if (!mime_part->disposition)
mime_part->disposition = g_new (GMimeContentField,1);
@@ -296,14 +300,14 @@ _set_disposition (CamelMimePart *mime_part, GString *disposition)
void
-camel_mime_part_set_disposition (CamelMimePart *mime_part, GString *disposition)
+camel_mime_part_set_disposition (CamelMimePart *mime_part, gchar *disposition)
{
CMP_CLASS(mime_part)->set_disposition (mime_part, disposition);
}
-static GString *
+static const gchar *
_get_disposition (CamelMimePart *mime_part)
{
if (!mime_part->disposition) return NULL;
@@ -311,7 +315,7 @@ _get_disposition (CamelMimePart *mime_part)
}
-GString *
+const gchar *
camel_mime_part_get_disposition (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_disposition (mime_part);
@@ -320,7 +324,7 @@ camel_mime_part_get_disposition (CamelMimePart *mime_part)
static void
-_set_filename (CamelMimePart *mime_part, GString *filename)
+_set_filename (CamelMimePart *mime_part, gchar *filename)
{
if (mime_part->filename) g_free(mime_part->filename);
mime_part->filename = filename;
@@ -328,21 +332,21 @@ _set_filename (CamelMimePart *mime_part, GString *filename)
void
-camel_mime_part_set_filename (CamelMimePart *mime_part, GString *filename)
+camel_mime_part_set_filename (CamelMimePart *mime_part, gchar *filename)
{
CMP_CLASS(mime_part)->set_filename (mime_part, filename);
}
-static GString *
+static const gchar *
_get_filename (CamelMimePart *mime_part)
{
return mime_part->filename;
}
-GString *
+const gchar *
camel_mime_part_get_filename (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_filename (mime_part);
@@ -351,21 +355,21 @@ camel_mime_part_get_filename (CamelMimePart *mime_part)
/* this routine must not be public */
static void
-_set_content_id (CamelMimePart *mime_part, GString *content_id)
+_set_content_id (CamelMimePart *mime_part, gchar *content_id)
{
if (mime_part->content_id) g_free(mime_part->content_id);
mime_part->content_id = content_id;
}
-static GString *
+static const gchar *
_get_content_id (CamelMimePart *mime_part)
{
return mime_part->content_id;
}
-GString *
+const gchar *
camel_mime_part_get_content_id (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_id (mime_part);
@@ -374,20 +378,20 @@ camel_mime_part_get_content_id (CamelMimePart *mime_part)
/* this routine must not be public */
static void
-_set_content_MD5 (CamelMimePart *mime_part, GString *content_MD5)
+_set_content_MD5 (CamelMimePart *mime_part, gchar *content_MD5)
{
if (mime_part->content_MD5) g_free(mime_part->content_MD5);
mime_part->content_MD5 = content_MD5;
}
-static GString *
+static const gchar *
_get_content_MD5 (CamelMimePart *mime_part)
{
return mime_part->content_MD5;
}
-GString *
+const gchar *
camel_mime_part_get_content_MD5 (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_MD5 (mime_part);
@@ -396,27 +400,27 @@ camel_mime_part_get_content_MD5 (CamelMimePart *mime_part)
static void
-_set_encoding (CamelMimePart *mime_part, GString *encoding)
+_set_encoding (CamelMimePart *mime_part, gchar *encoding)
{
if (mime_part->encoding) g_free(mime_part->encoding);
mime_part->encoding = encoding;
}
void
-camel_mime_part_set_encoding (CamelMimePart *mime_part, GString *encoding)
+camel_mime_part_set_encoding (CamelMimePart *mime_part, gchar *encoding)
{
CMP_CLASS(mime_part)->set_encoding (mime_part, encoding);
}
-static GString *
+static const gchar *
_get_encoding (CamelMimePart *mime_part)
{
return mime_part->encoding;
}
-GString *
+const gchar *
camel_mime_part_get_encoding (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_encoding (mime_part);
@@ -428,7 +432,7 @@ camel_mime_part_get_encoding (CamelMimePart *mime_part)
static void
_set_content_languages (CamelMimePart *mime_part, GList *content_languages)
{
- if (mime_part->content_languages) g_string_list_free(mime_part->content_languages);
+ if (mime_part->content_languages) string_list_free (mime_part->content_languages);
mime_part->content_languages = content_languages;
}
@@ -440,14 +444,14 @@ camel_mime_part_set_content_languages (CamelMimePart *mime_part, GList *content_
-static GList *
+static const GList *
_get_content_languages (CamelMimePart *mime_part)
{
return mime_part->content_languages;
}
-GList *
+const GList *
camel_mime_part_get_content_languages (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_languages (mime_part);
@@ -458,7 +462,7 @@ camel_mime_part_get_content_languages (CamelMimePart *mime_part)
static void
_set_header_lines (CamelMimePart *mime_part, GList *header_lines)
{
- if (mime_part->header_lines) g_string_list_free(mime_part->header_lines);
+ if (mime_part->header_lines) string_list_free (mime_part->header_lines);
mime_part->header_lines = header_lines;
}
@@ -470,7 +474,7 @@ camel_mime_part_set_header_lines (CamelMimePart *mime_part, GList *header_lines)
-static GList *
+static const GList *
_get_header_lines (CamelMimePart *mime_part)
{
return mime_part->header_lines;
@@ -478,7 +482,7 @@ _get_header_lines (CamelMimePart *mime_part)
-GList *
+const GList *
camel_mime_part_get_header_lines (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_header_lines (mime_part);
@@ -488,48 +492,69 @@ camel_mime_part_get_header_lines (CamelMimePart *mime_part)
/*********/
static void
-_set_content_type (CamelMimePart *mime_part, GString *content_type)
+_set_content_type (CamelMimePart *mime_part, const gchar *content_type)
{
g_assert (content_type);
gmime_content_field_construct_from_string (mime_part->content_type, content_type);
}
void
-camel_mime_part_set_mime_type (CamelMimePart *mime_part, GString *content_type)
+camel_mime_part_set_content_type (CamelMimePart *mime_part, gchar *content_type)
{
CMP_CLASS(mime_part)->set_content_type (mime_part, content_type);
}
-static GString *
+static GMimeContentField *
_get_content_type (CamelMimePart *mime_part)
{
- GString *mime_type;
-
- mime_type = gmime_content_field_get_mime_type (mime_part->content_type);
- return mime_type;
+ return mime_part->content_type;
}
-static GString *
+GMimeContentField *
camel_mime_part_get_content_type (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_type (mime_part);
}
+
/*********/
-static CamelDataWrapper *
+static const CamelDataWrapper *
_get_content_object(CamelMimePart *mime_part)
{
return mime_part->content;
-
+
}
-CamelDataWrapper *
+const CamelDataWrapper *
camel_mime_part_get_content_object(CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_content_object (mime_part);
}
+static void
+_set_content_object(CamelMimePart *mime_part, CamelDataWrapper *content)
+{
+ CAMEL_LOG_FULL_DEBUG ("Entering CamelMimePart::set_content_object\n");
+ if (mime_part->content) {
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::set_content_object unreferencing old content object\n");
+ gtk_object_unref (GTK_OBJECT (mime_part->content));
+ }
+ gtk_object_ref (GTK_OBJECT (content));
+ mime_part->content = content;
+ if (mime_part->content_type) gmime_content_field_free (mime_part->content_type);
+ mime_part->content_type = camel_data_wrapper_get_mime_type_field (content);
+ CAMEL_LOG_FULL_DEBUG ("Leaving CamelMimePart::set_content_object\n");
+
+}
+
+void
+camel_mime_part_set_content_object(CamelMimePart *mime_part, CamelDataWrapper *content)
+{
+ CMP_CLASS(mime_part)->set_content_object (mime_part, content);
+}
+
+
/**********************************************************************/
@@ -539,7 +564,6 @@ camel_mime_part_get_content_object(CamelMimePart *mime_part)
#define WHPT gmime_write_header_pair_to_stream
-/* This is not used for the moment */
static void
_write_content_to_stream (CamelMimePart *mime_part, CamelStream *stream)
{
@@ -548,20 +572,24 @@ _write_content_to_stream (CamelMimePart *mime_part, CamelStream *stream)
gchar *encoded_buffer;
CamelDataWrapper *content = mime_part->content;
+ CAMEL_LOG_FULL_DEBUG ( "Entering CamelMimePart::_write_content_to_stream\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::_write_content_to_stream, content=%p\n", content);
+ if (!content) return;
// buffer_size = camel_data_wrapper_size (content);
- buffer = g_malloc (buffer_size);
+ //buffer = g_malloc (buffer_size);
camel_data_wrapper_write_to_stream (content, stream);
- if (mime_part->encoding) {
+ //if (mime_part->encoding) {
// encoded_buffer_size = gmime_encoded_size(buffer, buffer_size, encoding);
// encoded_buffer = g_malloc (encoded_buffer_size);
// gmime_encode_buffer (buffer, encoded_buffer, encoding);
// camel_stream_write (stream, encoded_buffer, encoded_buffer_size);
// g_free (encoded_buffer);
- } else
+ //} else
//fwrite (buffer, buffer_size, 1, file);
- camel_stream_write (stream, buffer, buffer_size);
- g_free (buffer);
+ //camel_stream_write (stream, buffer, buffer_size);
+ //g_free (buffer);
+ CAMEL_LOG_FULL_DEBUG ( "Leaving CamelMimePart::_write_content_to_stream\n");
}
@@ -573,29 +601,29 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMimePart *mp = CAMEL_MIME_PART (data_wrapper);
- CAMEL_LOG (FULL_DEBUG, "Entering CamelMimePart::write_to_stream\n");
-
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-disposition\n");
+ CAMEL_LOG_FULL_DEBUG ( "Entering CamelMimePart::write_to_stream\n");
+
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-disposition\n");
gmime_content_field_write_to_stream(mp->disposition, stream);
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-transfer-encoding\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-transfer-encoding\n");
WHPT (stream, "Content-Transfer-Encoding", mp->encoding);
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-description\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-description\n");
WHPT (stream, "Content-Description", mp->description);
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-MD5\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-MD5\n");
WHPT (stream, "Content-MD5", mp->content_MD5);
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-id\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-id\n");
WHPT (stream, "Content-id", mp->content_id);
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-languages\n");
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-languages\n");
write_header_with_glist_to_stream (stream, "Content-Language", mp->content_languages,", ");
-
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing other headers\n");
+
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing other headers\n");
write_header_table_to_stream (stream, mp->headers);
-
- CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-type\n");
+
+ CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-type\n");
gmime_content_field_write_to_stream(mp->content_type, stream);
-
+
camel_stream_write_string(stream,"\n");
- if (mp->content) camel_data_wrapper_write_to_stream (mp->content, stream);
+ _write_content_to_stream (mp, stream);
}
@@ -605,64 +633,64 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
/* mime part parsing */
static gboolean
-_parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value)
+_parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value)
{
CamelHeaderType header_type;
gboolean header_handled = FALSE;
-
-
+
+
header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, header_name);
switch (header_type) {
-
+
case HEADER_DESCRIPTION:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_DESCRIPTION: %s\n",
- header_value->str );
+ header_value );
camel_mime_part_set_description (mime_part, header_value);
header_handled = TRUE;
break;
-
+
case HEADER_DISPOSITION:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_DISPOSITION: %s\n",
- header_value->str );
+ header_value);
camel_mime_part_set_disposition (mime_part, header_value);
header_handled = TRUE;
break;
-
+
case HEADER_CONTENT_ID:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_CONTENT_ID: %s\n",
- header_value->str );
+ header_value);
CMP_CLASS(mime_part)->set_content_id (mime_part, header_value);
header_handled = TRUE;
break;
case HEADER_ENCODING:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_ENCODING: %s\n",
- header_value->str );
+ header_value);
camel_mime_part_set_encoding (mime_part, header_value);
header_handled = TRUE;
break;
case HEADER_CONTENT_MD5:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_CONTENT_MD5: %s\n",
- header_value->str );
-
+ header_value );
+
CMP_CLASS(mime_part)->set_content_MD5 (mime_part, header_value);
header_handled = TRUE;
break;
case HEADER_CONTENT_TYPE:
- CAMEL_LOG (FULL_DEBUG,
+ CAMEL_LOG_FULL_DEBUG (
"CamelMimePart::parse_header_pair found HEADER_CONTENT_TYPE: %s\n",
- header_value->str );
+ header_value );
gmime_content_field_construct_from_string (mime_part->content_type, header_value);
header_handled = TRUE;
@@ -670,13 +698,13 @@ _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *hea
}
-
-
+
+
if (header_handled) {
- g_string_free (header_name, TRUE);
+ g_free (header_name);
return TRUE;
} else return FALSE;
-
+
}
/* calls _parse_header_pair, but can be called
@@ -684,19 +712,19 @@ _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *hea
void
_parse_hash_table_pair (gpointer key, gpointer value, gpointer user_data)
{
- GString *header_name = (GString *)key;
- GString *header_value = (GString *)value;
+ gchar *header_name = (gchar *)key;
+ gchar *header_value = (gchar *)value;
CamelMimePart *mime_part = (CamelMimePart *) user_data;
-
-
- CAMEL_LOG (FULL_DEBUG,"\n--------- New Header ----------\n");
- if ((header_name) && (header_name->str))
- CAMEL_LOG (FULL_DEBUG, "header name :%s\n", header_name->str);
- if ((header_value) && (header_value->str))
- CAMEL_LOG (FULL_DEBUG, "header value :%s\n", header_value->str);
-
+
+
+ CAMEL_LOG_FULL_DEBUG ("\n--------- New Header ----------\n");
+ if (header_name)
+ CAMEL_LOG_FULL_DEBUG ( "header name :%s\n", header_name);
+ if (header_value)
+ CAMEL_LOG_FULL_DEBUG ( "header value :%s\n", header_value);
+
camel_mime_part_add_header (mime_part, header_name, header_value);
- CAMEL_LOG (FULL_DEBUG, "--------- End -----------------\n");
+ CAMEL_LOG_FULL_DEBUG ( "--------- End -----------------\n");
}
void
@@ -704,11 +732,75 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
GHashTable *header_table;
CamelMimePart *mime_part = CAMEL_MIME_PART (data_wrapper);
-
+ GMimeContentField *content_type;
+ gchar *mime_type;
+ GtkType content_object_type;
+ CamelDataWrapper *content_object;
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Entering _construct_from_stream\n");
+ g_assert (stream);
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream parsing headers\n");
+ /* parse all header lines */
header_table = get_header_table_from_stream (stream);
if (header_table) {
g_hash_table_foreach (header_table, _parse_hash_table_pair, (gpointer)mime_part);
}
g_hash_table_destroy (header_table);
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream headers parsed \n");
+
+ /* now parse the content */
+ /* find its mime type */
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream parsing content\n");
+ content_type = camel_mime_part_get_content_type (mime_part);
+ mime_type = gmime_content_field_get_mime_type (content_type);
+ if (mime_type) {
+ content_object_type = data_wrapper_get_data_wrapper_type (mime_type);
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream content type object type used: %s\n", gtk_type_name (content_object_type));
+ g_free (mime_type);
+ content_object = CAMEL_DATA_WRAPPER (gtk_type_new (content_object_type));
+ camel_mime_part_set_content_object (mime_part, content_object);
+ camel_data_wrapper_construct_from_stream (content_object, stream);
+
+ } else
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream content type field not found\n");
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream content parsed\n");
+
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving _construct_from_stream\n");
+}
+
+
+/******************************/
+/** Misc utility functions **/
+
+
+/**
+ * camel_mime_part_set_text: set the content to be some text
+ * @camel_mime_part: Mime part
+ * @text: the text
+ *
+ * Utility function used to set the content of a mime part object to
+ * be a text string. When @text is NULL, this routine can be used as
+ * a way to remove old text content.
+ *
+ **/
+void
+camel_mime_part_set_text (CamelMimePart *camel_mime_part, gchar *text)
+{
+ CamelSimpleDataWrapper *simple_data_wrapper;
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Entering set_text\n");
+ CAMEL_LOG_TRACE ("CamelMimePart::set_text, setting text as a mime part content\n");
+ if (camel_mime_part->content) {
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::set_text unreferencing old content object\n");
+ gtk_object_unref (GTK_OBJECT (camel_mime_part->content));
+ }
+ if (text) {
+ simple_data_wrapper = camel_simple_data_wrapper_new ();
+ camel_mime_part->content = CAMEL_DATA_WRAPPER (simple_data_wrapper);
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::set_text calling CamelSimpleDataWrapper:set_text with %d chars\n", strlen (text));
+ camel_simple_data_wrapper_set_text ( simple_data_wrapper, text);
+ } else camel_mime_part->content = NULL;
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving camel_mime_part_set_text\n");
}