diff options
author | bertrand <Bertrand.Guiheneuf@aful.org> | 1999-08-03 18:19:39 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-08-03 18:19:39 +0800 |
commit | e9c6d8921cce940e590f763a881794323a9e6703 (patch) | |
tree | d8e989d8119fe6d8c825364c0b7dd16c6c2179be | |
parent | bba2b0a352933d8aa8894fe1b7a8a5185378990f (diff) | |
download | gsoc2013-evolution-e9c6d8921cce940e590f763a881794323a9e6703.tar.gz gsoc2013-evolution-e9c6d8921cce940e590f763a881794323a9e6703.tar.zst gsoc2013-evolution-e9c6d8921cce940e590f763a881794323a9e6703.zip |
Multipart Mime message parsing works with plain text parts. Woohooo :))))
Making it work with other types is now just a matter of writing
the various data wrappers. And display them will just be a matter of writing
the good bonobo components.
1999-08-03 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/camel-simple-data-wrapper.c (_construct_from_stream):
more debugging output + nb_bytes_read is now a signed int
to avoid bug when eos is encountered.
* camel/camel-mime-part.c (_construct_from_stream):
sync to data_wrapper_repository function name changes.
Use default "text/plain" type when conten-type field
is not found. (following RFC 2046 spec).
* camel/data-wrapper-repository.c (data_wrapper_repository_set_data_wrapper_type):
(data_wrapper_repository_get_data_wrapper_type):
change function name prefix (s/data_wrapper/data_wrapper_repository/)
* camel/camel-multipart.c (_read_part):
add `\n` at eol but not before boundary.
* camel/gmime-utils.c (get_header_table_from_stream):
correct implementation of end of stream detection.
svn path=/trunk/; revision=1070
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | camel/camel-mime-part.c | 13 | ||||
-rw-r--r-- | camel/camel-multipart.c | 24 | ||||
-rw-r--r-- | camel/camel-simple-data-wrapper.c | 26 | ||||
-rw-r--r-- | camel/camel-stream-mem.c | 6 | ||||
-rw-r--r-- | camel/data-wrapper-repository.c | 10 | ||||
-rw-r--r-- | camel/data-wrapper-repository.h | 4 | ||||
-rw-r--r-- | camel/gmime-utils.c | 7 | ||||
-rw-r--r-- | tests/test3.c | 6 |
9 files changed, 82 insertions, 37 deletions
@@ -1,3 +1,24 @@ +1999-08-03 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/camel-simple-data-wrapper.c (_construct_from_stream): + more debugging output + nb_bytes_read is now a signed int + to avoid bug when eos is encountered. + + * camel/camel-mime-part.c (_construct_from_stream): + sync to data_wrapper_repository function name changes. + Use default "text/plain" type when conten-type field + is not found. (following RFC 2046 spec). + + * camel/data-wrapper-repository.c (data_wrapper_repository_set_data_wrapper_type): + (data_wrapper_repository_get_data_wrapper_type): + change function name prefix (s/data_wrapper/data_wrapper_repository/) + + * camel/camel-multipart.c (_read_part): + add `\n` at eol but not before boundary. + + * camel/gmime-utils.c (get_header_table_from_stream): + correct implementation of end of stream detection. + 1999-08-01 bertrand <Bertrand.Guiheneuf@aful.org> * camel/camel-multipart.c (_read_part): @@ -28,7 +49,7 @@ do not return NULL when line is empty. * camel/camel-multipart.c (_read_part): return true when end - of multipart is found, not the contrary + of multipart is found, not the opposite 1999-07-31 bertrand <Bertrand.Guiheneuf@aful.org> diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index 8a3637afa7..bdb36f6748 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -753,16 +753,21 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) 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); + 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_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"); diff --git a/camel/camel-multipart.c b/camel/camel-multipart.c index e0cf2861ac..8362259ea6 100644 --- a/camel/camel-multipart.c +++ b/camel/camel-multipart.c @@ -379,11 +379,13 @@ _read_part (CamelStream *new_part_stream, CamelStream *stream, gchar *normal_bou gchar *new_line; gboolean end_of_part = FALSE; gboolean last_part = FALSE; + gboolean first_line = TRUE; + /* Note for future enhancements */ /* RFC 2046 precises that when parsing the content of a multipart - * element, the program should not think it will find the last bounndary, + * element, the program should not think it will find the last boundary, * and in particular, the message could have been damaged during - * transport, the parsing should be OK */ + * transport, the parsing should still be OK */ CAMEL_LOG_FULL_DEBUG ("CamelMultipart:: Entering _read_part\n"); new_line = gmime_read_line_from_stream (stream); @@ -392,13 +394,17 @@ _read_part (CamelStream *new_part_stream, CamelStream *stream, gchar *normal_bou printf ("++ new line = \"%s\"\n", new_line); end_of_part = (strcmp (new_line, normal_boundary) == 0); last_part = (strcmp (new_line, end_boundary) == 0); - if (!end_of_part && !last_part) - /* new_part = g_string_append (new_part, new_line); */ - camel_stream_write_string (new_part_stream, new_line); - new_line = gmime_read_line_from_stream (stream); + if (!end_of_part && !last_part) { + if (first_line) { + camel_stream_write_string (new_part_stream, "\n"); + first_line = FALSE; + } + camel_stream_write_strings (new_part_stream, "\n", new_line, NULL); + new_line = gmime_read_line_from_stream (stream); + } } CAMEL_LOG_FULL_DEBUG ("CamelMultipart:: Leaving _read_part\n"); - return (last_part && !new_line); + return (last_part || (new_line == NULL)); } static void @@ -423,7 +429,9 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) /* read the prefix if any */ - //end_of_multipart = _read_part (new_part, stream, real_boundary_line, end_boundary_line); + new_part_stream = camel_stream_mem_new (CAMEL_STREAM_MEM_RW); + end_of_multipart = _read_part (new_part_stream, stream, real_boundary_line, end_boundary_line); + gtk_object_destroy (GTK_OBJECT (new_part_stream)); if (multipart->preface) g_free (multipart->preface); //if ( (new_part->str)[0] != '\0') multipart->preface = g_strdup (new_part->str); diff --git a/camel/camel-simple-data-wrapper.c b/camel/camel-simple-data-wrapper.c index eaf62bb0a7..a2203a52e8 100644 --- a/camel/camel-simple-data-wrapper.c +++ b/camel/camel-simple-data-wrapper.c @@ -122,28 +122,36 @@ static void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { CamelSimpleDataWrapper *simple_data_wrapper = CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper); - guint current_index; - guint nb_bytes_read; - guint nb_bytes_left; + gint nb_bytes_read; static gchar *tmp_buf; GByteArray *array; + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering _construct_from_stream\n"); g_assert (data_wrapper); g_assert (stream); - if (!tmp_buf) tmp_buf = g_new (gchar, _CMSDW_TMP_BUF_SIZE); - + if (!tmp_buf) { + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream allocating new temp buffer " + "with %d bytes\n", _CMSDW_TMP_BUF_SIZE); + tmp_buf = g_new (gchar, _CMSDW_TMP_BUF_SIZE); + } + array = simple_data_wrapper->byte_array; - if (array) + if (array) { + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream freeing old byte array\n"); g_byte_array_free (array, FALSE); + } array = g_byte_array_new(); + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream new byte array address:%p\n", array); simple_data_wrapper->byte_array = array; - do { + nb_bytes_read = camel_stream_read (stream, tmp_buf, _CMSDW_TMP_BUF_SIZE); + while (nb_bytes_read>0) { + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream read %d bytes from stream\n", nb_bytes_read); + if (nb_bytes_read>0) g_byte_array_append (array, tmp_buf, nb_bytes_read); nb_bytes_read = camel_stream_read (stream, tmp_buf, _CMSDW_TMP_BUF_SIZE); - if (nb_bytes_read) g_byte_array_append (array, tmp_buf, nb_bytes_read); - } while (nb_bytes_read); + }; CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Leaving _construct_from_stream\n"); } diff --git a/camel/camel-stream-mem.c b/camel/camel-stream-mem.c index 55900554ab..2fa2c7c306 100644 --- a/camel/camel-stream-mem.c +++ b/camel/camel-stream-mem.c @@ -125,10 +125,11 @@ _read (CamelStream *stream, gchar *buffer, gint n) g_assert (stream); nb_bytes_to_read = MIN (n, (camel_stream_mem->buffer)->len - camel_stream_mem->position); - if (nb_bytes_to_read) { + if (nb_bytes_to_read>0) { memcpy (buffer, (camel_stream_mem->buffer)->data + camel_stream_mem->position, nb_bytes_to_read); camel_stream_mem->position += nb_bytes_to_read; - } + } else nb_bytes_to_read = -1; + return nb_bytes_to_read; } @@ -150,6 +151,7 @@ _write (CamelStream *stream, const gchar *buffer, gint n) CamelStreamMem *camel_stream_mem = CAMEL_STREAM_MEM (stream); g_assert (stream); + g_return_val_if_fail (camel_stream_mem->position>=0, -1); camel_stream_mem->buffer = g_byte_array_append (camel_stream_mem->buffer, (const guint8 *)buffer, n); camel_stream_mem->position += n; diff --git a/camel/data-wrapper-repository.c b/camel/data-wrapper-repository.c index 147a92b831..d579f95c4f 100644 --- a/camel/data-wrapper-repository.c +++ b/camel/data-wrapper-repository.c @@ -47,21 +47,21 @@ data_wrapper_repository_init () { if (_initialized != -1) return -1; _repository.mime_links = g_hash_table_new (g_str_hash, g_str_equal); - data_wrapper_set_data_wrapper_type ("multipart", camel_multipart_get_type()); + data_wrapper_repository_set_data_wrapper_type ("multipart", camel_multipart_get_type()); _content_field = gmime_content_field_new (NULL, NULL); _initialized = 1; return 1; } /** - * data_wrapper_set_data_wrapper_type: associate a data wrapper object type to a mime type + * data_wrapper_repository_set_data_wrapper_type: associate a data wrapper object type to a mime type * @mime_type: mime type * @object_type: object type * * Associate an object type to a mime type. **/ void -data_wrapper_set_data_wrapper_type (const gchar *mime_type, GtkType object_type) +data_wrapper_repository_set_data_wrapper_type (const gchar *mime_type, GtkType object_type) { gboolean already_exists; gchar *old_mime_type; @@ -78,7 +78,7 @@ data_wrapper_set_data_wrapper_type (const gchar *mime_type, GtkType object_type) /** - * data_wrapper_get_data_wrapper_type: get the gtk type object associated to a mime type + * data_wrapper_repository_get_data_wrapper_type: get the gtk type object associated to a mime type * @mime_type: mime type * * returns the GtkType of the data wrapper object associated to @@ -94,7 +94,7 @@ data_wrapper_set_data_wrapper_type (const gchar *mime_type, GtkType object_type) * Return value: the associated data wrapper object type. **/ GtkType -data_wrapper_get_data_wrapper_type (const gchar *mime_type) +data_wrapper_repository_get_data_wrapper_type (const gchar *mime_type) { gboolean exists; gchar *old_mime_type; diff --git a/camel/data-wrapper-repository.h b/camel/data-wrapper-repository.h index 06738db585..7c8f3f17cd 100644 --- a/camel/data-wrapper-repository.h +++ b/camel/data-wrapper-repository.h @@ -42,8 +42,8 @@ typedef struct { gint data_wrapper_repository_init (); -void data_wrapper_set_data_wrapper_type (const gchar *mime_type, GtkType object_type); -GtkType data_wrapper_get_data_wrapper_type (const gchar *mime_type); +void data_wrapper_repository_set_data_wrapper_type (const gchar *mime_type, GtkType object_type); +GtkType data_wrapper_repository_get_data_wrapper_type (const gchar *mime_type); #ifdef __cplusplus diff --git a/camel/gmime-utils.c b/camel/gmime-utils.c index 55a6ab0be1..7698d01039 100644 --- a/camel/gmime-utils.c +++ b/camel/gmime-utils.c @@ -127,8 +127,10 @@ _store_header_pair_from_string (GHashTable *header_table, gchar *header_line) STRING_DICHOTOMY_NONE); if (dich_result != 'o') CAMEL_LOG_WARNING ( - "store_header_pair_from_string : dichotomy result is %c" - "header line is :\n--\n%s\n--\n"); + "** WARNING **\n" + "store_header_pair_from_string : dichotomy result is '%c'\n" + "header line is :\n--\n%s\n--\n" + "** \n", dich_result, header_line); else { string_trim (header_value, " \t", STRING_TRIM_STRIP_LEADING | STRING_TRIM_STRIP_TRAILING); @@ -160,7 +162,6 @@ get_header_table_from_stream (CamelStream *stream) GHashTable *header_table; gint nb_char_read; -#warning Correct a bug here. Should use return value of camel_stream_read instead of looking for next_char!=-1 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); nb_char_read = camel_stream_read (stream, &next_char, 1); diff --git a/tests/test3.c b/tests/test3.c index a210ea3723..b036c190f5 100644 --- a/tests/test3.c +++ b/tests/test3.c @@ -12,15 +12,15 @@ main (int argc, char**argv) printf ("Test 3 : data wrapper repository\n"); printf ("\nMime type : \"multipart\"\n"); - type = data_wrapper_get_data_wrapper_type ("multipart"); + type = data_wrapper_repository_get_data_wrapper_type ("multipart"); printf ("Type found %s\n", gtk_type_name (type) ); printf ("\nMime type : \"multipart/alternative\"\n"); - type = data_wrapper_get_data_wrapper_type ("multipart/alternative"); + type = data_wrapper_repository_get_data_wrapper_type ("multipart/alternative"); printf ("Type found %s\n", gtk_type_name (type) ); printf ("\nMime type : \"toto/titi\"\n"); - type = data_wrapper_get_data_wrapper_type ("toto/titi"); + type = data_wrapper_repository_get_data_wrapper_type ("toto/titi"); printf ("Type found %s\n", gtk_type_name (type) ); printf ("Test3 finished\n"); |