aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
Diffstat (limited to 'camel')
-rw-r--r--camel/Makefile.am2
-rw-r--r--camel/camel-mime-part-utils.c134
-rw-r--r--camel/camel-mime-part-utils.h49
-rw-r--r--camel/camel-mime-part.c71
-rw-r--r--camel/camel-mime-part.h19
-rw-r--r--camel/gmime-utils.c45
-rw-r--r--camel/gmime-utils.h24
7 files changed, 250 insertions, 94 deletions
diff --git a/camel/Makefile.am b/camel/Makefile.am
index c6860a6845..3fdedaac43 100644
--- a/camel/Makefile.am
+++ b/camel/Makefile.am
@@ -21,6 +21,7 @@ libcamel_la_SOURCES = \
camel-mime-body-part.c \
camel-mime-message.c \
camel-mime-part.c \
+ camel-mime-part-utils.c \
camel-multipart.c \
camel-provider.c \
camel-service.c \
@@ -48,6 +49,7 @@ libcamelinclude_HEADERS = \
camel-medium.h \
camel-mime-message.h \
camel-mime-part.h \
+ camel-mime-part-utils.h \
camel-multipart.h \
camel-provider.h \
camel-service.h \
diff --git a/camel/camel-mime-part-utils.c b/camel/camel-mime-part-utils.c
new file mode 100644
index 0000000000..9914964a52
--- /dev/null
+++ b/camel/camel-mime-part-utils.c
@@ -0,0 +1,134 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-mime-part-utils : Utility for mime parsing and so on */
+
+
+/*
+ *
+ * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> .
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+#include <config.h>
+#include "gmime-content-field.h"
+#include "string-utils.h"
+#include "camel-log.h"
+#include "gmime-utils.h"
+#include "camel-simple-data-wrapper.h"
+
+#include "camel-mime-part-utils.h"
+
+
+void
+camel_mime_part_construct_headers_from_stream (CamelMimePart *mime_part,
+ CamelStream *stream)
+{
+ GArray *header_array;
+ Rfc822Header *cur_header;
+ int i;
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: "
+ "Entering _construct_headers_from_stream\n");
+ g_assert (stream);
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_headers_from_stream "
+ "parsing headers\n");
+ /*
+ * parse all header lines
+ */
+ header_array = get_header_array_from_stream (stream);
+ if (header_array) {
+ for (i=0; i<header_array->len; i++) {
+ cur_header = (Rfc822Header *)header_array->data + i;
+ camel_medium_add_header ( CAMEL_MEDIUM (mime_part),
+ cur_header->name,
+ cur_header->value);
+ }
+
+ g_array_free (header_array, TRUE);
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_headers_from_stream "
+ "headers parsed \n");
+ }
+}
+
+
+
+
+
+void
+camel_mime_part_construct_content_from_stream (CamelMimePart *mime_part,
+ CamelStream *stream)
+{
+ GMimeContentField *content_type = NULL;
+ gchar *mime_type = NULL;
+ GtkType content_object_type;
+ CamelDataWrapper *content_object = NULL;
+
+ /*
+ * find content mime type
+ */
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_content_from_stream "
+ "parsing content\n");
+
+ content_type = camel_mime_part_get_content_type (mime_part);
+ if (content_type)
+ mime_type = gmime_content_field_get_mime_type (content_type);
+
+ /*
+ * no mime type found for the content,
+ * using text/plain is the default
+ */
+ if (!mime_type) {
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_content_from_stream "
+ "content type field not found "
+ "using default \"text/plain\"\n");
+ mime_type = g_strdup ("text/plain");
+ camel_mime_part_set_content_type (mime_part, mime_type);
+ }
+
+ /*
+ * find in the repository what particular data wrapper is
+ * associated to this mime type
+ */
+ content_object_type =
+ data_wrapper_repository_get_data_wrapper_type (mime_type);
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_content_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_data_wrapper_set_mime_type_field (content_object,
+ camel_mime_part_get_content_type (mime_part));
+ camel_medium_set_content_object ( CAMEL_MEDIUM (mime_part), content_object);
+ camel_data_wrapper_construct_from_stream (content_object, stream);
+
+ /*
+ * the object is referenced in the set_content_object method,
+ * so unref it here
+ */
+ gtk_object_unref (GTK_OBJECT (content_object));
+
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream "
+ "content parsed\n");
+
+ CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving _construct_from_stream\n");
+}
+
+
+
diff --git a/camel/camel-mime-part-utils.h b/camel/camel-mime-part-utils.h
new file mode 100644
index 0000000000..f3f4d55c82
--- /dev/null
+++ b/camel/camel-mime-part-utils.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-mime-part-utils : Utility for mime parsing and so on */
+
+
+/*
+ *
+ * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> .
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef CAMEL_MIME_PART_UTILS_H
+#define CAMEL_MIME_PART_UTILS_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus }*/
+
+#include "camel-mime-part.h"
+
+
+void camel_mime_part_construct_headers_from_stream (CamelMimePart *mime_part,
+ CamelStream *stream);
+
+void camel_mime_part_construct_content_from_stream (CamelMimePart *mime_part,
+ CamelStream *stream);
+
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CAMEL_MIME_PART_UTILS_H */
+
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index 1e41e5038d..ef01a54ba4 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -719,77 +719,18 @@ _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_
}
-/* calls _parse_header_pair, but can be called
- in a g_hash_table_for_each */
-void
-_parse_hash_table_pair (gpointer key, gpointer value, gpointer user_data)
-{
- 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)
- CAMEL_LOG_FULL_DEBUG ( "header name :%s\n", header_name);
- if (header_value)
- CAMEL_LOG_FULL_DEBUG ( "header value :%s\n", header_value);
-
- camel_medium_add_header ( CAMEL_MEDIUM (mime_part), header_name, header_value);
-
- CAMEL_LOG_FULL_DEBUG ( "--------- End -----------------\n");
-}
void
_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) {
- CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream content type field not found "
- "using default \"text/plain\"\n");
- mime_type = g_strdup ("text/plain");
- camel_mime_part_set_content_type (mime_part, mime_type);
- }
- content_object_type = data_wrapper_repository_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_data_wrapper_set_mime_type_field (content_object, camel_mime_part_get_content_type (mime_part));
- camel_medium_set_content_object ( CAMEL_MEDIUM (mime_part), content_object);
- camel_data_wrapper_construct_from_stream (content_object, stream);
-
- /* the object is referenced in the set_content_object method, so unref it here */
- gtk_object_unref (GTK_OBJECT (content_object));
-
-
- CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream content parsed\n");
-
-
+
+ camel_mime_part_construct_headers_from_stream (mime_part, stream);
+ camel_mime_part_construct_content_from_stream (mime_part, stream);
+
CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving _construct_from_stream\n");
+
}
diff --git a/camel/camel-mime-part.h b/camel/camel-mime-part.h
index 10c8ca58a4..8ea9cf5346 100644
--- a/camel/camel-mime-part.h
+++ b/camel/camel-mime-part.h
@@ -99,21 +99,28 @@ GtkType camel_mime_part_get_type (void);
/* public methods */
-void camel_mime_part_set_description (CamelMimePart *mime_part, const gchar *description);
+void camel_mime_part_set_description (CamelMimePart *mime_part,
+ const gchar *description);
const gchar *camel_mime_part_get_description (CamelMimePart *mime_part);
-void camel_mime_part_set_disposition (CamelMimePart *mime_part, const gchar *disposition);
+void camel_mime_part_set_disposition (CamelMimePart *mime_part,
+ const gchar *disposition);
const gchar *camel_mime_part_get_disposition (CamelMimePart *mime_part);
-void camel_mime_part_set_filename (CamelMimePart *mime_part, gchar *filename);
+void camel_mime_part_set_filename (CamelMimePart *mime_part,
+ gchar *filename);
const gchar *camel_mime_part_get_filename (CamelMimePart *mime_part);
const gchar *camel_mime_part_get_content_id (CamelMimePart *mime_part);
const gchar *camel_mime_part_get_content_MD5 (CamelMimePart *mime_part);
-void camel_mime_part_set_encoding (CamelMimePart *mime_part, gchar *encoding);
+void camel_mime_part_set_encoding (CamelMimePart *mime_part,
+ gchar *encoding);
const gchar *camel_mime_part_get_encoding (CamelMimePart *mime_part);
-void camel_mime_part_set_content_languages (CamelMimePart *mime_part, GList *content_languages);
+void camel_mime_part_set_content_languages (CamelMimePart *mime_part,
+ GList *content_languages);
const GList *camel_mime_part_get_content_languages (CamelMimePart *mime_part);
-void camel_mime_part_set_header_lines (CamelMimePart *mime_part, GList *header_lines);
+void camel_mime_part_set_header_lines (CamelMimePart *mime_part,
+ GList *header_lines);
const GList *camel_mime_part_get_header_lines (CamelMimePart *mime_part);
+GMimeContentField *camel_mime_part_get_content_type (CamelMimePart *mime_part);
/* utility functions */
void camel_mime_part_set_text (CamelMimePart *camel_mime_part, gchar *text);
diff --git a/camel/gmime-utils.c b/camel/gmime-utils.c
index c9c17b62bd..68257fe128 100644
--- a/camel/gmime-utils.c
+++ b/camel/gmime-utils.c
@@ -93,11 +93,11 @@ write_header_with_glist_to_stream (CamelStream *stream, const gchar *header_name
else first = FALSE;
camel_stream_write (stream, current, strlen (current));
}
- header_values = g_list_next(header_values);
+ header_values = g_list_next (header_values);
}
camel_stream_write (stream, "\n", 1);
}
- CAMEL_LOG_FULL_DEBUG ( "write_header_with_glist_to_stream:: leaving\n");
+ CAMEL_LOG_FULL_DEBUG ("write_header_with_glist_to_stream:: leaving\n");
}
@@ -109,16 +109,18 @@ write_header_with_glist_to_stream (CamelStream *stream, const gchar *header_name
/* scanning functions */
static void
-_store_header_pair_from_string (GHashTable *header_table, gchar *header_line)
+_store_header_pair_from_string (GArray *header_array, gchar *header_line)
{
gchar dich_result;
gchar *header_name, *header_value;
- gboolean key_exists;
- gchar *old_header_name, *old_header_value;
-
+ Rfc822Header header;
+
CAMEL_LOG_FULL_DEBUG ( "_store_header_pair_from_string:: Entering\n");
- g_assert (header_table);
- g_assert (header_line);
+
+ g_assert (header_array);
+ g_return_if_fail (header_line);
+
+
if (header_line) {
dich_result = string_dichotomy ( header_line, ':',
&header_name, &header_value,
@@ -137,12 +139,13 @@ _store_header_pair_from_string (GHashTable *header_table, gchar *header_line)
} else {
string_trim (header_value, " \t",
STRING_TRIM_STRIP_LEADING | STRING_TRIM_STRIP_TRAILING);
- key_exists = g_hash_table_lookup_extended (header_table, header_name, &old_header_name, &old_header_name);
- if (key_exists)
- printf ("-------- Key %s already exists /n", header_name);
- g_hash_table_insert (header_table, header_name, header_value);
+
+ header.name = header_name;
+ header.value = header_value;
+ g_array_append_val (header_array, header);
}
}
+
CAMEL_LOG_FULL_DEBUG ( "_store_header_pair_from_string:: Leaving\n");
}
@@ -150,26 +153,30 @@ _store_header_pair_from_string (GHashTable *header_table, gchar *header_line)
-GHashTable *
-get_header_table_from_stream (CamelStream *stream)
+GArray *
+get_header_array_from_stream (CamelStream *stream)
{
#warning Correct Lazy Implementation
/* should not use GString. */
/* should read the header line by line */
/* and not char by char */
gchar next_char;
+ gint nb_char_read;
gboolean crlf = FALSE;
gboolean end_of_header_line = FALSE;
gboolean end_of_headers = FALSE;
gboolean end_of_file = FALSE;
+
GString *header_line=NULL;
gchar *str_header_line;
- GHashTable *header_table;
- gint nb_char_read;
+
+ GArray *header_array;
+
CAMEL_LOG_FULL_DEBUG ( "gmime-utils:: Entering get_header_table_from_stream\n");
- header_table = g_hash_table_new (g_str_hash, g_str_equal);
+ header_array = g_array_new (FALSE, FALSE, sizeof (Rfc822Header));
+
nb_char_read = camel_stream_read (stream, &next_char, 1);
do {
header_line = g_string_new ("");
@@ -211,14 +218,14 @@ get_header_table_from_stream (CamelStream *stream)
} while ( !end_of_header_line );
if ( strlen(header_line->str) ) {
/* str_header_line = g_strdup (header_line->str); */
- _store_header_pair_from_string (header_table, header_line->str);
+ _store_header_pair_from_string (header_array, header_line->str);
}
g_string_free (header_line, FALSE);
} while ( (!end_of_headers) && (!end_of_file) );
CAMEL_LOG_FULL_DEBUG ( "gmime-utils:: Leaving get_header_table_from_stream\n");
- return header_table;
+ return header_array;
}
diff --git a/camel/gmime-utils.h b/camel/gmime-utils.h
index 5c99ca3d66..0c12f6bfb2 100644
--- a/camel/gmime-utils.h
+++ b/camel/gmime-utils.h
@@ -35,11 +35,27 @@ extern "C" {
#include <stdio.h>
#include <camel-stream.h>
-void gmime_write_header_pair_to_stream (CamelStream *stream, const gchar* name, const gchar *value);
-void write_header_table_to_stream (CamelStream *stream, GHashTable *header_table);
-void write_header_with_glist_to_stream (CamelStream *stream, const gchar *header_name, GList *header_values, const gchar *separator);
+typedef struct
+{
+ gchar *name;
+ gchar *value;
-GHashTable *get_header_table_from_stream (CamelStream *stream);
+} Rfc822Header;
+
+
+void gmime_write_header_pair_to_stream (CamelStream *stream,
+ const gchar* name,
+ const gchar *value);
+
+void write_header_table_to_stream (CamelStream *stream,
+ GHashTable *header_table);
+
+void write_header_with_glist_to_stream (CamelStream *stream,
+ const gchar *header_name,
+ GList *header_values,
+ const gchar *separator);
+
+GArray *get_header_array_from_stream (CamelStream *stream);
gchar *gmime_read_line_from_stream (CamelStream *stream);