sync before going home

svn path=/trunk/; revision=1064
This commit is contained in:
Bertrand Guiheneuf
1999-08-02 15:11:10 +00:00
parent 9a87a9ff78
commit e04ff08029
6 changed files with 76 additions and 44 deletions

View File

@ -1,4 +1,9 @@
1999-08-01 root <guiheneu@jean.joudboeuf.fr>
1999-08-02 root <guiheneu@linoleum.inria.fr>
* camel/gmime-utils.c (gmime_write_header_pair_to_stream):
corrected a bug with memory not allocated for '\0' in strtmp
1999-08-01 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/gmime-utils.c (gmime_read_line_from_stream):
do not return NULL when line is empty.

View File

@ -796,9 +796,11 @@ camel_mime_part_set_text (CamelMimePart *camel_mime_part, gchar *text)
}
if (text) {
simple_data_wrapper = camel_simple_data_wrapper_new ();
camel_mime_part->content = CAMEL_DATA_WRAPPER (simple_data_wrapper);
//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_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (simple_data_wrapper), "text/plain");
camel_simple_data_wrapper_set_text ( simple_data_wrapper, text);
camel_mime_part_set_content_object (camel_mime_part, CAMEL_DATA_WRAPPER (simple_data_wrapper));
} else camel_mime_part->content = NULL;
CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving camel_mime_part_set_text\n");

View File

@ -27,6 +27,7 @@
#include "camel-log.h"
#include "gmime-content-field.h"
#include "gmime-utils.h"
#include "camel-stream-mem.h"
static void _add_part (CamelMultipart *multipart, CamelMimeBodyPart *part);
@ -80,6 +81,8 @@ camel_multipart_init (gpointer object, gpointer klass)
CamelMultipart *multipart = CAMEL_MULTIPART (object);
camel_data_wrapper_set_mime_type ( CAMEL_DATA_WRAPPER (multipart), "multipart");
camel_multipart_set_boundary (multipart, "__camel_boundary__");
multipart->preface = NULL;
multipart->postface = NULL;
}
@ -357,7 +360,7 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
/**
* _read_part: read one part in a multipart environement.
* @part: GString to add the part to
* @new_part_stream: stream to add the part to
* @stream: the stream to read the lines from.
* @normal_boundary: end of part bundary.
* @end_boundary: end of multipart boundary.
@ -371,7 +374,7 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
**/
static gboolean
_read_part (GString *new_part, CamelStream *stream, gchar *normal_boundary, gchar *end_boundary)
_read_part (CamelStream *new_part_stream, CamelStream *stream, gchar *normal_boundary, gchar *end_boundary)
{
gchar *new_line;
gboolean end_of_part = FALSE;
@ -399,7 +402,8 @@ _read_part (GString *new_part, CamelStream *stream, gchar *normal_boundary, gcha
pending_crlf = TRUE;
new_line[line_length-1]='\0';
}
new_part = g_string_append (new_part, new_line);
//new_part = g_string_append (new_part, new_line);
}
}
@ -412,7 +416,8 @@ _read_part (GString *new_part, CamelStream *stream, gchar *normal_boundary, gcha
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);
/* 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);
}
CAMEL_LOG_FULL_DEBUG ("CamelMultipart:: Leaving _read_part\n");
@ -426,7 +431,7 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
const gchar *boundary;
gchar *real_boundary_line;
gchar *end_boundary_line;
GString *new_part;
CamelStream *new_part_stream;
gboolean end_of_multipart;
CamelMimeBodyPart *body_part;
@ -437,29 +442,34 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
real_boundary_line = g_strdup_printf ("--%s", boundary);
end_boundary_line = g_strdup_printf ("--%s--", boundary);
new_part = g_string_new ("");
//new_part = g_string_new ("");
/* read the prefix if any */
end_of_multipart = _read_part (new_part, stream, real_boundary_line, end_boundary_line);
//end_of_multipart = _read_part (new_part, stream, real_boundary_line, end_boundary_line);
if (multipart->preface) g_free (multipart->preface);
if ( (new_part->str)[0] != '\0') multipart->preface = g_strdup (new_part->str);
//if ( (new_part->str)[0] != '\0') multipart->preface = g_strdup (new_part->str);
/* read all the real parts */
while (!end_of_multipart) {
CAMEL_LOG_FULL_DEBUG ("CamelMultipart::construct_from_stream, detected a new part\n");
g_string_assign (new_part, "");
new_part_stream = camel_stream_mem_new (CAMEL_STREAM_MEM_RW);
body_part = camel_mime_body_part_new ();
//camel_data_wrapper_construct_from_stream ();
end_of_multipart = _read_part ( new_part_stream, stream, real_boundary_line, end_boundary_line);
camel_stream_seek (new_part_stream, 0, CAMEL_STREAM_SET);
camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (body_part), new_part_stream);
camel_multipart_add_part (multipart, body_part);
end_of_multipart = _read_part (new_part, stream, real_boundary_line, end_boundary_line);
gtk_object_destroy (GTK_OBJECT (new_part_stream));
}
g_string_assign (new_part, "");
_read_part (new_part, stream, real_boundary_line, end_boundary_line);
//g_string_assign (new_part, "");
//_read_part (new_part, stream, real_boundary_line, end_boundary_line);
if (multipart->postface) g_free (multipart->postface);
if ( (new_part->str)[0] != '\0') multipart->postface = g_strdup (new_part->str);
//if ( (new_part->str)[0] != '\0') multipart->postface = g_strdup (new_part->str);
g_string_free (new_part, TRUE);
//g_string_free (new_part, TRUE);
g_free (real_boundary_line);
g_free (end_boundary_line);
CAMEL_LOG_FULL_DEBUG ("Leaving CamelMultipart::_construct_from_stream\n");

View File

@ -96,6 +96,15 @@ camel_stream_mem_get_type (void)
}
CamelStream *
camel_stream_mem_new (CamelStreamMemMode mode)
{
CamelStreamMem *stream_mem;
stream_mem = gtk_type_new (camel_stream_mem_get_type ());
stream_mem->mode = mode;
return CAMEL_STREAM (stream_mem);
}
/**

View File

@ -43,7 +43,8 @@ extern "C" {
typedef enum
{
CAMEL_STREAM_MEM_READ = 1,
CAMEL_STREAM_MEM_WRITE = 2
CAMEL_STREAM_MEM_WRITE = 2,
CAMEL_STREAM_MEM_RW = 3
} CamelStreamMemMode;
@ -72,7 +73,7 @@ GtkType camel_stream_mem_get_type (void);
/* public methods */
CamelStream *camel_stream_mem_new (CamelStreamMemMode mode);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -38,13 +38,14 @@ gmime_write_header_pair_to_stream (CamelStream *stream, const gchar* name, const
#warning use g_strdup_printf instead
if (!value) return;
len = strlen (name) + strlen (value) +3;
/* 3 is for ": " and "\n" */
len = strlen (name) + strlen (value) +4;
/* 4 is for ": " and "\n\0" */
strtmp = g_new (gchar, len);
sprintf (strtmp, "%s: %s\n", name, value);
camel_stream_write (stream, strtmp, len);
CAMEL_LOG_FULL_DEBUG ( "gmime_write_header_pair_to_stream:\n writing %s\n", strtmp);
g_free (strtmp);
CAMEL_LOG_FULL_DEBUG ( "gmime_write_header_pair_to_stream:: Leaving\n");
@ -157,10 +158,12 @@ get_header_table_from_stream (CamelStream *stream)
GString *header_line=NULL;
gchar *str_header_line;
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);
camel_stream_read (stream, &next_char, 1);
nb_char_read = camel_stream_read (stream, &next_char, 1);
do {
header_line = g_string_new ("");
end_of_header_line = FALSE;
@ -168,33 +171,35 @@ get_header_table_from_stream (CamelStream *stream)
/* read a whole header line */
do {
switch (next_char) {
case -1:
if (nb_char_read>0) {
switch (next_char) {
case '\n': /* a blank line means end of headers */
if (crlf) {
end_of_headers=TRUE;
end_of_header_line = TRUE;
}
else crlf = TRUE;
break;
case ' ':
case '\t':
if (crlf) {
crlf = FALSE;
next_char = ' ';
}
default:
if (!crlf) header_line = g_string_append_c (header_line, next_char);
else end_of_header_line = TRUE;
}
} else {
end_of_file=TRUE;
end_of_header_line = TRUE;
break;
case '\n': /* a blank line means end of headers */
if (crlf) {
end_of_headers=TRUE;
end_of_header_line = TRUE;
}
else crlf = TRUE;
break;
case ' ':
case '\t':
if (crlf) {
crlf = FALSE;
next_char = ' ';
}
default:
if (!crlf) header_line = g_string_append_c (header_line, next_char);
else end_of_header_line = TRUE;
}
/* if we have read a whole header line, we have also read
the first character of the next line to be sure the
crlf was not followed by a space or a tab char */
if (!end_of_header_line) camel_stream_read (stream, &next_char, 1);
if (!end_of_header_line) nb_char_read = camel_stream_read (stream, &next_char, 1);
} while ( !end_of_header_line );
if ( strlen(header_line->str) ) {