diff options
author | NotZed <NotZed@HelixCode.com> | 2000-04-23 18:10:44 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-04-23 18:10:44 +0800 |
commit | 5fcb83b5fb1294a781e3f7139200aa3486650db4 (patch) | |
tree | a890998dfce162ec25eb55b238e537f506abb6c1 /camel/camel-mime-part.c | |
parent | f229f08168b0666469e0fc35d065860f2da58303 (diff) | |
download | gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar.gz gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar.zst gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.zip |
Whole swag of changes. Still lots of cleanup remaining ...
2000-04-23 NotZed <NotZed@HelixCode.com>
* camel-data-wrapper.c (set_mime_type_field): Ref the
content_field when we get it?
* camel-mime-parser.c (camel_mime_parser_unstep): New function.
Cause a subsequent call to mime_parser_step() to return the same
state over again.
* providers/mbox/camel-mbox-folder.c (_get_message_by_uid):
Initial test code using the mime parser to construct the message.
* camel-mime-part.c (construct_from_parser): part constructor.
(camel_mime_part_construct_content): Basically a simpler
replacement for the datawrapper repository.
(camel_mime_part_init): Set the default type to text/plain.
* camel-simple-data-wrapper.c (construct_from_parser): Initial
implementation of a content constructor.
* camel-multipart.c (construct_from_parser): Multipart
construction routine.
(camel_multipart_init): Set the default multipart type to
multipart/mixed. Duh, no subtype is not allowed anyway.
2000-04-22 NotZed <NotZed@HelixCode.com>
* camel-mime-message.h (struct _CamelMimeMessage): Removed
send_date, and received_date, and replaced it with a time_t
'date' (this is what the header is called), and date_offset to
store the GMT offset of the date.
* camel-mime-message.c (camel_mime_message_set_from): Update raw
header as we go.
(_set_from): Removed.
(_get_from): Removed.
(camel_mime_message_get_from): Moved implementation here.
(camel_mime_message_get_subject): Move implementation here.
(_get_subject): Nuked.
(camel_mime_message_set_subject): Handle utf-8 input, and also
update raw header when changed.
(_set_subject): Removed.
(_set_received_date): Removed.
(camel_mime_message_set_received_date): Removed.
(_get_received_date): Removed.
(camel_mime_message_get_received_date): Removed.
(_get_sent_date): Removed.
(camel_mime_message_get_sent_date): Removed.
(camel_mime_message_get_date): New function to get the date as a
time_t/offset.
(camel_mime_message_set_date): Set the date as a time_t/offset.
(camel_mime_message_get_date_string): Get the date as a string.
(camel_mime_message_init): Initialise the current date as
'CMAEL_MESSAGE_DATE_CURRENT'.
(_set_reply_to): Removed.
(camel_mime_message_set_reply_to): Moved implementation here.
This is still broken, reply-to can have multiple addresses.
(_get_reply_to): Removed.
(_set_field): Removed, no longer used anywhere.
(_get_field): Also removed.
(_init_header_name_table): Add the Date header.
(process_header): Also handle snooping of Date header here.
* camel-stream-filter.c (finalise): Unref the source stream on
finalise, and also call the parent class (oops).
* camel-mime-parser.c (camel_mime_parser_state): New function to
get the current parser state.
(camel_mime_parser_stream): Allow you to get the stream back from
the mime_parser.
(camel_mime_parser_fd): Alternative to allow you to get the fd
back from the mime_parser.
(folder_scan_init_with_stream): Properly ref/unref the stream.
(folder_scan_close): Properly unref the stream/close the fd on
exit.
(folder_scan_init_with_fd): Close the old fd if there is one.
* camel-data-wrapper.c (camel_data_wrapper_construct_from_parser):
New method, construct a data wrapper from an initialised parser.
(construct_from_parser): Empty implementation.
* providers/mbox/camel-mbox-summary.c (message_struct_new):
Convert subject line to unicode, before storing in the summary.
(strdup_trim): Removed, no longer needed.
* providers/mbox/camel-mbox-folder.c (_get_message_by_uid): Ref
the folder after setting it in the new message.
* camel-mime-part.c (my_set_content_object): Have the headers
follow the content-type change here too.
(my_write_to_stream): Dont write content-type here, automatically
stored in the headers ...
(my_write_to_stream): Use header_disposition_format() to format
the content-disposition header.
(my_write_to_stream): Removed old code, all headers are now stored
in the camel-medium level, always. Need to do the same with
camel-mime-message i suppose ...
(my_write_to_stream): Write the content using the parent class,
not some weird function.
(camel_mime_part_class_init): Dont override get_output_stream.
(camel_mime_part_encoding_from_string): Bleh, make it
case-insensitive.
* camel-mime-utils.c (header_content_type_is): Handle empty types.
(header_encode_string): Start of an implementation of the rfc2047
encoder. It does iso-8859-1, and us-ascii, and utf-8 (others get
tricky *sigh*)
(rfc2047_encode_word): Convert a single word/string into rfc2047
encoding.
(quoted_encode): Different quoted-printable encoding for rfc2047
encoding of headers.
* gmime-content-field.c (gmime_content_field_write_to_stream): Use
header_content_type_format() to format it.
svn path=/trunk/; revision=2560
Diffstat (limited to 'camel/camel-mime-part.c')
-rw-r--r-- | camel/camel-mime-part.c | 119 |
1 files changed, 109 insertions, 10 deletions
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index bda4f932ed..78f1897e8b 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -37,7 +37,16 @@ #include "camel-seekable-substream.h" #include "camel-stream-filter.h" #include "camel-mime-filter-basic.h" +#include "camel-mime-filter-charset.h" #include <ctype.h> +#include "camel-mime-parser.h" + +/* ick, this shouldn't need to know about the parent types ... then again the repository does *sigh* */ +#include "camel-mime-message.h" +#include "camel-multipart.h" +#include "camel-mime-body-part.h" + +#define d(x) typedef enum { HEADER_UNKNOWN, @@ -69,6 +78,7 @@ static void my_write_to_stream (CamelDataWrapper *data_w CamelStream *stream); static void my_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); +static void construct_from_parser (CamelDataWrapper *, CamelMimeParser *); static void my_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); static CamelStream * my_get_output_stream (CamelDataWrapper *data_wrapper); @@ -122,8 +132,9 @@ camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class) camel_data_wrapper_class->write_to_stream = my_write_to_stream; camel_data_wrapper_class->construct_from_stream = my_construct_from_stream; + camel_data_wrapper_class->construct_from_parser = construct_from_parser; camel_data_wrapper_class->set_input_stream = my_set_input_stream; - camel_data_wrapper_class->get_output_stream = my_get_output_stream; +/* camel_data_wrapper_class->get_output_stream = my_get_output_stream;*/ gtk_object_class->finalize = my_finalize; } @@ -133,7 +144,7 @@ camel_mime_part_init (gpointer object, gpointer klass) { CamelMimePart *camel_mime_part = CAMEL_MIME_PART (object); - camel_mime_part->content_type = gmime_content_field_new (NULL, NULL); + camel_mime_part->content_type = gmime_content_field_new ("text", "plain"); camel_mime_part->description = NULL; camel_mime_part->disposition = NULL; camel_mime_part->content_id = NULL; @@ -224,7 +235,7 @@ process_header(CamelMedium *medium, const char *header_name, const char *header_ break; case HEADER_ENCODING: text = header_token_decode(header_value); - camel_mime_part_set_encoding(mime_part, camel_mime_part_encoding_from_string (text)); + mime_part->encoding = camel_mime_part_encoding_from_string (text); g_free(text); break; case HEADER_CONTENT_MD5: @@ -498,10 +509,14 @@ my_get_content_object (CamelMedium *medium) CamelStream *decoded_stream; CamelMimeFilter *mf = NULL; + d(printf("getting content object? for %p\n", medium)); + if (!medium->content ) { stream = mime_part->content_input_stream; decoded_stream = stream; + g_warning("No content object, this old code is probably going to crash ..."); + switch (mime_part->encoding) { case CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE: mf = (CamelMimeFilter *)camel_mime_filter_basic_new_type(CAMEL_MIME_FILTER_BASIC_QP_DEC); @@ -606,8 +621,7 @@ my_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) CamelMimePart *mp = CAMEL_MIME_PART (data_wrapper); CamelMedium *medium = CAMEL_MEDIUM (data_wrapper); - /* FIXME: something needs to be done about this ... */ - gmime_write_header_with_glist_to_stream (stream, "Content-Language", mp->content_languages,", "); + d(printf("mime_part::write_to_stream\n")); #warning This class should NOT BE WRITING the headers out if (medium->headers) { @@ -618,8 +632,24 @@ my_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) } } + /* FIXME: something needs to be done about this ... */ + gmime_write_header_with_glist_to_stream (stream, "Content-Language", mp->content_languages,", "); + camel_stream_write_string(stream,"\n"); - my_write_content_to_stream (mp, stream); + +#if 1 + { + CamelDataWrapper *content = camel_medium_get_content_object (CAMEL_MEDIUM (data_wrapper)); + if (content) { + camel_data_wrapper_write_to_stream(content, stream); + } else { + g_warning("No content for data wrapper"); + } + } +#else + ((CamelDataWrapperClass *)parent_class)->write_to_stream (data_wrapper, stream); +#endif + /*my_write_content_to_stream (mp, stream);*/ } @@ -636,7 +666,76 @@ my_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) } +/* FIXME: this should be in another file ... */ +/* This replaces the data wrapper repository ... and/or could be replaced by it? */ +static void +camel_mime_part_construct_content(CamelDataWrapper *dw, CamelMimeParser *mp) +{ + CamelDataWrapper *content = NULL; + int state; + switch ((state = camel_mime_parser_state(mp))) { + case HSCAN_HEADER: + d(printf("Creating body part\n")); + content = (CamelDataWrapper *)camel_simple_data_wrapper_new(); + break; + case HSCAN_MESSAGE: + d(printf("Creating message part\n")); + content = (CamelDataWrapper *)camel_mime_message_new(); + break; + case HSCAN_MULTIPART: + d(printf("Creating multi-part\n")); + content = (CamelDataWrapper *)camel_multipart_new(); + break; + default: + g_warning("Invalid state encountered???: %d", camel_mime_parser_state(mp)); + } + if (content) { + camel_data_wrapper_construct_from_parser(content, mp); +#warning there just has got to be a better way ... to transfer the mime-type to the datawrapper + /* would you believe you have to set this BEFORE you set the content object??? oh my god !!!! */ + camel_data_wrapper_set_mime_type_field (content, + camel_mime_part_get_content_type ((CamelMimePart *)dw)); + camel_medium_set_content_object((CamelMedium *)dw, content); + } + /* this should probably go into camel-mime-message::construct_from_parser */ + if (state == HSCAN_MESSAGE) { + char *buf; + int len; + + if (camel_mime_parser_step(mp, &buf, &len) != HSCAN_MESSAGE_END) { + g_warning("Bad parser state: Expecing MESSAGE_EOF, got: %d", camel_mime_parser_state(mp)); + camel_mime_parser_unstep(mp); + } + } +} + +/* mime_part */ +static void +construct_from_parser(CamelDataWrapper *dw, CamelMimeParser *mp) +{ + struct _header_raw *headers; + char *buf; + int len; + + d(printf("constructing mime-part\n")); + + switch (camel_mime_parser_step(mp, &buf, &len)) { + case HSCAN_HEADER: + case HSCAN_MESSAGE: + case HSCAN_MULTIPART: + /* we have the headers, build them into 'us' */ + headers = camel_mime_parser_headers_raw(mp); + while (headers) { + camel_medium_add_header((CamelMedium *)dw, headers->name, headers->value); + headers = headers->next; + } + camel_mime_part_construct_content(dw, mp); + break; + default: + g_warning("Invalid state encountered???: %d", camel_mime_parser_state(mp)); + } +} static void my_set_input_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) @@ -734,13 +833,13 @@ camel_mime_part_encoding_from_string (const gchar *string) { if (string == NULL) return CAMEL_MIME_PART_ENCODING_DEFAULT; - else if (strcmp (string, "7bit") == 0) + else if (strcasecmp (string, "7bit") == 0) return CAMEL_MIME_PART_ENCODING_7BIT; - else if (strcmp (string, "8bit") == 0) + else if (strcasecmp (string, "8bit") == 0) return CAMEL_MIME_PART_ENCODING_8BIT; - else if (strcmp (string, "base64") == 0) + else if (strcasecmp (string, "base64") == 0) return CAMEL_MIME_PART_ENCODING_BASE64; - else if (strcmp (string, "quoted-printable") == 0) + else if (strcasecmp (string, "quoted-printable") == 0) return CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE; else /* FIXME? Spit a warning? */ |