aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbertrand <Bertrand.Guiheneuf@inria.fr>1999-06-22 22:19:24 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>1999-06-22 22:19:24 +0800
commit5deed2f193e7ab91f159f1a764b78578861044cd (patch)
tree78830536944b4a030673a5cb43339aaef65e1112
parent4f689d0fb8e33e91fec8b8e0471d48f1e6993622 (diff)
downloadgsoc2013-evolution-5deed2f193e7ab91f159f1a764b78578861044cd.tar
gsoc2013-evolution-5deed2f193e7ab91f159f1a764b78578861044cd.tar.gz
gsoc2013-evolution-5deed2f193e7ab91f159f1a764b78578861044cd.tar.bz2
gsoc2013-evolution-5deed2f193e7ab91f159f1a764b78578861044cd.tar.lz
gsoc2013-evolution-5deed2f193e7ab91f159f1a764b78578861044cd.tar.xz
gsoc2013-evolution-5deed2f193e7ab91f159f1a764b78578861044cd.tar.zst
gsoc2013-evolution-5deed2f193e7ab91f159f1a764b78578861044cd.zip
new function, returns "type/subtype" mime type string.
* camel/gmime-content-field.c (gmime_content_field_get_mime_type): new function, returns "type/subtype" mime type string. (gmime_content_field_construct_from_string): new function, construbt a content_field object form a string. be used to set the mime_type from a string. * camel/camel-mime-part.c (_set_content_type): (camel_mime_part_set_content_type): (_get_content_type): (_get_content_type): new methods. 1999-06-21 bertrand <Bertrand.Guiheneuf@inria.fr> * camel/gmime-utils.c (get_header_table_from_stream): replace CR/LF+'\t' with ' ' * camel/camel-mime-message.c (_set_recipient_list_from_string): trim \t when splitting * camel/gmime-utils.c (get_header_table_from_file): corrected bug in scanning tabulations ('t' -> '\t') * tests/test2.c (main): read mail.test instead of mail1.test * camel/camel-mime-part.c (_add_header): added comments svn path=/trunk/; revision=984
-rw-r--r--ChangeLog17
-rw-r--r--camel/camel-mime-part.c37
-rw-r--r--camel/camel-mime-part.h6
-rw-r--r--camel/gmime-content-field.c81
-rw-r--r--camel/gmime-content-field.h3
5 files changed, 121 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 1bbfb884b4..7d5bb1e32a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,19 @@
-1999-06-21 root <guiheneu@linoleum.inria.fr>
+1999-06-22 root <guiheneu@jean.joudboeuf.fr>
+
+ * camel/gmime-content-field.c (gmime_content_field_get_mime_type):
+ new function, returns "type/subtype" mime type string.
+ (gmime_content_field_construct_from_string):
+ new function, construbt a content_field object
+ form a string. be used to set the mime_type from a
+ string.
+
+ * camel/camel-mime-part.c (_set_content_type):
+ (camel_mime_part_set_content_type):
+ (_get_content_type):
+ (_get_content_type):
+ new methods.
+
+1999-06-21 bertrand <Bertrand.Guiheneuf@inria.fr>
* camel/gmime-utils.c (get_header_table_from_stream):
replace CR/LF+'\t' with ' '
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index 2d294b6b8b..489e6d0d27 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -68,6 +68,8 @@ static void _set_content_languages (CamelMimePart *mime_part, GList *content_lan
static 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 CamelDataWrapper *_get_content_object(CamelMimePart *mime_part);
static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
@@ -120,6 +122,8 @@ camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class)
camel_mime_part_class->get_header_lines=_get_header_lines;
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_type = _set_content_type;
+ camel_mime_part_class->get_content_type = _get_content_type;
@@ -133,6 +137,7 @@ 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->content_type_field = gmime_content_field_new (NULL, NULL);
}
@@ -491,6 +496,38 @@ camel_mime_part_get_content_object(CamelMimePart *mime_part)
return CMP_CLASS(mime_part)->get_content_object (mime_part);
}
+
+static void
+_set_content_type (CamelMimePart *mime_part, GString *content_type)
+{
+ g_assert (content_type);
+ gmime_content_field_construct_from_string (mime_part->content_type_field, content_type);
+}
+
+void
+camel_mime_part_set_content_type (CamelMimePart *mime_part, GString *content_type)
+{
+ CMP_CLASS(mime_part)->set_content_type (mime_part, content_type);
+}
+
+static GString *
+_get_content_type (CamelMimePart *mime_part)
+{
+ GString *mime_type;
+
+ mime_type = gmime_content_field_get_mime_type (mime_part->content_type_field);
+ return mime_type;
+}
+
+static GString *
+camel_mime_part_get_content_type (CamelMimePart *mime_part)
+{
+ return CMP_CLASS(mime_part)->get_content_type (mime_part);
+}
+
+
+
+/**********************************************************************/
#ifdef WHPT
#warning : WHPT is already defined !!!!!!
#endif
diff --git a/camel/camel-mime-part.h b/camel/camel-mime-part.h
index 87ed6e7a4f..8ab5fc152c 100644
--- a/camel/camel-mime-part.h
+++ b/camel/camel-mime-part.h
@@ -58,6 +58,7 @@ typedef struct
GString *encoding;
GString *filename;
GList *header_lines;
+ GMimeContentField *content_type_field;
CamelDataWrapper *content; /* part real content */
@@ -88,6 +89,9 @@ typedef struct {
GList * (*get_content_languages) (CamelMimePart *mime_part);
void (*set_header_lines) (CamelMimePart *mime_part, GList *header_lines);
GList * (*get_header_lines) (CamelMimePart *mime_part);
+ void (*set_content_type) (CamelMimePart *mime_part, GString *content_type);
+ GString * (*get_content_type) (CamelMimePart *mime_part);
+
gboolean (*parse_header_pair) (CamelMimePart *mime_part, GString *header_name, GString *header_value);
CamelDataWrapper * (*get_content_object) (CamelMimePart *mime_part);
@@ -117,6 +121,8 @@ void camel_mime_part_set_content_languages (CamelMimePart *mime_part, GList *con
GList *camel_mime_part_get_content_languages (CamelMimePart *mime_part);
void camel_mime_part_set_header_lines (CamelMimePart *mime_part, GList *header_lines);
GList *camel_mime_part_get_header_lines (CamelMimePart *mime_part);
+void camel_mime_part_set_content_type (CamelMimePart *mime_part, GString *content_type);
+static GString *camel_mime_part_get_content_type (CamelMimePart *mime_part);
#ifdef __cplusplus
}
diff --git a/camel/gmime-content-field.c b/camel/gmime-content-field.c
index 6cd368664e..a22bbe2979 100644
--- a/camel/gmime-content-field.c
+++ b/camel/gmime-content-field.c
@@ -27,6 +27,7 @@
#include "gmime-content-field.h"
#include "gstring-util.h"
+
GMimeContentField *
gmime_content_field_new (GString *type, GString *subtype)
{
@@ -41,7 +42,7 @@ gmime_content_field_new (GString *type, GString *subtype)
void
-gmime_content_field_set_parameter(GMimeContentField *content_field, GString *attribute, GString *value)
+gmime_content_field_set_parameter (GMimeContentField *content_field, GString *attribute, GString *value)
{
gboolean attribute_exists;
GString *old_attribute;
@@ -86,23 +87,34 @@ gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStre
{
if (!content_field) return;
if ((content_field->type) && ((content_field->type)->str)) {
- //fprintf (file, "Content-Type: %s", content_field->type->str);
camel_stream_write_strings (stream, "Content-Type: ", content_field->type->str, NULL);
if ((content_field->subtype) && ((content_field->subtype)->str)) {
- //fprintf (file, "/%s", content_field->subtype->str);
camel_stream_write_strings (stream, "/", content_field->subtype->str, NULL);
}
/* print all parameters */
g_hash_table_foreach (content_field->parameters, _print_parameter, stream);
- //fprintf (file, "\n");
camel_stream_write_string (stream, "\n");
}
}
-GMimeContentField *
-gmime_content_field_construct_from_string (GString *string)
+GString *
+gmime_content_field_get_mime_type (GMimeContentField *content_field)
+{
+ GString *mime_type;
+
+ if (!content_field->type) return NULL;
+ mime_type = g_string_clone (content_field->type);
+ if (content_field->subtype) {
+ g_string_append_c (mime_type, '/');
+ g_string_append_g_string (mime_type, content_field->subtype);
+ }
+ return mime_type;
+}
+
+
+void
+gmime_content_field_construct_from_string (GMimeContentField *content_field, GString *string)
{
- GMimeContentField *cf;
gint first, len;
gchar *str;
gint i=0;
@@ -113,31 +125,38 @@ gmime_content_field_construct_from_string (GString *string)
g_assert (string);
g_assert (string->str);
- cf = g_new (GMimeContentField,1);
+ if (content_field->type) g_string_free (content_field->type, FALSE);
+ if (content_field->subtype) g_string_free (content_field->subtype, FALSE);
+
str = string->str;
first = 0;
len = string->len;
- if (!len) return NULL;
+ if (!len) return;
/* find the type */
while ( (i<len) && (!strchr ("/;", str[i])) ) i++;
- if (i == 0) return NULL;
+ if (i == 0) return;
+
+ type = g_string_new (g_strndup (str, i));
+ content_field->type = type;
- type = g_string_new (strndup (str, i));
- if (i == len) return (gmime_content_field_new (type, NULL));
+ if (i == len) {
+ content_field->subtype = NULL;
+ return;
+ }
first = i+1;
/* find the subtype, if any */
if (str[i++] == '/') {
while ( (i<len) && (str[i] != ';') ) i++;
if (i != first) {
- subtype = g_string_new (strndup (str+first, i-first));
- if (first == len) return (gmime_content_field_new (type, subtype));
+ subtype = g_string_new (g_strndup (str+first, i-first));
+ content_field->subtype = subtype;
+ if (i == len) return;
}
}
first = i+1;
- cf = gmime_content_field_new (type, subtype);
/* parse parameters list */
param_end = FALSE;
@@ -146,17 +165,35 @@ gmime_content_field_construct_from_string (GString *string)
if ((i == len) || (i==first)) param_end = TRUE;
else {
/* we have found parameter name */
- param_name = g_string_new (strndup (str+first, i-first));
+ param_name = g_string_new (g_strndup (str+first, i-first));
i++;
first = i;
+ /* Let's find parameter value */
while ( (i<len) && (str[i] != ';') ) i++;
- if (i != first) {
- /** ****/
- } else {
-
- }
+ if (i != first) param_value = g_string_new (g_strndup (str+first, i-first));
+ else param_value = g_string_new ("");
+ gmime_content_field_set_parameter (content_field, param_name, param_value);
+ i++;
+ first = i;
}
} while ((!param_end) && (first < len));
- return cf;
+}
+
+
+static void
+_free_parameter (gpointer name, gpointer value, gpointer user_data)
+{
+ g_string_free (name, FALSE);
+ g_string_free (value, FALSE);
+}
+
+void
+gmime_content_field_free (GMimeContentField *content_field)
+{
+ g_hash_table_foreach (content_field->parameters, _free_parameter, NULL);
+ g_string_free (content_field->type, FALSE);
+ g_string_free (content_field->subtype, FALSE);
+ g_hash_table_destroy (content_field->parameters);
+ g_free (content_field);
}
diff --git a/camel/gmime-content-field.h b/camel/gmime-content-field.h
index 2711deabb9..7fe66bf7a9 100644
--- a/camel/gmime-content-field.h
+++ b/camel/gmime-content-field.h
@@ -46,6 +46,9 @@ typedef struct {
GMimeContentField *gmime_content_field_new (GString *type, GString *subtype);
void gmime_content_field_set_parameter(GMimeContentField *content_field, GString *attribute, GString *value);
void gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStream *stream);
+void gmime_content_field_construct_from_string (GMimeContentField *content_field, GString *string);
+void gmime_content_field_free (GMimeContentField *content_field);
+GString * gmime_content_field_get_mime_type (GMimeContentField *content_field);
#ifdef __cplusplus