diff options
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | camel/camel-mime-message.c | 2 | ||||
-rw-r--r-- | camel/camel-mime-part.c | 23 | ||||
-rw-r--r-- | camel/gmime-content-field.c | 63 | ||||
-rw-r--r-- | camel/gmime-utils.c | 64 | ||||
-rw-r--r-- | tests/test2.c | 2 |
6 files changed, 108 insertions, 63 deletions
@@ -1,3 +1,20 @@ +1999-06-21 root <guiheneu@linoleum.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 + 1999-06-03 bertrand <Bertrand.Guiheneuf@inria.fr> * devel-docs/query/virtual-folder-in-depth.sgml: diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c index dd984fbeac..fc4d28eced 100644 --- a/camel/camel-mime-message.c +++ b/camel/camel-mime-message.c @@ -563,7 +563,7 @@ _set_recipient_list_from_string (CamelMimeMessage *message, GString *recipient_t { GList *recipients_list; CAMEL_LOG (FULL_DEBUG,"CamelMimeMessage::_set_recipient_list_from_string parsing ##%s##\n", recipients_string->str); - recipients_list = g_string_split (recipients_string, ',', " ", TRIM_STRIP_TRAILING | TRIM_STRIP_LEADING); + recipients_list = g_string_split (recipients_string, ',', "\t ", TRIM_STRIP_TRAILING | TRIM_STRIP_LEADING); g_hash_table_insert (message->recipients, recipient_type, recipients_list); } diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index 503e303c06..2d294b6b8b 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -36,8 +36,11 @@ typedef enum { HEADER_CONTENT_ID, HEADER_ENCODING, HEADER_CONTENT_MD5, - HEADER_CONTENT_LANGUAGES + HEADER_CONTENT_LANGUAGES, + HEADER_CONTENT_TYPE } CamelHeaderType; + + static GHashTable *header_name_table; @@ -72,6 +75,9 @@ static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *strea static gboolean _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value); +/* loads in a hash table the set of header names we */ +/* recognize and associate them with a unique enum */ +/* identifier (see CamelHeaderType above) */ static void _init_header_name_table() { @@ -81,6 +87,7 @@ _init_header_name_table() 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); } @@ -165,7 +172,10 @@ _add_header (CamelMimePart *mime_part, GString *header_name, GString *header_val gboolean header_exists; GString *old_header_name; GString *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 */ if (CMP_CLASS(mime_part)->parse_header_pair (mime_part, header_name, header_value)) return; header_exists = g_hash_table_lookup_extended (mime_part->headers, header_name, @@ -604,6 +614,15 @@ _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *hea header_handled = TRUE; break; + case HEADER_CONTENT_TYPE: + CAMEL_LOG (FULL_DEBUG, + "CamelMimePart::parse_header_pair found HEADER_CONTENT_TYPE: %s\n", + header_value->str ); + + /* CMP_CLASS(mime_part)->set_content_MD5 (mime_part, header_value); */ + header_handled = TRUE; + break; + } diff --git a/camel/gmime-content-field.c b/camel/gmime-content-field.c index 87ceaf39f0..6cd368664e 100644 --- a/camel/gmime-content-field.c +++ b/camel/gmime-content-field.c @@ -90,7 +90,7 @@ gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStre 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->type->str, NULL); + camel_stream_write_strings (stream, "/", content_field->subtype->str, NULL); } /* print all parameters */ g_hash_table_foreach (content_field->parameters, _print_parameter, stream); @@ -99,3 +99,64 @@ gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStre } } +GMimeContentField * +gmime_content_field_construct_from_string (GString *string) +{ + GMimeContentField *cf; + gint first, len; + gchar *str; + gint i=0; + GString *type, *subtype; + GString *param_name, *param_value; + gboolean param_end; + + g_assert (string); + g_assert (string->str); + + cf = g_new (GMimeContentField,1); + str = string->str; + first = 0; + len = string->len; + if (!len) return NULL; + + /* find the type */ + while ( (i<len) && (!strchr ("/;", str[i])) ) i++; + + if (i == 0) return NULL; + + type = g_string_new (strndup (str, i)); + if (i == len) return (gmime_content_field_new (type, NULL)); + + 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)); + } + } + first = i+1; + cf = gmime_content_field_new (type, subtype); + + /* parse parameters list */ + param_end = FALSE; + do { + while ( (i<len) && (str[i] != '=') ) i++; + if ((i == len) || (i==first)) param_end = TRUE; + else { + /* we have found parameter name */ + param_name = g_string_new (strndup (str+first, i-first)); + i++; + first = i; + while ( (i<len) && (str[i] != ';') ) i++; + if (i != first) { + /** ****/ + } else { + + } + } + } while ((!param_end) && (first < len)); + + return cf; +} diff --git a/camel/gmime-utils.c b/camel/gmime-utils.c index e2390b1499..917c426801 100644 --- a/camel/gmime-utils.c +++ b/camel/gmime-utils.c @@ -127,62 +127,7 @@ _store_header_pair_from_gstring (GHashTable *header_table, GString *header_line) } -GHashTable * -get_header_table_from_file (FILE *file) -{ - int next_char; - - gboolean crlf = FALSE; - gboolean end_of_header_line = FALSE; - gboolean end_of_headers = FALSE; - gboolean end_of_file = FALSE; - GString *header_line=NULL; - GHashTable *header_table; - - header_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash); - next_char = fgetc (file); - do { - header_line = g_string_new(""); - end_of_header_line = FALSE; - crlf = FALSE; - - /* read a whole header line */ - do { - switch (next_char) { - case EOF: - 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; - - 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) next_char = fgetc (file); - - } while ( !end_of_header_line ); - if ( strlen(header_line->str) ) - _store_header_pair_from_gstring (header_table, header_line); - g_string_free (header_line, FALSE); - - } while ( (!end_of_headers) && (!end_of_file) ); - - return header_table; -} - + GHashTable * get_header_table_from_stream (CamelStream *stream) @@ -218,8 +163,11 @@ get_header_table_from_stream (CamelStream *stream) else crlf = TRUE; break; case ' ': - case 't': - if (crlf) crlf = FALSE; + case '\t': + if (crlf) { + crlf = FALSE; + next_char = ' '; + } default: if (!crlf) header_line = g_string_append_c (header_line, next_char); diff --git a/tests/test2.c b/tests/test2.c index 8d980868d5..6f4ef3fdc6 100644 --- a/tests/test2.c +++ b/tests/test2.c @@ -39,7 +39,7 @@ main (int argc, char**argv) message = camel_mime_message_new_with_session( (CamelSession *)NULL); - input_stream = camel_stream_fs_new_with_name (g_string_new ("mail1.test"), CAMEL_STREAM_FS_READ); + input_stream = camel_stream_fs_new_with_name (g_string_new ("mail.test"), CAMEL_STREAM_FS_READ); if (!input_stream) { perror("could not open input file"); exit(2); |