diff options
author | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-08-01 21:38:28 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-08-01 21:38:28 +0800 |
commit | cac0ba57e6c47acd94600b5add1930301df33c50 (patch) | |
tree | a399fb592b6e5df4afbaa7d1d677d818b3767880 | |
parent | 5709aa9ef61dc720571acec93085f7d2d4ef4758 (diff) | |
download | gsoc2013-evolution-cac0ba57e6c47acd94600b5add1930301df33c50.tar.gz gsoc2013-evolution-cac0ba57e6c47acd94600b5add1930301df33c50.tar.zst gsoc2013-evolution-cac0ba57e6c47acd94600b5add1930301df33c50.zip |
merge a lot of work. Rough ChangeLog will follow
svn path=/trunk/; revision=1052
38 files changed, 1218 insertions, 740 deletions
@@ -1,8 +1,131 @@ -1999-07-15 root <guiheneu@linoleum.inria.fr> +1999-07-31 root <guiheneu@felix.joudboeuf.fr> + + * camel/gmime-utils.c (gmime_read_line_from_stream): + Don't return crlf at end of line. + +1999-07-30 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/gmime-utils.c (gmime_read_line_from_stream): + new function: reads a line from a stream. + should be in streams utils maybe. + +1999-07-29 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/camel-mime-part.c (_construct_from_stream): + Uses data wrapper repository to find what data wrapper + to use to construct the content from a stream. When + no object is registered for the mime type found in + content type field a CamelSimpleDataWrapper is + used. + + * camel/camel-mime-part.c (_get_content_type): + (camel_mime_part_get_content_type): returns + a pointer on the content_type field instead + of the gchar * mime "type/subtype". + +1999-07-28 bertrand <Bertrand.Guiheneuf@aful.org> + + + * camel/data-wrapper-repository.c + * camel/data-wrapper-repository.h + New files. Handles mime type <-> camel object + (for example "multipart" <-> CamelMultipart + * tests/tesst3.c: test data repository thing. + +1999-07-26 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/camel-multipart.c (_write_to_stream): + implemented output of multipart. + + * tests/test1.c (main): testing content objects operations. + +1999-07-25 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/camel-mime-part.c (camel_mime_part_set_text): + new util function to set a mime part content to be + a text string. + + * camel/camel-simple-data-wrapper.c (camel_simple_data_wrapper_set_buffer_from_text): + new util func. + (camel_simple_data_wrapper_new): new func. + + * camel/camel-multipart.c (_write_to_stream): + implemented output of multiparts. + +1999-07-24 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/gmime-content-field.c (gmime_content_field_get_parameter): + New function. Returns the value associated to a + mime parameter. + + +1999-07-22 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/camel-multipart.h: + * camel/camel-multipart.c: + New class. Models multipart mime objects. + + * camel/camel-mime-body-part.h: + * camel/camel-mime-body-part.c: + New class. Body part is a mime part contained in + a multipart object. + + +1999-07-21 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/camel-log.h: + implemented hard log level stuff. + * came/*.c use "CAMEL_LOG_*" instead of "CAMEL_LOG (*" + in order to allow hard level switch. + + * tests/test1.c: + * tests/test2.c: + updated to use gchar instead of GString. Tests passed. + + +1999-07-19 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/camel-stream.c: + * camel/camel-stream.h: + "const"-antified + + + * camel/camel-simple-data-wrapper.c: (_construct_from_stream) + do not use any limit when constructing the object from a stream + + * camel/camel-stream-fs.c: + * camel/camel-stream-fs.h: + * camel/camel-mime-message.c: + * camel/camel-mime-message.h: + * camel/camel-session.c: + * camel/camel-session.h: + * camel/camel-service.c: + * camel/camel-service.h: + * camel/camel-store.c: + * camel/camel-store.h: + * camel/camel-folder.c: + * camel/camel-folder.h: + * camel/gmime-utils.c: + * camel/gmime-utils.h: + GString -> gchar + constantified what had to be. + + * camel/string-utils.c: + * camel/string-utils.h: + New files. Meant to replace gstring-util for gchar * + +1999-07-16 bertrand <Bertrand.Guiheneuf@aful.org> + + * camel/gmime-content-field.c (gmime_content_field_construct_from_string): + GString -> gchar + use const to indicate copied parameter. + +1999-07-15 bertrand <Bertrand.Guiheneuf@aful.org> * camel/camel-simple-data-wrapper.c: * camel/camel-simple-data-wrapper.h: - + Gstring -> gchar + 1999-07-15 bertrand <Bertrand.Guiheneuf@aful.org> * camel/url-util.c: @@ -465,7 +588,7 @@ * camel/camel-folder.h: correct declarations of structs ->>>>>>> 1.36 + 1999-04-22 bertrand <Bertrand.Guiheneuf@aful.org> * camel/providers/MH/camel-mh-store.c: diff --git a/acconfig.h b/acconfig.h index 38d46cf2e4..4ac725695e 100644 --- a/acconfig.h +++ b/acconfig.h @@ -7,6 +7,7 @@ #undef PACKAGE #undef VERSION #undef HAVE_BONOBO +#undef CAMEL_HARD_LOG_LEVEL /* Define this if you want to build against the development gtk */ #undef HAVE_DEVGTK diff --git a/camel/Makefile.am b/camel/Makefile.am index 1d35a897a6..573f256d48 100644 --- a/camel/Makefile.am +++ b/camel/Makefile.am @@ -12,39 +12,49 @@ INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ $(GTK_INCLUDEDIR) libcamel_la_SOURCES = \ + camel.c \ camel-log.c \ camel-data-wrapper.c \ camel-simple-data-wrapper.c \ camel-folder.c \ + camel-mime-body-part.c \ camel-mime-message.c \ camel-mime-part.c \ + camel-multipart.c \ camel-provider.c \ camel-service.c \ camel-session.c \ camel-store.c \ camel-stream.c \ camel-stream-fs.c \ + data-wrapper-repository.c \ gmime-content-field.c \ gmime-utils.c \ gstring-util.c \ + string-utils.c \ url-util.c libcamelinclude_HEADERS = \ + camel.h \ camel-log.h \ camel-data-wrapper.h \ camel-simple-data-wrapper.h \ camel-folder.h \ + camel-mime-body-part.h \ camel-mime-message.h \ camel-mime-part.h \ + camel-multipart.h \ camel-provider.h \ camel-service.h \ camel-session.h \ camel-store.h \ camel-stream.h \ camel-stream-fs.h \ + data-wrapper-repository.h \ gmime-content-field.h \ gmime-utils.h \ gstring-util.h \ + string-utils.h \ url-util.h diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c index b348662808..b6a9f9ea3e 100644 --- a/camel/camel-data-wrapper.c +++ b/camel/camel-data-wrapper.c @@ -6,7 +6,7 @@ /* * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> . + * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -25,6 +25,7 @@ */ #include <config.h> #include "camel-data-wrapper.h" +#include "camel-log.h" static GtkObjectClass *parent_class=NULL; @@ -35,6 +36,9 @@ static void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); static void _set_mime_type (CamelDataWrapper *data_wrapper, gchar *mime_type); static gchar *_get_mime_type (CamelDataWrapper *data_wrapper); +static GMimeContentField *_get_mime_type_field (CamelDataWrapper *data_wrapper); +static void _set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type); + static void camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class) @@ -46,7 +50,8 @@ camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class) camel_data_wrapper_class->construct_from_stream = _construct_from_stream; camel_data_wrapper_class->set_mime_type = _set_mime_type; camel_data_wrapper_class->get_mime_type = _get_mime_type; - + camel_data_wrapper_class->get_mime_type_field = _get_mime_type_field; + camel_data_wrapper_class->set_mime_type_field = _set_mime_type_field; /* virtual method overload */ } @@ -59,7 +64,9 @@ camel_data_wrapper_init (gpointer object, gpointer klass) { CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object); + CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_init:: Entering\n"); camel_data_wrapper->mime_type = gmime_content_field_new (NULL, NULL); + CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_init:: Leaving\n"); } @@ -114,7 +121,7 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) /** * camel_data_wrapper_write_to_stream: write data in a stream - * @data_wrapper: the data wrapper object + * @data_wrappewr: the data wrapper object * @stream: byte stream where data will be written * * Write data content in a stream. Data is stored in a machine @@ -124,7 +131,9 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) void camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { + CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_write_to_stream:: Entering\n"); CDW_CLASS(data_wrapper)->write_to_stream (data_wrapper, stream); + CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_write_to_stream:: Leaving\n"); } @@ -141,7 +150,9 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) void camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { + CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_construct_from_stream:: Entering\n"); CDW_CLASS(data_wrapper)->construct_from_stream (data_wrapper, stream); + CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_construct_from_stream:: Leaving\n"); } @@ -149,8 +160,10 @@ camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelS static void _set_mime_type (CamelDataWrapper *data_wrapper, gchar *mime_type) { + CAMEL_LOG_FULL_DEBUG ( "CamelDataWrapper::set_mime_type Entering\n"); g_assert (mime_type); gmime_content_field_construct_from_string (data_wrapper->mime_type, mime_type); + CAMEL_LOG_FULL_DEBUG ( "CamelDataWrapper::set_mime_type Leaving\n"); } void @@ -168,8 +181,38 @@ _get_mime_type (CamelDataWrapper *data_wrapper) return mime_type; } -static gchar * +gchar * camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper) { + CAMEL_LOG_FULL_DEBUG ( "camel_data_wrapper_get_mime_type:: Entering before returning\n"); return CDW_CLASS(data_wrapper)->get_mime_type (data_wrapper); } + + +static GMimeContentField * +_get_mime_type_field (CamelDataWrapper *data_wrapper) +{ + return data_wrapper->mime_type; +} + +GMimeContentField * +camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper) +{ + return CDW_CLASS(data_wrapper)->get_mime_type_field (data_wrapper); +} + + +static void +_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type) +{ + if (data_wrapper->mime_type) gmime_content_field_free (data_wrapper->mime_type); + data_wrapper->mime_type = mime_type; +} + +void +camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type) +{ + CDW_CLASS(data_wrapper)->set_mime_type_field (data_wrapper, mime_type); +} + + diff --git a/camel/camel-data-wrapper.h b/camel/camel-data-wrapper.h index ff534f9a5a..bee6df1c16 100644 --- a/camel/camel-data-wrapper.h +++ b/camel/camel-data-wrapper.h @@ -59,9 +59,10 @@ typedef struct { /* Virtual methods */ void (*write_to_stream) (CamelDataWrapper *data_wrapper, CamelStream *stream); void (*construct_from_stream) (CamelDataWrapper *data_wrapper, CamelStream *stream); - void (*set_mime_type) (CamelDataWrapper *data_wrapper, gchar *content_type); + void (*set_mime_type) (CamelDataWrapper *data_wrapper, gchar * mime_type); gchar * (*get_mime_type) (CamelDataWrapper *data_wrapper); - + GMimeContentField * (*get_mime_type_field) (CamelDataWrapper *data_wrapper); + void (*set_mime_type_field) (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type_field); } CamelDataWrapperClass; @@ -76,6 +77,8 @@ void camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper, CamelSt void camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); void camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper, gchar *mime_type); static gchar *camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper); +GMimeContentField *camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper); +void camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type); #ifdef __cplusplus } diff --git a/camel/camel-folder.c b/camel/camel-folder.c index 63881d1422..7211ba63f6 100644 --- a/camel/camel-folder.c +++ b/camel/camel-folder.c @@ -22,7 +22,7 @@ */ #include <config.h> #include "camel-folder.h" -#include "gstring-util.h" +#include "string-utils.h" static GtkObjectClass *parent_class=NULL; @@ -32,15 +32,15 @@ static GtkObjectClass *parent_class=NULL; static void _init_with_store (CamelFolder *folder, CamelStore *parent_store); static void _open (CamelFolder *folder, CamelFolderOpenMode mode); static void _close (CamelFolder *folder, gboolean expunge); -static void _set_name (CamelFolder *folder, GString *name_); -static void _set_full_name (CamelFolder *folder, GString *name); -static GString *_get_name (CamelFolder *folder); -static GString *_get_full_name (CamelFolder *folder); +static void _set_name (CamelFolder *folder, const gchar *name); +static void _set_full_name (CamelFolder *folder, const gchar *name); +static const gchar *_get_name (CamelFolder *folder); +static const gchar *_get_full_name (CamelFolder *folder); static gboolean _can_hold_folders (CamelFolder *folder); static gboolean _can_hold_messages(CamelFolder *folder); static gboolean _exists (CamelFolder *folder); static gboolean _is_open (CamelFolder *folder); -static CamelFolder *_get_folder (CamelFolder *folder, GString *folder_name); +static CamelFolder *_get_folder (CamelFolder *folder, const gchar *folder_name); static gboolean _create (CamelFolder *folder); static gboolean _delete (CamelFolder *folder, gboolean recurse); static gboolean _delete_messages (CamelFolder *folder); @@ -118,7 +118,7 @@ camel_folder_get_type (void) * **/ static void -_init_with_store(CamelFolder *folder, CamelStore *parent_store) +_init_with_store (CamelFolder *folder, CamelStore *parent_store) { g_assert(folder); g_assert(parent_store); @@ -131,12 +131,13 @@ _init_with_store(CamelFolder *folder, CamelStore *parent_store) /** * _open: Open a folder - * @folder: + * @folder: The folder object * @mode: open mode (R/W/RW ?) * + * **/ static void -_open(CamelFolder *folder, CamelFolderOpenMode mode) +_open( CamelFolder *folder, CamelFolderOpenMode mode) { folder->open_state = FOLDER_OPEN; folder->open_mode = mode; @@ -152,7 +153,7 @@ _open(CamelFolder *folder, CamelFolderOpenMode mode) * expunge the flagged messages. **/ static void -_close(CamelFolder *folder, gboolean expunge) +_close (CamelFolder *folder, gboolean expunge) { if (expunge) CF_CLASS(folder)->expunge(folder); folder->open_state = FOLDER_CLOSE; @@ -167,14 +168,14 @@ _close(CamelFolder *folder, gboolean expunge) * @name: new name of the folder * * set the name of the folder. - * The old name object is freed. + * * **/ static void -_set_name(CamelFolder *folder, GString *name) +_set_name(CamelFolder *folder, const gchar *name) { - if (folder->name) g_string_free(folder->name, 0);; - folder->name = name; + if (folder->name) g_free(folder->name); + folder->name = g_strdup (name); } @@ -185,14 +186,13 @@ _set_name(CamelFolder *folder, GString *name) * @name: new name of the folder * * set the name of the folder. - * The old name object is freed. * **/ static void -_set_full_name(CamelFolder *folder, GString *name) +_set_full_name (CamelFolder *folder, const gchar *name) { - if (folder->full_name) g_string_free(folder->full_name, 0);; - folder->full_name = name; + if (folder->full_name) g_free(folder->full_name); + folder->full_name = g_strdup (name); } @@ -207,8 +207,8 @@ _set_full_name(CamelFolder *folder, GString *name) * * Return value: name of the folder **/ -static GString * -_get_name(CamelFolder *folder) +static const gchar * +_get_name (CamelFolder *folder) { return folder->name; } @@ -222,8 +222,8 @@ _get_name(CamelFolder *folder) * * Return value: full name of the folder **/ -static GString * -_get_full_name(CamelFolder *folder) +static const gchar * +_get_full_name (CamelFolder *folder) { return folder->full_name; } @@ -232,14 +232,15 @@ _get_full_name(CamelFolder *folder) /** * _can_hold_folders: tests if the folder can contain other folders - * @folder: - * + * @folder: The folder object * + * Tests if a folder can contain other folder + * (as for example MH folders) * * Return value: **/ static gboolean -_can_hold_folders(CamelFolder *folder) +_can_hold_folders (CamelFolder *folder) { return folder->can_hold_folders; } @@ -249,14 +250,16 @@ _can_hold_folders(CamelFolder *folder) /** * _can_hold_messages: tests if the folder can contain messages - * @folder: + * @folder: The folder object * + * Tests if a folder object can contain messages. + * In the case it can not, it most surely can only + * contain folders (rare). * - * - * Return value: + * Return value: true if it can contain messages false otherwise **/ static gboolean -_can_hold_messages(CamelFolder *folder) +_can_hold_messages (CamelFolder *folder) { return folder->can_hold_messages; } @@ -264,15 +267,17 @@ _can_hold_messages(CamelFolder *folder) /** - * _exists: tests if the folder object exists on the store. - * @folder: + * _exists: tests if the folder object exists in its parent store. + * @folder: folder object * + * Test if a folder exists on a store. A folder can be + * created without physically on a store. In that case, + * use CamelFolder::create to create it * - * - * Return value: + * Return value: true if the folder exists on the store false otherwise **/ static gboolean -_exists(CamelFolder *folder) +_exists (CamelFolder *folder) { return folder->exists_on_store; } @@ -280,57 +285,61 @@ _exists(CamelFolder *folder) /** - * _is_open: - * @folder: - * + * _is_open: test if the folder is open + * @folder: The folder object * + * Tests if a folder is open. If not open it can be opened + * CamelFolder::open * - * Return value: + * Return value: true if the folder exists, false otherwise **/ static gboolean -_is_open(CamelFolder *folder) +_is_open (CamelFolder *folder) { return (folder->open_state==FOLDER_OPEN); -} +} /** - * _get_folder: return the (sub)folder object that - * is specified. + * _get_folder: return the (sub)folder object that is specified. + * + * @folder : the folder + * @folder_name: subfolder path. * * This method returns a folder objects. This folder * is necessarily a subfolder of the current folder. * It is an error to ask a folder begining with the * folder separator character. * - * @folder : the folder - * @folderName: subfolder path. NULL if the subfolder object - * could not be created + * + * Return value: Required folder. NULL if the subfolder object + * could not be obtained **/ static CamelFolder * -_get_folder(CamelFolder *folder, GString *folder_name) +_get_folder (CamelFolder *folder, const gchar *folder_name) { g_warning("getFolder called on the abstract CamelFolder class\n"); return NULL; } /** - * camel_folder_get_folder: return the (sub)folder object that - * is specified. + * _get_folder: return the (sub)folder object that is specified. + * + * @folder : the folder + * @folder_name: subfolder path. * * This method returns a folder objects. This folder * is necessarily a subfolder of the current folder. * It is an error to ask a folder begining with the * folder separator character. * - * @folder : the folder - * @folderName: subfolder path. NULL if the subfolder object - * could not be created + * Return value: Required folder. NULL if the subfolder object + * could not be obtained **/ CamelFolder * -camel_folder_get_folder(CamelFolder *folder, GString *folder_name) +camel_folder_get_folder(CamelFolder *folder, gchar *folder_name) { return (CF_CLASS(folder)->get_folder(folder,folder_name)); } @@ -353,7 +362,7 @@ camel_folder_get_folder(CamelFolder *folder, GString *folder_name) static gboolean _create(CamelFolder *folder) { - GString *prefix; + gchar *prefix; gchar dich_result; CamelFolder *parent; gchar sep; @@ -362,24 +371,24 @@ _create(CamelFolder *folder) g_assert(folder->parent_store); g_assert(folder->name); - if (CF_CLASS(folder)->exists(folder)) + if (CF_CLASS(folder)->exists (folder)) return TRUE; - sep = camel_store_get_separator(folder->parent_store); + sep = camel_store_get_separator (folder->parent_store); if (folder->parent_folder) - camel_folder_create(folder->parent_folder); + camel_folder_create (folder->parent_folder); else { if (folder->full_name) { - dich_result = g_string_dichotomy( + dich_result = string_dichotomy ( folder->full_name, sep, &prefix, NULL, - GSTRING_DICHOTOMY_STRIP_TRAILING | GSTRING_DICHOTOMY_RIGHT_DIR); + STRING_DICHOTOMY_STRIP_TRAILING | STRING_DICHOTOMY_RIGHT_DIR); if (dich_result!='o') { g_warning("I have to handle the case where the path is not OK\n"); return FALSE; } else { - parent = camel_store_get_folder(folder->parent_store, prefix); - camel_folder_create(parent); - gtk_object_unref (GTK_OBJECT(parent)); + parent = camel_store_get_folder (folder->parent_store, prefix); + camel_folder_create (parent); + gtk_object_unref (GTK_OBJECT (parent)); } } } @@ -631,7 +640,7 @@ _list_subfolders(CamelFolder *folder) * Return value: list of subfolders **/ GList * -camel_folder_list_subfolders(CamelFolder *folder) +camel_folder_list_subfolders (CamelFolder *folder) { return CF_CLASS(folder)->list_subfolders(folder); } @@ -640,7 +649,7 @@ camel_folder_list_subfolders(CamelFolder *folder) static GList * -_expunge(CamelFolder *folder) +_expunge (CamelFolder *folder) { return NULL; } @@ -656,8 +665,8 @@ _expunge(CamelFolder *folder) * Return value: list of expunged message objects. **/ GList * -camel_folder_expunge(CamelFolder *folder) +camel_folder_expunge (CamelFolder *folder) { - return CF_CLASS(folder)->expunge(folder); + return CF_CLASS (folder)->expunge (folder); } diff --git a/camel/camel-folder.h b/camel/camel-folder.h index 8d4a9f4aef..2e6eaf2f85 100644 --- a/camel/camel-folder.h +++ b/camel/camel-folder.h @@ -65,8 +65,8 @@ struct _CamelFolder gboolean exists_on_store; CamelFolderOpenMode open_mode; CamelFolderState open_state; - GString *name; - GString *full_name; + gchar *name; + gchar *full_name; CamelStore *parent_store; CamelFolder *parent_folder; @@ -81,15 +81,15 @@ typedef struct { void (*init_with_store) (CamelFolder *folder, CamelStore *parent_store); void (*open) (CamelFolder *object, CamelFolderOpenMode mode); void (*close) (CamelFolder *folder, gboolean expunge); - void (*set_name) (CamelFolder *folder, GString *name); - void (*set_full_name) (CamelFolder *folder, GString *name); - GString * (*get_name) (CamelFolder *folder); - GString * (*get_full_name) (CamelFolder *folder); + void (*set_name) (CamelFolder *folder, const gchar *name); + void (*set_full_name) (CamelFolder *folder, const gchar *name); + const gchar * (*get_name) (CamelFolder *folder); + const gchar * (*get_full_name) (CamelFolder *folder); gboolean (*can_hold_folders) (CamelFolder *folder); gboolean (*can_hold_messages) (CamelFolder *folder); gboolean (*exists) (CamelFolder *folder); gboolean (*is_open) (CamelFolder *folder); - CamelFolder * (*get_folder) (CamelFolder *folder, GString *folder_name); + CamelFolder * (*get_folder) (CamelFolder *folder, const gchar *folder_name); gboolean (*create) (CamelFolder *folder); gboolean (*delete) (CamelFolder *folder, gboolean recurse); gboolean (*delete_messages) (CamelFolder *folder); @@ -107,7 +107,7 @@ GtkType camel_folder_get_type (void); /* public methods */ -CamelFolder *camel_folder_get_folder(CamelFolder *folder, GString *folder_name); +CamelFolder *camel_folder_get_folder(CamelFolder *folder, gchar *folder_name); gboolean camel_folder_create(CamelFolder *folder); gboolean camel_folder_delete (CamelFolder *folder, gboolean recurse); gboolean camel_folder_delete_messages (CamelFolder *folder); diff --git a/camel/camel-log.c b/camel/camel-log.c index a0dd8007b7..1e6a3cdae6 100644 --- a/camel/camel-log.c +++ b/camel/camel-log.c @@ -23,16 +23,16 @@ #include <config.h> #include "camel-log.h" -int camel_debug_level = 10; +int camel_debug_level = CAMEL_LOG_LEVEL_FULL_DEBUG; FILE *camel_log_file_descriptor = NULL; void -camel_log(CamelLogLevel level, const gchar *format, ... ) +camel_log(guint level, const gchar *format, ... ) { va_list args; - if (camel_log_file_descriptor == NULL) - camel_log_file_descriptor = stderr; - + if (camel_log_file_descriptor == NULL) + camel_log_file_descriptor = stdout; + if (level<=camel_debug_level) { va_start(args, format); diff --git a/camel/camel-log.h b/camel/camel-log.h index 5ab9f8f405..82fb430719 100644 --- a/camel/camel-log.h +++ b/camel/camel-log.h @@ -31,25 +31,45 @@ extern int camel_debug_level; extern FILE *camel_log_file_descriptor; -typedef enum { - NO_LOG = 0, - STRANGE = 5, - WARNING = 6, - TRACE = 8, - FULL_DEBUG = 10 -} CamelLogLevel; +#define CAMEL_LOG_LEVEL_NO_LOG 0 +#define CAMEL_LOG_LEVEL_STRANGE 5 +#define CAMEL_LOG_LEVEL_WARNING 6 +#define CAMEL_LOG_LEVEL_TRACE 8 +#define CAMEL_LOG_LEVEL_FULL_DEBUG 10 -#define HARD_LOG_LEVEL TRACE +/* #define CAMEL_HARD_LOG_LEVEL CAMEL_LOG_LEVEL_TRACE */ /* the idea here is to be able to have a hard maximum log level, given at compilation time, and a soft one, given at -runtime (with camel_debug_level). For the moment, only -soft level is implmented, but one day, when performance -become important, I will set the hard one too */ +runtime (with camel_debug_level) */ +#if CAMEL_HARD_LOG_LEVEL>=CAMEL_LOG_LEVEL_STRANGE +#define CAMEL_LOG_STRANGE(args...) camel_log(CAMEL_LOG_LEVEL_STRANGE, ##args) +#else /* CAMEL_LOG_LEVEL_STRANGE */ +#define CAMEL_LOG_STRANGE(args...) +#endif /* CAMEL_LOG_LEVEL_STRANGE */ -#define CAMEL_LOG(level, args...) camel_log(level,##args) +#if CAMEL_HARD_LOG_LEVEL>=CAMEL_LOG_LEVEL_WARNING +#define CAMEL_LOG_WARNING(args...) camel_log(CAMEL_LOG_LEVEL_WARNING, ##args) +#else /* CAMEL_LOG_LEVEL_WARNING */ +#define CAMEL_LOG_WARNING(args...) +#endif /* CAMEL_LOG_LEVEL_WARNING */ -extern void camel_log(CamelLogLevel level, const gchar *format, ... ); +#if CAMEL_HARD_LOG_LEVEL>=CAMEL_LOG_LEVEL_TRACE +#define CAMEL_LOG_TRACE(args...) camel_log(CAMEL_LOG_LEVEL_TRACE, ##args) +#else /* CAMEL_LOG_LEVEL_TRACE */ +#define CAMEL_LOG_TRACE(args...) +#endif /* CAMEL_LOG_LEVEL_TRACE */ + +#if CAMEL_HARD_LOG_LEVEL>=CAMEL_LOG_LEVEL_FULL_DEBUG +#define CAMEL_LOG_FULL_DEBUG(args...) camel_log(CAMEL_LOG_LEVEL_FULL_DEBUG, ##args) +#else /* CAMEL_LOG_LEVEL_FULL_DEBUG */ +#define CAMEL_LOG_FULL_DEBUG(args...) +#endif /* CAMEL_LOG_LEVEL_FULL_DEBUG */ + + + + +extern void camel_log(guint level, const gchar *format, ... ); #endif /* CAMEL_LOG_H */ diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c index 61a4ca4c8d..5b608a6076 100644 --- a/camel/camel-mime-message.c +++ b/camel/camel-mime-message.c @@ -25,7 +25,7 @@ #include "camel-mime-message.h" #include <stdio.h> #include "gmime-content-field.h" -#include "gstring-util.h" +#include "string-utils.h" #include "camel-log.h" #include "gmime-utils.h" @@ -45,34 +45,34 @@ static GHashTable *header_name_table; static CamelMimePartClass *parent_class=NULL; -static GString *received_date_str; -static GString *sent_date_str; -static GString *reply_to_str; -static GString *subject_str; -static GString *from_str; - -static void _set_received_date (CamelMimeMessage *mime_message, GString *received_date); -static GString *_get_received_date (CamelMimeMessage *mime_message); -static GString *_get_sent_date (CamelMimeMessage *mime_message); -static void _set_reply_to (CamelMimeMessage *mime_message, GString *reply_to); -static GString *_get_reply_to (CamelMimeMessage *mime_message); -static void _set_subject (CamelMimeMessage *mime_message, GString *subject); -static GString *_get_subject (CamelMimeMessage *mime_message); -static void _set_from (CamelMimeMessage *mime_message, GString *from); -static GString *_get_from (CamelMimeMessage *mime_message); - -static void _add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient); -static void _remove_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient); -static GList *_get_recipients (CamelMimeMessage *mime_message, GString *recipient_type); - -static void _set_flag (CamelMimeMessage *mime_message, GString *flag, gboolean value); -static gboolean _get_flag (CamelMimeMessage *mime_message, GString *flag); +static gchar *received_date_str; +static gchar *sent_date_str; +static gchar *reply_to_str; +static gchar *subject_str; +static gchar *from_str; + +static void _set_received_date (CamelMimeMessage *mime_message, gchar *received_date); +static const gchar *_get_received_date (CamelMimeMessage *mime_message); +static const gchar *_get_sent_date (CamelMimeMessage *mime_message); +static void _set_reply_to (CamelMimeMessage *mime_message, gchar *reply_to); +static const gchar *_get_reply_to (CamelMimeMessage *mime_message); +static void _set_subject (CamelMimeMessage *mime_message, gchar *subject); +static const gchar *_get_subject (CamelMimeMessage *mime_message); +static void _set_from (CamelMimeMessage *mime_message, gchar *from); +static const gchar *_get_from (CamelMimeMessage *mime_message); + +static void _add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient); +static void _remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient); +static const GList *_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type); + +static void _set_flag (CamelMimeMessage *mime_message, gchar *flag, gboolean value); +static gboolean _get_flag (CamelMimeMessage *mime_message, gchar *flag); static void _set_message_number (CamelMimeMessage *mime_message, guint number); static guint _get_message_number (CamelMimeMessage *mime_message); static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); -static gboolean _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value); +static gboolean _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value); /* Returns the class for a CamelMimeMessage */ #define CMM_CLASS(so) CAMEL_MIME_MESSAGE_CLASS (GTK_OBJECT(so)->klass) @@ -82,13 +82,13 @@ static gboolean _parse_header_pair (CamelMimePart *mime_part, GString *header_na static void _init_header_name_table() { - header_name_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash); - g_hash_table_insert (header_name_table, g_string_new ("From"), (gpointer)HEADER_FROM); - g_hash_table_insert (header_name_table, g_string_new ("Reply-To"), (gpointer)HEADER_REPLY_TO); - g_hash_table_insert (header_name_table, g_string_new ("Subject"), (gpointer)HEADER_SUBJECT); - g_hash_table_insert (header_name_table, g_string_new ("To"), (gpointer)HEADER_TO); - g_hash_table_insert (header_name_table, g_string_new ("Cc"), (gpointer)HEADER_CC); - g_hash_table_insert (header_name_table, g_string_new ("Bcc"), (gpointer)HEADER_BCC); + header_name_table = g_hash_table_new (g_str_hash, g_str_equal); + g_hash_table_insert (header_name_table, "From", (gpointer)HEADER_FROM); + g_hash_table_insert (header_name_table, "Reply-To", (gpointer)HEADER_REPLY_TO); + g_hash_table_insert (header_name_table, "Subject", (gpointer)HEADER_SUBJECT); + g_hash_table_insert (header_name_table, "To", (gpointer)HEADER_TO); + g_hash_table_insert (header_name_table, "Cc", (gpointer)HEADER_CC); + g_hash_table_insert (header_name_table, "Bcc", (gpointer)HEADER_BCC); } @@ -101,11 +101,11 @@ camel_mime_message_class_init (CamelMimeMessageClass *camel_mime_message_class) parent_class = gtk_type_class (camel_mime_part_get_type ()); _init_header_name_table(); - received_date_str = g_string_new(""); - sent_date_str = g_string_new(""); - reply_to_str = g_string_new("Reply-To"); - subject_str = g_string_new("Subject"); - from_str = g_string_new("From"); + received_date_str = ""; + sent_date_str = ""; + reply_to_str = "Reply-To"; + subject_str = "Subject"; + from_str = "From"; /* virtual method definition */ camel_mime_message_class->set_received_date = _set_received_date; @@ -135,19 +135,14 @@ camel_mime_message_class_init (CamelMimeMessageClass *camel_mime_message_class) static void -camel_mime_message_init (gpointer object, gpointer klass) +camel_mime_message_init (gpointer object, gpointer klass) { CamelMimeMessage *camel_mime_message = CAMEL_MIME_MESSAGE (object); - camel_mime_message->recipients = g_hash_table_new(g_string_hash, g_string_equal_for_hash); - camel_mime_message->flags = g_hash_table_new(g_string_hash, g_string_equal_for_hash); - + camel_mime_message->recipients = g_hash_table_new(g_str_hash, g_str_equal); + camel_mime_message->flags = g_hash_table_new(g_str_hash, g_str_equal); } - - - - GtkType camel_mime_message_get_type (void) { @@ -173,7 +168,6 @@ camel_mime_message_get_type (void) } - CamelMimeMessage * camel_mime_message_new_with_session (CamelSession *session) { @@ -184,95 +178,86 @@ camel_mime_message_new_with_session (CamelSession *session) } - - /* two utils func */ static void -_set_field (CamelMimeMessage *mime_message, GString *name, GString *value, GString **variable) +_set_field (CamelMimeMessage *mime_message, gchar *name, gchar *value, gchar **variable) { if (variable) { - if (*variable) g_string_free (*variable, FALSE); + if (*variable) g_free (*variable); *variable = value; } } -static GString * -_get_field (CamelMimeMessage *mime_message, GString *name, GString *variable) +/* for future use */ +/* for the moment, only @variable is used */ +static gchar * +_get_field (CamelMimeMessage *mime_message, gchar *name, gchar *variable) { return variable; } - - - +/* * */ static void -_set_received_date (CamelMimeMessage *mime_message, GString *received_date) +_set_received_date (CamelMimeMessage *mime_message, gchar *received_date) { _set_field (mime_message, received_date_str, received_date, &(mime_message->received_date)); } void -camel_mime_message_set_received_date (CamelMimeMessage *mime_message, GString *received_date) +camel_mime_message_set_received_date (CamelMimeMessage *mime_message, gchar *received_date) { CMM_CLASS (mime_message)->set_received_date (mime_message, received_date); } -static GString * +static const gchar * _get_received_date (CamelMimeMessage *mime_message) { return _get_field (mime_message, received_date_str, mime_message->received_date); } -GString * +const gchar * camel_mime_message_get_received_date (CamelMimeMessage *mime_message) { return CMM_CLASS (mime_message)->get_received_date (mime_message); } - - - - -static GString * +static const gchar * _get_sent_date (CamelMimeMessage *mime_message) { return _get_field (mime_message, sent_date_str, mime_message->sent_date); } -GString * +const gchar * camel_mime_message_get_sent_date (CamelMimeMessage *mime_message) { return CMM_CLASS (mime_message)->get_sent_date (mime_message); } - - - static void -_set_reply_to (CamelMimeMessage *mime_message, GString *reply_to) +_set_reply_to (CamelMimeMessage *mime_message, gchar *reply_to) { _set_field (mime_message, reply_to_str, reply_to, &(mime_message->reply_to)); } void -camel_mime_message_set_reply_to (CamelMimeMessage *mime_message, GString *reply_to) +camel_mime_message_set_reply_to (CamelMimeMessage *mime_message, gchar *reply_to) { CMM_CLASS (mime_message)->set_reply_to (mime_message, reply_to); } -static GString * +static const gchar * _get_reply_to (CamelMimeMessage *mime_message) { return _get_field (mime_message, reply_to_str, mime_message->reply_to); } -GString * +const gchar * camel_mime_message_get_reply_to (CamelMimeMessage *mime_message) { return CMM_CLASS (mime_message)->get_reply_to (mime_message); @@ -282,25 +267,25 @@ camel_mime_message_get_reply_to (CamelMimeMessage *mime_message) static void -_set_subject (CamelMimeMessage *mime_message, GString *subject) +_set_subject (CamelMimeMessage *mime_message, gchar *subject) { _set_field (mime_message, subject_str, subject, &(mime_message->subject)); } void -camel_mime_message_set_subject (CamelMimeMessage *mime_message, GString *subject) +camel_mime_message_set_subject (CamelMimeMessage *mime_message, gchar *subject) { CMM_CLASS (mime_message)->set_subject (mime_message, subject); } -static GString * +static const gchar * _get_subject (CamelMimeMessage *mime_message) { return _get_field (mime_message, subject_str, mime_message->subject); } -GString * +const gchar * camel_mime_message_get_subject (CamelMimeMessage *mime_message) { return CMM_CLASS (mime_message)->get_subject (mime_message); @@ -310,25 +295,25 @@ camel_mime_message_get_subject (CamelMimeMessage *mime_message) static void -_set_from (CamelMimeMessage *mime_message, GString *from) +_set_from (CamelMimeMessage *mime_message, gchar *from) { _set_field (mime_message, from_str, from, &(mime_message->from)); } void -camel_mime_message_set_from (CamelMimeMessage *mime_message, GString *from) +camel_mime_message_set_from (CamelMimeMessage *mime_message, gchar *from) { CMM_CLASS (mime_message)->set_from (mime_message, from); } -static GString * +static const gchar * _get_from (CamelMimeMessage *mime_message) { return _get_field (mime_message, from_str, mime_message->from); } -GString * +const gchar * camel_mime_message_get_from (CamelMimeMessage *mime_message) { return CMM_CLASS (mime_message)->get_from (mime_message); @@ -340,7 +325,7 @@ camel_mime_message_get_from (CamelMimeMessage *mime_message) static void -_add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient) +_add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient) { /* be careful, recipient_type and recipient may be freed within this func */ GList *recipients_list; @@ -350,9 +335,9 @@ _add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString existent_list = (GList *)g_hash_table_lookup (mime_message->recipients, recipient_type); /* if the recipient is already in this list, do nothing */ - if ( existent_list && g_list_find_custom (existent_list, (gpointer)recipient, g_string_equal_for_glist) ) { - g_string_free (recipient_type, FALSE); - g_string_free (recipient, FALSE); + if ( existent_list && g_list_find_custom (existent_list, (gpointer)recipient, string_equal_for_glist) ) { + g_free (recipient_type); + g_free (recipient); return; } /* append the new recipient to the recipient list @@ -363,7 +348,7 @@ _add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString if (!existent_list) /* if there was no recipient of this type create the section */ g_hash_table_insert (mime_message->recipients, recipient_type, recipients_list); else - g_string_free (recipient_type, FALSE); + g_free (recipient_type); } @@ -377,7 +362,7 @@ _add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString * @recipient may be freed within this func **/ void -camel_mime_message_add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient) +camel_mime_message_add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient) { CMM_CLASS (mime_message)->add_recipient (mime_message, recipient_type, recipient); } @@ -394,12 +379,12 @@ camel_mime_message_add_recipient (CamelMimeMessage *mime_message, GString *recip * them just after remove_recipient returns. **/ static void -_remove_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient) +_remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient) { GList *recipients_list; GList *new_recipients_list; GList *old_element; - GString *old_recipient_type; + gchar *old_recipient_type; /* if the recipient type section does not exist, do nothing */ if (! g_hash_table_lookup_extended (mime_message->recipients, @@ -409,7 +394,8 @@ _remove_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GStr ) return; /* look for the recipient to remove */ - old_element = g_list_find_custom (recipients_list, recipient, g_string_equal_for_hash); + /* g_list_find_custom does use "const" for recipient, is it a mistake ? */ + old_element = g_list_find_custom (recipients_list, recipient, g_str_equal); if (old_element) { /* if recipient exists, remove it */ new_recipients_list = g_list_remove_link (recipients_list, old_element); @@ -418,40 +404,36 @@ _remove_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GStr if (new_recipients_list != recipients_list) g_hash_table_insert (mime_message->recipients, old_recipient_type, new_recipients_list); - g_string_free( (GString *)(old_element->data), FALSE); - g_list_free_1(old_element); + g_free( (gchar *)(old_element->data)); + g_list_free_1 (old_element); } } void -camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *recipient) +camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient) { CMM_CLASS (mime_message)->remove_recipient (mime_message, recipient_type, recipient); } - - -static GList * -_get_recipients (CamelMimeMessage *mime_message, GString *recipient_type) +static const GList * +_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type) { return (GList *)g_hash_table_lookup (mime_message->recipients, recipient_type); } -GList * -camel_mime_message_get_recipients (CamelMimeMessage *mime_message, GString *recipient_type) +const GList * +camel_mime_message_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type) { return CMM_CLASS (mime_message)->get_recipients (mime_message, recipient_type); } - - static void -_set_flag (CamelMimeMessage *mime_message, GString *flag, gboolean value) +_set_flag (CamelMimeMessage *mime_message, gchar *flag, gboolean value) { - GString old_flags; + gchar old_flags; gboolean *ptr_value; if (! g_hash_table_lookup_extended (mime_message->flags, flag, @@ -461,14 +443,14 @@ _set_flag (CamelMimeMessage *mime_message, GString *flag, gboolean value) ptr_value = g_new (gboolean, 1); g_hash_table_insert (mime_message->flags, flag, ptr_value); } else { - g_string_free (flag, FALSE); + g_free (flag); } *ptr_value = value; } void -camel_mime_message_set_flag (CamelMimeMessage *mime_message, GString *flag, gboolean value) +camel_mime_message_set_flag (CamelMimeMessage *mime_message, gchar *flag, gboolean value) { CMM_CLASS (mime_message)->set_flag (mime_message, flag, value); } @@ -476,7 +458,7 @@ camel_mime_message_set_flag (CamelMimeMessage *mime_message, GString *flag, gboo static gboolean -_get_flag (CamelMimeMessage *mime_message, GString *flag) +_get_flag (CamelMimeMessage *mime_message, gchar *flag) { gboolean *value; value = (gboolean *)g_hash_table_lookup (mime_message->flags, flag); @@ -484,7 +466,7 @@ _get_flag (CamelMimeMessage *mime_message, GString *flag) } gboolean -camel_mime_message_get_flag (CamelMimeMessage *mime_message, GString *flag) +camel_mime_message_get_flag (CamelMimeMessage *mime_message, gchar *flag) { return CMM_CLASS (mime_message)->get_flag (mime_message, flag); } @@ -523,12 +505,12 @@ camel_mime_message_get_message_number (CamelMimeMessage *mime_message) static void _write_one_recipient_to_stream (gpointer key, gpointer value, gpointer user_data) { - GString *recipient_type = (GString *)key; + gchar *recipient_type = (gchar *)key; GList *recipients = (GList *)value; - // GString *current; + // gchar *current; CamelStream *stream = (CamelStream *)user_data; - if ( (recipient_type) && (recipient_type->str) ) - write_header_with_glist_to_stream (stream, recipient_type->str, recipients, ", "); + if (recipient_type) + write_header_with_glist_to_stream (stream, recipient_type, recipients, ", "); } static void @@ -541,16 +523,16 @@ static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { CamelMimeMessage *mm = CAMEL_MIME_MESSAGE (data_wrapper); - CAMEL_LOG (FULL_DEBUG, "CamelMimeMessage::write_to_stream\n"); - CAMEL_LOG (FULL_DEBUG, "Writing \"From\"\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage::write_to_stream\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"From\"\n"); WHPT (stream, "From", mm->from); - CAMEL_LOG (FULL_DEBUG, "Writing \"Reply-To\"\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"Reply-To\"\n"); WHPT (stream, "Reply-To", mm->reply_to); - CAMEL_LOG (FULL_DEBUG, "Writing recipients\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing recipients\n"); _write_recipients_to_stream (mm, stream); - CAMEL_LOG (FULL_DEBUG, "Writing \"Date\"\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"Date\"\n"); WHPT (stream, "Date", mm->received_date); - CAMEL_LOG (FULL_DEBUG, "Writing \"Subject\"\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage:: Writing \"Subject\"\n"); WHPT (stream, "Subject", mm->subject); CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_stream (data_wrapper, stream); @@ -560,19 +542,19 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) /* mime message header parsing */ static void -_set_recipient_list_from_string (CamelMimeMessage *message, GString *recipient_type, GString *recipients_string) +_set_recipient_list_from_string (CamelMimeMessage *message, gchar *recipient_type, gchar *recipients_string) { GList *recipients_list; - CAMEL_LOG (FULL_DEBUG,"CamelMimeMessage::_set_recipient_list_from_string parsing ##%s##\n", recipients_string->str); - recipients_list = g_string_split ( + CAMEL_LOG_FULL_DEBUG ("CamelMimeMessage::_set_recipient_list_from_string parsing ##%s##\n", recipients_string); + recipients_list = string_split ( recipients_string, ',', "\t ", - GSTRING_TRIM_STRIP_TRAILING | GSTRING_TRIM_STRIP_LEADING); + STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING); g_hash_table_insert (message->recipients, recipient_type, recipients_list); } static gboolean -_parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value) +_parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value) { CamelHeaderType header_type; CamelMimeMessage *message = CAMEL_MIME_MESSAGE (mime_part); @@ -583,66 +565,66 @@ _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *hea switch (header_type) { case HEADER_FROM: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage::parse_header_pair found HEADER_FROM : %s\n", - header_value->str ); + header_value ); camel_mime_message_set_from (message, header_value); header_handled = TRUE; break; case HEADER_REPLY_TO: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage::parse_header_pair found HEADER_REPLY_YO : %s\n", - header_value->str ); + header_value ); camel_mime_message_set_reply_to (message, header_value); header_handled = TRUE; break; case HEADER_SUBJECT: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage::parse_header_pair found HEADER_SUBJECT : %s\n", - header_value->str ); + header_value ); camel_mime_message_set_subject (message, header_value); header_handled = TRUE; break; case HEADER_TO: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage::parse_header_pair found HEADER_TO : %s\n", - header_value->str ); + header_value ); - _set_recipient_list_from_string (message, g_string_new ("To"), header_value); - g_string_free (header_value, TRUE); + _set_recipient_list_from_string (message, "To", header_value); + g_free (header_value); header_handled = TRUE; break; case HEADER_CC: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage::parse_header_pair found HEADER_CC : %s\n", - header_value->str ); + header_value ); - _set_recipient_list_from_string (message, g_string_new ("Cc"), header_value); - g_string_free (header_value, TRUE); + _set_recipient_list_from_string (message, "Cc", header_value); + g_free (header_value); header_handled = TRUE; break; case HEADER_BCC: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimeMessage::parse_header_pair found HEADER_BCC : %s\n", - header_value->str ); + header_value ); - _set_recipient_list_from_string (message, g_string_new ("Bcc"), header_value); - g_string_free (header_value, TRUE); + _set_recipient_list_from_string (message, "Bcc", header_value); + g_free (header_value); header_handled = TRUE; break; } if (header_handled) { - g_string_free (header_name, TRUE); + g_free (header_name); return TRUE; } else return parent_class->parse_header_pair (mime_part, header_name, header_value); diff --git a/camel/camel-mime-message.h b/camel/camel-mime-message.h index 321f3fdade..617286b0c1 100644 --- a/camel/camel-mime-message.h +++ b/camel/camel-mime-message.h @@ -54,13 +54,13 @@ typedef struct CamelMimePart parent_object; /* header fields */ - GString *received_date; - GString *sent_date; + gchar *received_date; + gchar *sent_date; - GString *subject; - GString *reply_to; + gchar *subject; + gchar *reply_to; - GString *from; + gchar *from; GHashTable *recipients; /* -> each value is a GList of address strings */ /* each key is a recipient type string in lower-case */ @@ -81,35 +81,23 @@ typedef struct { CamelMimePartClass parent_class; /* Virtual methods */ - void (*set_received_date) (CamelMimeMessage *mime_message, - GString *received_date); - GString * (*get_received_date) (CamelMimeMessage *mime_message); - GString * (*get_sent_date) (CamelMimeMessage *mime_message); - void (*set_reply_to) (CamelMimeMessage *mime_message, - GString *reply_to); - GString * (*get_reply_to) (CamelMimeMessage *mime_message); - void (*set_subject) (CamelMimeMessage *mime_message, - GString *subject); - GString * (*get_subject) (CamelMimeMessage *mime_message); - void (*set_from) (CamelMimeMessage *mime_message, - GString *from); - GString * (*get_from) (CamelMimeMessage *mime_message); - void (*add_recipient) (CamelMimeMessage *mime_message, - GString *recipient_type, - GString *recipient); - void (*remove_recipient) (CamelMimeMessage *mime_message, - GString *recipient_type, - GString *recipient); - GList * (*get_recipients) (CamelMimeMessage *mime_message, - GString *recipient_type); - void (*set_flag) (CamelMimeMessage *mime_message, - GString *flag, gboolean value); - gboolean (*get_flag) (CamelMimeMessage *mime_message, - GString *flag); - - void (*set_message_number)(CamelMimeMessage *mime_message, - guint number); - guint (*get_message_number)(CamelMimeMessage *mime_message); + void (*set_received_date) (CamelMimeMessage *mime_message, gchar *received_date); + const gchar * (*get_received_date) (CamelMimeMessage *mime_message); + const gchar * (*get_sent_date) (CamelMimeMessage *mime_message); + void (*set_reply_to) (CamelMimeMessage *mime_message, gchar *reply_to); + const gchar * (*get_reply_to) (CamelMimeMessage *mime_message); + void (*set_subject) (CamelMimeMessage *mime_message, gchar *subject); + const gchar * (*get_subject) (CamelMimeMessage *mime_message); + void (*set_from) (CamelMimeMessage *mime_message, gchar *from); + const gchar * (*get_from) (CamelMimeMessage *mime_message); + void (*add_recipient) (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient); + void (*remove_recipient) (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient); + const GList * (*get_recipients) (CamelMimeMessage *mime_message, const gchar *recipient_type); + void (*set_flag) (CamelMimeMessage *mime_message, gchar *flag, gboolean value); + gboolean (*get_flag) (CamelMimeMessage *mime_message, gchar *flag); + + void (*set_message_number)(CamelMimeMessage *mime_message, guint number); + guint (*get_message_number)(CamelMimeMessage *mime_message); } CamelMimeMessageClass; @@ -122,34 +110,24 @@ GtkType camel_mime_message_get_type (void); CamelMimeMessage *camel_mime_message_new_with_session (CamelSession *session); -void camel_mime_message_set_received_date (CamelMimeMessage *mime_message, - GString *received_date); -GString *camel_mime_message_get_received_date (CamelMimeMessage *mime_message); -GString *camel_mime_message_get_sent_date (CamelMimeMessage *mime_message); -void camel_mime_message_set_reply_to (CamelMimeMessage *mime_message, - GString *reply_to); -GString *camel_mime_message_get_reply_to (CamelMimeMessage *mime_message); -void camel_mime_message_set_subject (CamelMimeMessage *mime_message, - GString *subject); -GString *camel_mime_message_get_subject (CamelMimeMessage *mime_message); -void camel_mime_message_set_from (CamelMimeMessage *mime_message, GString *from); -GString *camel_mime_message_get_from (CamelMimeMessage *mime_message); - -void camel_mime_message_add_recipient (CamelMimeMessage *mime_message, - GString *recipient_type, - GString *recipient); -void camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, - GString *recipient_type, - GString *recipient); -GList *camel_mime_message_get_recipients (CamelMimeMessage *mime_message, - GString *recipient_type); - -void camel_mime_message_set_flag (CamelMimeMessage *mime_message, - GString *flag, gboolean value); -gboolean camel_mime_message_get_flag (CamelMimeMessage *mime_message, - GString *flag); - -guint camel_mime_message_get_message_number (CamelMimeMessage *mime_message); +void camel_mime_message_set_received_date (CamelMimeMessage *mime_message, gchar *received_date); +const gchar *camel_mime_message_get_received_date (CamelMimeMessage *mime_message); +const gchar *camel_mime_message_get_sent_date (CamelMimeMessage *mime_message); +void camel_mime_message_set_reply_to (CamelMimeMessage *mime_message, gchar *reply_to); +const gchar *camel_mime_message_get_reply_to (CamelMimeMessage *mime_message); +void camel_mime_message_set_subject (CamelMimeMessage *mime_message, gchar *subject); +const gchar *camel_mime_message_get_subject (CamelMimeMessage *mime_message); +void camel_mime_message_set_from (CamelMimeMessage *mime_message, gchar *from); +const gchar *camel_mime_message_get_from (CamelMimeMessage *mime_message); + +void camel_mime_message_add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient); +void camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient); +const GList *camel_mime_message_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type); + +void camel_mime_message_set_flag (CamelMimeMessage *mime_message, gchar *flag, gboolean value); +gboolean camel_mime_message_get_flag (CamelMimeMessage *mime_message, gchar *flag); + +guint camel_mime_message_get_message_number (CamelMimeMessage *mime_message); #ifdef __cplusplus } diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index aa40144acf..913ab31e63 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -25,9 +25,10 @@ #include "camel-mime-part.h" #include <stdio.h> #include "gmime-content-field.h" -#include "gstring-util.h" +#include "string-utils.h" #include "camel-log.h" #include "gmime-utils.h" +#include "camel-simple-data-wrapper.h" typedef enum { @@ -50,32 +51,33 @@ static CamelDataWrapperClass *parent_class=NULL; /* Returns the class for a CamelMimePart */ #define CMP_CLASS(so) CAMEL_MIME_PART_CLASS (GTK_OBJECT(so)->klass) -static void _add_header (CamelMimePart *mime_part, GString *header_name, GString *header_value); -static void _remove_header (CamelMimePart *mime_part, GString *header_name); -static GString *_get_header (CamelMimePart *mime_part, GString *header_name); -static void _set_description (CamelMimePart *mime_part, GString *description); -static GString *_get_description (CamelMimePart *mime_part); -static void _set_disposition (CamelMimePart *mime_part, GString *disposition); -static GString *_get_disposition (CamelMimePart *mime_part); -static void _set_filename (CamelMimePart *mime_part, GString *filename); -static GString *_get_filename (CamelMimePart *mime_part); -static void _set_content_id (CamelMimePart *mime_part, GString *content_id); -static GString *_get_content_id (CamelMimePart *mime_part); -static void _set_content_MD5 (CamelMimePart *mime_part, GString *content_MD5); -static GString *_get_content_MD5 (CamelMimePart *mime_part); -static void _set_encoding (CamelMimePart *mime_part, GString *encoding); -static GString *_get_encoding (CamelMimePart *mime_part); +static void _add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value); +static void _remove_header (CamelMimePart *mime_part, const gchar *header_name); +static const gchar *_get_header (CamelMimePart *mime_part, const gchar *header_name); +static void _set_description (CamelMimePart *mime_part, gchar *description); +static const gchar *_get_description (CamelMimePart *mime_part); +static void _set_disposition (CamelMimePart *mime_part, gchar *disposition); +static const gchar *_get_disposition (CamelMimePart *mime_part); +static void _set_filename (CamelMimePart *mime_part, gchar *filename); +static const gchar *_get_filename (CamelMimePart *mime_part); +static void _set_content_id (CamelMimePart *mime_part, gchar *content_id); +static const gchar *_get_content_id (CamelMimePart *mime_part); +static void _set_content_MD5 (CamelMimePart *mime_part, gchar *content_MD5); +static const gchar *_get_content_MD5 (CamelMimePart *mime_part); +static void _set_encoding (CamelMimePart *mime_part, gchar *encoding); +static const gchar *_get_encoding (CamelMimePart *mime_part); static void _set_content_languages (CamelMimePart *mime_part, GList *content_languages); -static GList *_get_content_languages (CamelMimePart *mime_part); +static const 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 const GList *_get_header_lines (CamelMimePart *mime_part); +static void _set_content_type (CamelMimePart *mime_part, const gchar *content_type); +static GMimeContentField *_get_content_type (CamelMimePart *mime_part); -static CamelDataWrapper *_get_content_object(CamelMimePart *mime_part); -static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); +static const CamelDataWrapper *_get_content_object(CamelMimePart *mime_part); +static void _set_content_object(CamelMimePart *mime_part, CamelDataWrapper *content); -static gboolean _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value); +static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); +static gboolean _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value); void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); @@ -85,14 +87,14 @@ void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream static void _init_header_name_table() { - header_name_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash); - g_hash_table_insert (header_name_table, g_string_new ("Content-Description"), (gpointer)HEADER_DESCRIPTION); - g_hash_table_insert (header_name_table, g_string_new ("Content-Disposition"), (gpointer)HEADER_DISPOSITION); - 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); - + header_name_table = g_hash_table_new (g_str_hash, g_str_equal); + g_hash_table_insert (header_name_table, "Content-Description", (gpointer)HEADER_DESCRIPTION); + g_hash_table_insert (header_name_table, "Content-Disposition", (gpointer)HEADER_DISPOSITION); + g_hash_table_insert (header_name_table, "Content-id", (gpointer)HEADER_CONTENT_ID); + g_hash_table_insert (header_name_table, "Content-Transfer-Encoding", (gpointer)HEADER_ENCODING); + g_hash_table_insert (header_name_table, "Content-MD5", (gpointer)HEADER_CONTENT_MD5); + g_hash_table_insert (header_name_table, "Content-Type", (gpointer)HEADER_CONTENT_TYPE); + } static void @@ -124,10 +126,11 @@ camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class) camel_mime_part_class->get_header_lines =_get_header_lines; camel_mime_part_class->set_content_type = _set_content_type; camel_mime_part_class->get_content_type = _get_content_type; - + 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_object = _set_content_object; + /* virtual method overload */ @@ -139,8 +142,8 @@ static void 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->headers = g_hash_table_new (g_str_hash, g_str_equal); camel_mime_part->content_type = gmime_content_field_new (NULL, NULL); } @@ -175,12 +178,12 @@ camel_mime_part_get_type (void) static void -_add_header (CamelMimePart *mime_part, GString *header_name, GString *header_value) +_add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value) { gboolean header_exists; - GString *old_header_name; - GString *old_header_value; - + gchar *old_header_name; + gchar *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 */ @@ -190,8 +193,8 @@ _add_header (CamelMimePart *mime_part, GString *header_name, GString *header_val (gpointer *) &old_header_name, (gpointer *) &old_header_value); if (header_exists) { - g_string_free (old_header_name, TRUE); - g_string_free (old_header_value, TRUE); + g_free (old_header_name); + g_free (old_header_value); } g_hash_table_insert (mime_part->headers, header_name, header_value); @@ -199,7 +202,7 @@ _add_header (CamelMimePart *mime_part, GString *header_name, GString *header_val void -camel_mime_part_add_header (CamelMimePart *mime_part, GString *header_name, GString *header_value) +camel_mime_part_add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value) { CMP_CLASS(mime_part)->add_header(mime_part, header_name, header_value); } @@ -207,19 +210,19 @@ camel_mime_part_add_header (CamelMimePart *mime_part, GString *header_name, GStr static void -_remove_header (CamelMimePart *mime_part, GString *header_name) +_remove_header (CamelMimePart *mime_part, const gchar *header_name) { gboolean header_exists; - GString *old_header_name; - GString *old_header_value; - + gchar *old_header_name; + gchar *old_header_value; + header_exists = g_hash_table_lookup_extended (mime_part->headers, header_name, (gpointer *) &old_header_name, (gpointer *) &old_header_value); if (header_exists) { - g_string_free (old_header_name, TRUE); - g_string_free (old_header_value, TRUE); + g_free (old_header_name); + g_free (old_header_value); } g_hash_table_remove (mime_part->headers, header_name); @@ -227,27 +230,27 @@ _remove_header (CamelMimePart *mime_part, GString *header_name) } void -camel_mime_part_remove_header (CamelMimePart *mime_part, GString *header_name) +camel_mime_part_remove_header (CamelMimePart *mime_part, const gchar *header_name) { CMP_CLASS(mime_part)->remove_header(mime_part, header_name); } -static GString * -_get_header (CamelMimePart *mime_part, GString *header_name) +static const gchar * +_get_header (CamelMimePart *mime_part, const gchar *header_name) { - GString *old_header_name; - GString *old_header_value; - GString *header_value; - - header_value = (GString *)g_hash_table_lookup (mime_part->headers, header_name); + gchar *old_header_name; + gchar *old_header_value; + gchar *header_value; + + header_value = (gchar *)g_hash_table_lookup (mime_part->headers, header_name); return header_value; } -GString * -camel_mime_part_get_header (CamelMimePart *mime_part, GString *header_name) +const gchar * +camel_mime_part_get_header (CamelMimePart *mime_part, const gchar *header_name) { return CMP_CLASS(mime_part)->get_header (mime_part, header_name); } @@ -255,14 +258,14 @@ camel_mime_part_get_header (CamelMimePart *mime_part, GString *header_name) static void -_set_description (CamelMimePart *mime_part, GString *description) +_set_description (CamelMimePart *mime_part, gchar *description) { - if (mime_part->description) g_free(mime_part->description); + if (mime_part->description) g_free (mime_part->description); mime_part->description = description; } void -camel_mime_part_set_description (CamelMimePart *mime_part, GString *description) +camel_mime_part_set_description (CamelMimePart *mime_part, gchar *description) { CMP_CLASS(mime_part)->set_description (mime_part, description); } @@ -270,13 +273,13 @@ camel_mime_part_set_description (CamelMimePart *mime_part, GString *description) -static GString * +static const gchar * _get_description (CamelMimePart *mime_part) { return mime_part->description; } -GString * +const gchar * camel_mime_part_get_description (CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_description (mime_part); @@ -285,8 +288,9 @@ camel_mime_part_get_description (CamelMimePart *mime_part) static void -_set_disposition (CamelMimePart *mime_part, GString *disposition) +_set_disposition (CamelMimePart *mime_part, gchar *disposition) { +#warning Do not use MimeContentfield here !!! //if (mime_part->disposition) g_free(mime_part->disposition); if (!mime_part->disposition) mime_part->disposition = g_new (GMimeContentField,1); @@ -296,14 +300,14 @@ _set_disposition (CamelMimePart *mime_part, GString *disposition) void -camel_mime_part_set_disposition (CamelMimePart *mime_part, GString *disposition) +camel_mime_part_set_disposition (CamelMimePart *mime_part, gchar *disposition) { CMP_CLASS(mime_part)->set_disposition (mime_part, disposition); } -static GString * +static const gchar * _get_disposition (CamelMimePart *mime_part) { if (!mime_part->disposition) return NULL; @@ -311,7 +315,7 @@ _get_disposition (CamelMimePart *mime_part) } -GString * +const gchar * camel_mime_part_get_disposition (CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_disposition (mime_part); @@ -320,7 +324,7 @@ camel_mime_part_get_disposition (CamelMimePart *mime_part) static void -_set_filename (CamelMimePart *mime_part, GString *filename) +_set_filename (CamelMimePart *mime_part, gchar *filename) { if (mime_part->filename) g_free(mime_part->filename); mime_part->filename = filename; @@ -328,21 +332,21 @@ _set_filename (CamelMimePart *mime_part, GString *filename) void -camel_mime_part_set_filename (CamelMimePart *mime_part, GString *filename) +camel_mime_part_set_filename (CamelMimePart *mime_part, gchar *filename) { CMP_CLASS(mime_part)->set_filename (mime_part, filename); } -static GString * +static const gchar * _get_filename (CamelMimePart *mime_part) { return mime_part->filename; } -GString * +const gchar * camel_mime_part_get_filename (CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_filename (mime_part); @@ -351,21 +355,21 @@ camel_mime_part_get_filename (CamelMimePart *mime_part) /* this routine must not be public */ static void -_set_content_id (CamelMimePart *mime_part, GString *content_id) +_set_content_id (CamelMimePart *mime_part, gchar *content_id) { if (mime_part->content_id) g_free(mime_part->content_id); mime_part->content_id = content_id; } -static GString * +static const gchar * _get_content_id (CamelMimePart *mime_part) { return mime_part->content_id; } -GString * +const gchar * camel_mime_part_get_content_id (CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_content_id (mime_part); @@ -374,20 +378,20 @@ camel_mime_part_get_content_id (CamelMimePart *mime_part) /* this routine must not be public */ static void -_set_content_MD5 (CamelMimePart *mime_part, GString *content_MD5) +_set_content_MD5 (CamelMimePart *mime_part, gchar *content_MD5) { if (mime_part->content_MD5) g_free(mime_part->content_MD5); mime_part->content_MD5 = content_MD5; } -static GString * +static const gchar * _get_content_MD5 (CamelMimePart *mime_part) { return mime_part->content_MD5; } -GString * +const gchar * camel_mime_part_get_content_MD5 (CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_content_MD5 (mime_part); @@ -396,27 +400,27 @@ camel_mime_part_get_content_MD5 (CamelMimePart *mime_part) static void -_set_encoding (CamelMimePart *mime_part, GString *encoding) +_set_encoding (CamelMimePart *mime_part, gchar *encoding) { if (mime_part->encoding) g_free(mime_part->encoding); mime_part->encoding = encoding; } void -camel_mime_part_set_encoding (CamelMimePart *mime_part, GString *encoding) +camel_mime_part_set_encoding (CamelMimePart *mime_part, gchar *encoding) { CMP_CLASS(mime_part)->set_encoding (mime_part, encoding); } -static GString * +static const gchar * _get_encoding (CamelMimePart *mime_part) { return mime_part->encoding; } -GString * +const gchar * camel_mime_part_get_encoding (CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_encoding (mime_part); @@ -428,7 +432,7 @@ camel_mime_part_get_encoding (CamelMimePart *mime_part) static void _set_content_languages (CamelMimePart *mime_part, GList *content_languages) { - if (mime_part->content_languages) g_string_list_free(mime_part->content_languages); + if (mime_part->content_languages) string_list_free (mime_part->content_languages); mime_part->content_languages = content_languages; } @@ -440,14 +444,14 @@ camel_mime_part_set_content_languages (CamelMimePart *mime_part, GList *content_ -static GList * +static const GList * _get_content_languages (CamelMimePart *mime_part) { return mime_part->content_languages; } -GList * +const GList * camel_mime_part_get_content_languages (CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_content_languages (mime_part); @@ -458,7 +462,7 @@ camel_mime_part_get_content_languages (CamelMimePart *mime_part) static void _set_header_lines (CamelMimePart *mime_part, GList *header_lines) { - if (mime_part->header_lines) g_string_list_free(mime_part->header_lines); + if (mime_part->header_lines) string_list_free (mime_part->header_lines); mime_part->header_lines = header_lines; } @@ -470,7 +474,7 @@ camel_mime_part_set_header_lines (CamelMimePart *mime_part, GList *header_lines) -static GList * +static const GList * _get_header_lines (CamelMimePart *mime_part) { return mime_part->header_lines; @@ -478,7 +482,7 @@ _get_header_lines (CamelMimePart *mime_part) -GList * +const GList * camel_mime_part_get_header_lines (CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_header_lines (mime_part); @@ -488,48 +492,69 @@ camel_mime_part_get_header_lines (CamelMimePart *mime_part) /*********/ static void -_set_content_type (CamelMimePart *mime_part, GString *content_type) +_set_content_type (CamelMimePart *mime_part, const gchar *content_type) { g_assert (content_type); gmime_content_field_construct_from_string (mime_part->content_type, content_type); } void -camel_mime_part_set_mime_type (CamelMimePart *mime_part, GString *content_type) +camel_mime_part_set_content_type (CamelMimePart *mime_part, gchar *content_type) { CMP_CLASS(mime_part)->set_content_type (mime_part, content_type); } -static GString * +static GMimeContentField * _get_content_type (CamelMimePart *mime_part) { - GString *mime_type; - - mime_type = gmime_content_field_get_mime_type (mime_part->content_type); - return mime_type; + return mime_part->content_type; } -static GString * +GMimeContentField * camel_mime_part_get_content_type (CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_content_type (mime_part); } + /*********/ -static CamelDataWrapper * +static const CamelDataWrapper * _get_content_object(CamelMimePart *mime_part) { return mime_part->content; - + } -CamelDataWrapper * +const CamelDataWrapper * camel_mime_part_get_content_object(CamelMimePart *mime_part) { return CMP_CLASS(mime_part)->get_content_object (mime_part); } +static void +_set_content_object(CamelMimePart *mime_part, CamelDataWrapper *content) +{ + CAMEL_LOG_FULL_DEBUG ("Entering CamelMimePart::set_content_object\n"); + if (mime_part->content) { + CAMEL_LOG_FULL_DEBUG ("CamelMimePart::set_content_object unreferencing old content object\n"); + gtk_object_unref (GTK_OBJECT (mime_part->content)); + } + gtk_object_ref (GTK_OBJECT (content)); + mime_part->content = content; + if (mime_part->content_type) gmime_content_field_free (mime_part->content_type); + mime_part->content_type = camel_data_wrapper_get_mime_type_field (content); + CAMEL_LOG_FULL_DEBUG ("Leaving CamelMimePart::set_content_object\n"); + +} + +void +camel_mime_part_set_content_object(CamelMimePart *mime_part, CamelDataWrapper *content) +{ + CMP_CLASS(mime_part)->set_content_object (mime_part, content); +} + + /**********************************************************************/ @@ -539,7 +564,6 @@ camel_mime_part_get_content_object(CamelMimePart *mime_part) #define WHPT gmime_write_header_pair_to_stream -/* This is not used for the moment */ static void _write_content_to_stream (CamelMimePart *mime_part, CamelStream *stream) { @@ -548,20 +572,24 @@ _write_content_to_stream (CamelMimePart *mime_part, CamelStream *stream) gchar *encoded_buffer; CamelDataWrapper *content = mime_part->content; + CAMEL_LOG_FULL_DEBUG ( "Entering CamelMimePart::_write_content_to_stream\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::_write_content_to_stream, content=%p\n", content); + if (!content) return; // buffer_size = camel_data_wrapper_size (content); - buffer = g_malloc (buffer_size); + //buffer = g_malloc (buffer_size); camel_data_wrapper_write_to_stream (content, stream); - if (mime_part->encoding) { + //if (mime_part->encoding) { // encoded_buffer_size = gmime_encoded_size(buffer, buffer_size, encoding); // encoded_buffer = g_malloc (encoded_buffer_size); // gmime_encode_buffer (buffer, encoded_buffer, encoding); // camel_stream_write (stream, encoded_buffer, encoded_buffer_size); // g_free (encoded_buffer); - } else + //} else //fwrite (buffer, buffer_size, 1, file); - camel_stream_write (stream, buffer, buffer_size); - g_free (buffer); + //camel_stream_write (stream, buffer, buffer_size); + //g_free (buffer); + CAMEL_LOG_FULL_DEBUG ( "Leaving CamelMimePart::_write_content_to_stream\n"); } @@ -573,29 +601,29 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { CamelMimePart *mp = CAMEL_MIME_PART (data_wrapper); - CAMEL_LOG (FULL_DEBUG, "Entering CamelMimePart::write_to_stream\n"); - - CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-disposition\n"); + CAMEL_LOG_FULL_DEBUG ( "Entering CamelMimePart::write_to_stream\n"); + + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-disposition\n"); gmime_content_field_write_to_stream(mp->disposition, stream); - CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-transfer-encoding\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-transfer-encoding\n"); WHPT (stream, "Content-Transfer-Encoding", mp->encoding); - CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-description\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-description\n"); WHPT (stream, "Content-Description", mp->description); - CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-MD5\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-MD5\n"); WHPT (stream, "Content-MD5", mp->content_MD5); - CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-id\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-id\n"); WHPT (stream, "Content-id", mp->content_id); - CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-languages\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-languages\n"); write_header_with_glist_to_stream (stream, "Content-Language", mp->content_languages,", "); - - CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing other headers\n"); + + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing other headers\n"); write_header_table_to_stream (stream, mp->headers); - - CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-type\n"); + + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-type\n"); gmime_content_field_write_to_stream(mp->content_type, stream); - + camel_stream_write_string(stream,"\n"); - if (mp->content) camel_data_wrapper_write_to_stream (mp->content, stream); + _write_content_to_stream (mp, stream); } @@ -605,64 +633,64 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) /* mime part parsing */ static gboolean -_parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value) +_parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_value) { CamelHeaderType header_type; gboolean header_handled = FALSE; - - + + header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, header_name); switch (header_type) { - + case HEADER_DESCRIPTION: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::parse_header_pair found HEADER_DESCRIPTION: %s\n", - header_value->str ); + header_value ); camel_mime_part_set_description (mime_part, header_value); header_handled = TRUE; break; - + case HEADER_DISPOSITION: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::parse_header_pair found HEADER_DISPOSITION: %s\n", - header_value->str ); + header_value); camel_mime_part_set_disposition (mime_part, header_value); header_handled = TRUE; break; - + case HEADER_CONTENT_ID: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::parse_header_pair found HEADER_CONTENT_ID: %s\n", - header_value->str ); + header_value); CMP_CLASS(mime_part)->set_content_id (mime_part, header_value); header_handled = TRUE; break; case HEADER_ENCODING: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::parse_header_pair found HEADER_ENCODING: %s\n", - header_value->str ); + header_value); camel_mime_part_set_encoding (mime_part, header_value); header_handled = TRUE; break; case HEADER_CONTENT_MD5: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::parse_header_pair found HEADER_CONTENT_MD5: %s\n", - header_value->str ); - + header_value ); + CMP_CLASS(mime_part)->set_content_MD5 (mime_part, header_value); header_handled = TRUE; break; case HEADER_CONTENT_TYPE: - CAMEL_LOG (FULL_DEBUG, + CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::parse_header_pair found HEADER_CONTENT_TYPE: %s\n", - header_value->str ); + header_value ); gmime_content_field_construct_from_string (mime_part->content_type, header_value); header_handled = TRUE; @@ -670,13 +698,13 @@ _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *hea } - - + + if (header_handled) { - g_string_free (header_name, TRUE); + g_free (header_name); return TRUE; } else return FALSE; - + } /* calls _parse_header_pair, but can be called @@ -684,19 +712,19 @@ _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *hea void _parse_hash_table_pair (gpointer key, gpointer value, gpointer user_data) { - GString *header_name = (GString *)key; - GString *header_value = (GString *)value; + gchar *header_name = (gchar *)key; + gchar *header_value = (gchar *)value; CamelMimePart *mime_part = (CamelMimePart *) user_data; - - - CAMEL_LOG (FULL_DEBUG,"\n--------- New Header ----------\n"); - if ((header_name) && (header_name->str)) - CAMEL_LOG (FULL_DEBUG, "header name :%s\n", header_name->str); - if ((header_value) && (header_value->str)) - CAMEL_LOG (FULL_DEBUG, "header value :%s\n", header_value->str); - + + + CAMEL_LOG_FULL_DEBUG ("\n--------- New Header ----------\n"); + if (header_name) + CAMEL_LOG_FULL_DEBUG ( "header name :%s\n", header_name); + if (header_value) + CAMEL_LOG_FULL_DEBUG ( "header value :%s\n", header_value); + camel_mime_part_add_header (mime_part, header_name, header_value); - CAMEL_LOG (FULL_DEBUG, "--------- End -----------------\n"); + CAMEL_LOG_FULL_DEBUG ( "--------- End -----------------\n"); } void @@ -704,11 +732,75 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { GHashTable *header_table; CamelMimePart *mime_part = CAMEL_MIME_PART (data_wrapper); - + GMimeContentField *content_type; + gchar *mime_type; + GtkType content_object_type; + CamelDataWrapper *content_object; + + CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Entering _construct_from_stream\n"); + g_assert (stream); + CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream parsing headers\n"); + /* parse all header lines */ header_table = get_header_table_from_stream (stream); if (header_table) { g_hash_table_foreach (header_table, _parse_hash_table_pair, (gpointer)mime_part); } g_hash_table_destroy (header_table); + CAMEL_LOG_FULL_DEBUG ("CamelMimePart::construct_from_stream headers parsed \n"); + + /* now parse the content */ + /* find its mime type */ + 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); + 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"); + + + CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving _construct_from_stream\n"); +} + + +/******************************/ +/** Misc utility functions **/ + + +/** + * camel_mime_part_set_text: set the content to be some text + * @camel_mime_part: Mime part + * @text: the text + * + * Utility function used to set the content of a mime part object to + * be a text string. When @text is NULL, this routine can be used as + * a way to remove old text content. + * + **/ +void +camel_mime_part_set_text (CamelMimePart *camel_mime_part, gchar *text) +{ + CamelSimpleDataWrapper *simple_data_wrapper; + CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Entering set_text\n"); + CAMEL_LOG_TRACE ("CamelMimePart::set_text, setting text as a mime part content\n"); + if (camel_mime_part->content) { + CAMEL_LOG_FULL_DEBUG ("CamelMimePart::set_text unreferencing old content object\n"); + gtk_object_unref (GTK_OBJECT (camel_mime_part->content)); + } + if (text) { + simple_data_wrapper = camel_simple_data_wrapper_new (); + 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_simple_data_wrapper_set_text ( simple_data_wrapper, text); + } else camel_mime_part->content = NULL; + + CAMEL_LOG_FULL_DEBUG ("CamelMimePart:: Leaving camel_mime_part_set_text\n"); } diff --git a/camel/camel-mime-part.h b/camel/camel-mime-part.h index 9f364c427c..5b07491dcf 100644 --- a/camel/camel-mime-part.h +++ b/camel/camel-mime-part.h @@ -1,5 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camelMimePart.h : class for a mime part */ +/* camel-mime-part.h : class for a mime part */ /* * @@ -36,7 +36,6 @@ extern "C" { #include "camel-stream.h" - #define CAMEL_MIME_PART_TYPE (camel_mime_part_get_type ()) #define CAMEL_MIME_PART(obj) (GTK_CHECK_CAST((obj), CAMEL_MIME_PART_TYPE, CamelMimePart)) #define CAMEL_MIME_PART_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MIME_PART_TYPE, CamelMimePartClass)) @@ -50,18 +49,18 @@ typedef struct CamelDataWrapper parent_object; GHashTable *headers; - GString *description; + gchar *description; GMimeContentField *disposition; - GString *content_id; - GString *content_MD5; + gchar *content_id; + gchar *content_MD5; GList *content_languages; - GString *encoding; - GString *filename; + gchar *encoding; + gchar *filename; GList *header_lines; GMimeContentField *content_type; CamelDataWrapper *content; /* part real content */ - + } CamelMimePart; @@ -70,31 +69,33 @@ typedef struct { CamelDataWrapperClass parent_class; /* Virtual methods */ - void (*add_header) (CamelMimePart *mime_part, GString *header_name, GString *header_value); - void (*remove_header) (CamelMimePart *mime_part, GString *header_name); - GString * (*get_header) (CamelMimePart *mime_part, GString *header_name); - void (*set_description) (CamelMimePart *mime_part, GString *description); - GString * (*get_description) (CamelMimePart *mime_part); - void (*set_disposition) (CamelMimePart *mime_part, GString *disposition); - GString * (*get_disposition) (CamelMimePart *mime_part); - void (*set_filename) (CamelMimePart *mime_part, GString *filename); - GString * (*get_filename) (CamelMimePart *mime_part); - void (*set_content_id) (CamelMimePart *mime_part, GString *content_id); - GString * (*get_content_id) (CamelMimePart *mime_part); - void (*set_content_MD5) (CamelMimePart *mime_part, GString *content_MD5); - GString * (*get_content_MD5) (CamelMimePart *mime_part); - void (*set_encoding) (CamelMimePart *mime_part, GString *encoding); - GString * (*get_encoding) (CamelMimePart *mime_part); + void (*add_header) (CamelMimePart *mime_part, gchar *header_name, gchar *header_value); + void (*remove_header) (CamelMimePart *mime_part, const gchar *header_name); + const gchar * (*get_header) (CamelMimePart *mime_part, const gchar *header_name); + void (*set_description) (CamelMimePart *mime_part, gchar *description); + const gchar * (*get_description) (CamelMimePart *mime_part); + void (*set_disposition) (CamelMimePart *mime_part, gchar *disposition); + const gchar * (*get_disposition) (CamelMimePart *mime_part); + void (*set_filename) (CamelMimePart *mime_part, gchar *filename); + const gchar * (*get_filename) (CamelMimePart *mime_part); + void (*set_content_id) (CamelMimePart *mime_part, gchar *content_id); + const gchar * (*get_content_id) (CamelMimePart *mime_part); + void (*set_content_MD5) (CamelMimePart *mime_part, gchar *content_MD5); + const gchar * (*get_content_MD5) (CamelMimePart *mime_part); + void (*set_encoding) (CamelMimePart *mime_part, gchar *encoding); + const gchar * (*get_encoding) (CamelMimePart *mime_part); void (*set_content_languages) (CamelMimePart *mime_part, GList *content_languages); - GList * (*get_content_languages) (CamelMimePart *mime_part); + const 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); + const GList * (*get_header_lines) (CamelMimePart *mime_part); + void (*set_content_type) (CamelMimePart *mime_part, const gchar *content_type); + GMimeContentField * (*get_content_type) (CamelMimePart *mime_part); - CamelDataWrapper * (*get_content_object) (CamelMimePart *mime_part); + gboolean (*parse_header_pair) (CamelMimePart *mime_part, gchar *header_name, gchar *header_value); + + const CamelDataWrapper * (*get_content_object) (CamelMimePart *mime_part); + void (*set_content_object) (CamelMimePart *mime_part, CamelDataWrapper *content); + } CamelMimePartClass; @@ -104,36 +105,37 @@ GtkType camel_mime_part_get_type (void); /* public methods */ -void camel_mime_part_add_header (CamelMimePart *mime_part, - GString *header_name, - GString *header_value); -void camel_mime_part_remove_header (CamelMimePart *mime_part, - GString *header_name); -GString *camel_mime_part_get_header (CamelMimePart *mime_part, - GString *header_name); -void camel_mime_part_set_description (CamelMimePart *mime_part, - GString *description); -GString *camel_mime_part_get_description (CamelMimePart *mime_part); -void camel_mime_part_set_disposition (CamelMimePart *mime_part, - GString *disposition); -GString *camel_mime_part_get_disposition (CamelMimePart *mime_part); -void camel_mime_part_set_filename (CamelMimePart *mime_part, - GString *filename); -GString *camel_mime_part_get_filename (CamelMimePart *mime_part); -GString *camel_mime_part_get_content_id (CamelMimePart *mime_part); -GString *camel_mime_part_get_content_MD5 (CamelMimePart *mime_part); -void camel_mime_part_set_encoding (CamelMimePart *mime_part, - GString *encoding); -GString *camel_mime_part_get_encoding (CamelMimePart *mime_part); -void camel_mime_part_set_content_languages (CamelMimePart *mime_part, - GList *content_languages); -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_add_header (CamelMimePart *mime_part, gchar *header_name, gchar *header_value); +void camel_mime_part_remove_header (CamelMimePart *mime_part, const gchar *header_name); +const gchar *camel_mime_part_get_header (CamelMimePart *mime_part, const gchar *header_name); +void camel_mime_part_set_description (CamelMimePart *mime_part, gchar *description); +const gchar *camel_mime_part_get_description (CamelMimePart *mime_part); +void camel_mime_part_set_disposition (CamelMimePart *mime_part, gchar *disposition); +const gchar *camel_mime_part_get_disposition (CamelMimePart *mime_part); +void camel_mime_part_set_filename (CamelMimePart *mime_part, gchar *filename); +const gchar *camel_mime_part_get_filename (CamelMimePart *mime_part); +const gchar *camel_mime_part_get_content_id (CamelMimePart *mime_part); +const gchar *camel_mime_part_get_content_MD5 (CamelMimePart *mime_part); +void camel_mime_part_set_encoding (CamelMimePart *mime_part, gchar *encoding); +const gchar *camel_mime_part_get_encoding (CamelMimePart *mime_part); +void camel_mime_part_set_content_languages (CamelMimePart *mime_part, GList *content_languages); +const GList *camel_mime_part_get_content_languages (CamelMimePart *mime_part); +void camel_mime_part_set_header_lines (CamelMimePart *mime_part, GList *header_lines); +const GList *camel_mime_part_get_header_lines (CamelMimePart *mime_part); + +const CamelDataWrapper *camel_mime_part_get_content_object (CamelMimePart *mime_part); +void camel_mime_part_set_content_object (CamelMimePart *mime_part, CamelDataWrapper *content); + + +/* utility functions */ +void camel_mime_part_set_text (CamelMimePart *camel_mime_part, gchar *text); + + + #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* CAMEL_MIME_PART_H */ + diff --git a/camel/camel-service.c b/camel/camel-service.c index 645eaf3f09..c0f436bb89 100644 --- a/camel/camel-service.c +++ b/camel/camel-service.c @@ -29,11 +29,11 @@ static GtkObjectClass *parent_class=NULL; #define CSERV_CLASS(so) CAMEL_SERVICE_CLASS (GTK_OBJECT(so)->klass) static void _connect(CamelService *service); -static void _connect_to_with_login_passwd(CamelService *service, GString *host, GString *login, GString *passwd); -static void _connect_to_with_login_passwd_port(CamelService *service, GString *host, GString *login, GString *passwd, guint port); -static gboolean _is_connected(CamelService *service); -static void _set_connected(CamelService *service, gboolean state); -static GString *_get_url(CamelService *service); +static void _connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd); +static void _connect_to_with_login_passwd_port (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port); +static gboolean _is_connected (CamelService *service); +static void _set_connected (CamelService *service, gboolean state); +static const gchar *_get_url (CamelService *service); static void camel_service_class_init (CamelServiceClass *camel_service_class) @@ -95,7 +95,7 @@ camel_service_get_type (void) * @service: object to connect **/ static void -_connect(CamelService *service) +_connect (CamelService *service) { CSERV_CLASS(service)->set_connected(service, TRUE); } @@ -111,7 +111,7 @@ _connect(CamelService *service) * @service: object to connect to **/ void -camel_service_connect(CamelService *service) +camel_service_connect (CamelService *service) { CSERV_CLASS(service)->connect(service); } @@ -130,7 +130,7 @@ camel_service_connect(CamelService *service) * @passwd: password used to log in **/ static void -_connect_to_with_login_passwd(CamelService *service, GString *host, GString *login, GString *passwd) +_connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd) { CSERV_CLASS(service)->set_connected(service, TRUE); } @@ -147,7 +147,7 @@ _connect_to_with_login_passwd(CamelService *service, GString *host, GString *log * **/ void -camel_service_connect_to_with_login_passwd(CamelService *service, GString *host, GString *login, GString *passwd) +camel_service_connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd) { CSERV_CLASS(service)->connect_to_with_login_passwd (service, host, login, passwd); } @@ -168,7 +168,7 @@ camel_service_connect_to_with_login_passwd(CamelService *service, GString *host, * **/ static void -_connect_to_with_login_passwd_port(CamelService *service, GString *host, GString *login, GString *passwd, guint port) +_connect_to_with_login_passwd_port(CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port) { CSERV_CLASS(service)->set_connected(service, TRUE); } @@ -187,7 +187,7 @@ _connect_to_with_login_passwd_port(CamelService *service, GString *host, GString * **/ void -camel_service_connect_to_with_login_passwd_port(CamelService *service, GString *host, GString *login, GString *passwd, guint port) +camel_service_connect_to_with_login_passwd_port (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port) { CSERV_CLASS(service)->connect_to_with_login_passwd_port (service, host, login, passwd, port); } @@ -203,7 +203,7 @@ camel_service_connect_to_with_login_passwd_port(CamelService *service, GString * * **/ static gboolean -_is_connected(CamelService *service) +_is_connected (CamelService *service) { return service->connected; } @@ -219,7 +219,7 @@ _is_connected(CamelService *service) * Return value: TRUE is the service is connected **/ gboolean -camel_service_is_connected(CamelService *service) +camel_service_is_connected (CamelService *service) { return CSERV_CLASS(service)->is_connected(service); } @@ -237,7 +237,7 @@ camel_service_is_connected(CamelService *service) * **/ static void -_set_connected(CamelService *service, gboolean state) +_set_connected (CamelService *service, gboolean state) { service->connected = state; } @@ -253,8 +253,8 @@ _set_connected(CamelService *service, gboolean state) * * Return value: **/ -static GString * -_get_url(CamelService *service) +static const gchar * +_get_url (CamelService *service) { return service->url; } @@ -268,8 +268,8 @@ _get_url(CamelService *service) * * Return value: the url name **/ -GString * -camel_service_get_url(CamelService *service) +const gchar * +camel_service_get_url (CamelService *service) { return CSERV_CLASS(service)->get_url(service); } diff --git a/camel/camel-service.h b/camel/camel-service.h index d22f97a6bc..7831699bbf 100644 --- a/camel/camel-service.h +++ b/camel/camel-service.h @@ -44,7 +44,7 @@ typedef struct { GtkObject parent_object; gboolean connected; - GString *url; /* This may be a full object ? */ + gchar *url; /* This may be a full object ? */ } CamelService; @@ -54,11 +54,11 @@ typedef struct { GtkObjectClass parent_class; void (*connect) (CamelService *service); - void (*connect_to_with_login_passwd) (CamelService *service, GString *host, GString *login, GString *passwd); - void (*connect_to_with_login_passwd_port) (CamelService *service, GString *host, GString *login, GString *passwd, guint port); + void (*connect_to_with_login_passwd) (CamelService *service, gchar *host, gchar *login, gchar *passwd); + void (*connect_to_with_login_passwd_port) (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port); gboolean (*is_connected) (CamelService *service); void (*set_connected) (CamelService *service, gboolean state); - GString * (*get_url) (CamelService *service); + const gchar * (*get_url) (CamelService *service); } CamelServiceClass; @@ -68,9 +68,9 @@ typedef struct { /* public methods */ void camel_service_connect (CamelService *service); gboolean camel_service_is_connected (CamelService *service); -void camel_service_connect_to_with_login_passwd (CamelService *service, GString *host, GString *login, GString *passwd); -void camel_service_connect_to_with_login_passwd_port (CamelService *service, GString *host, GString *login, GString *passwd, guint port); -GString *camel_service_get_url(CamelService *service); +void camel_service_connect_to_with_login_passwd (CamelService *service, gchar *host, gchar *login, gchar *passwd); +void camel_service_connect_to_with_login_passwd_port (CamelService *service, gchar *host, gchar *login, gchar *passwd, guint port); +const gchar *camel_service_get_url (CamelService *service); /* Standard Gtk function */ GtkType camel_service_get_type (void); diff --git a/camel/camel-session.c b/camel/camel-session.c index 5238b8d5eb..f9916df6f6 100644 --- a/camel/camel-session.c +++ b/camel/camel-session.c @@ -22,7 +22,6 @@ */ #include <config.h> #include "camel-session.h" -#include "gstring-util.h" static GtkObjectClass *parent_class=NULL; diff --git a/camel/camel-simple-data-wrapper.c b/camel/camel-simple-data-wrapper.c index 775cf5ca58..eaf62bb0a7 100644 --- a/camel/camel-simple-data-wrapper.c +++ b/camel/camel-simple-data-wrapper.c @@ -23,13 +23,14 @@ */ #include <config.h> #include "camel-simple-data-wrapper.h" +#include "camel-log.h" static CamelDataWrapperClass *parent_class=NULL; /* Returns the class for a CamelDataWrapper */ #define CSDW_CLASS(so) CAMEL_SIMPLE_DATA_WRAPPER_CLASS (GTK_OBJECT(so)->klass) -static void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, guint size); +static void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); static void @@ -58,9 +59,9 @@ camel_simple_data_wrapper_get_type (void) if (!camel_simple_data_wrapper_type) { GtkTypeInfo camel_simple_data_wrapper_info = { - "CamelDataWrapper", - sizeof (CamelDataWrapper), - sizeof (CamelDataWrapperClass), + "CamelSimpleDataWrapper", + sizeof (CamelSimpleDataWrapper), + sizeof (CamelSimpleDataWrapperClass), (GtkClassInitFunc) camel_simple_data_wrapper_class_init, (GtkObjectInitFunc) NULL, /* reserved_1 */ NULL, @@ -76,21 +77,41 @@ camel_simple_data_wrapper_get_type (void) +/** + * camel_simple_data_wrapper_new: create a new CamelSimpleDataWrapper object + * + * + * + * Return value: + **/ +CamelSimpleDataWrapper * +camel_simple_data_wrapper_new () +{ + CamelSimpleDataWrapper *simple_data_wrapper; + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering new()\n"); + + simple_data_wrapper = (CamelSimpleDataWrapper *)gtk_type_new (CAMEL_SIMPLE_DATA_WRAPPER_TYPE); + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Leaving new()\n"); + return simple_data_wrapper; +} + + + static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { CamelSimpleDataWrapper *simple_data_wrapper = CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper); GByteArray *array; + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering _write_to_stream\n"); g_assert (data_wrapper); g_assert (stream); g_assert (simple_data_wrapper->byte_array); - array = simple_data_wrapper->byte_array; if (array->len) camel_stream_write (stream, (gchar *)array->data, array->len); - return; + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Leaving _write_to_stream\n"); } @@ -98,7 +119,7 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) #define _CMSDW_TMP_BUF_SIZE 100 static void -_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, guint size) +_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { CamelSimpleDataWrapper *simple_data_wrapper = CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper); guint current_index; @@ -106,12 +127,11 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, gui guint nb_bytes_left; static gchar *tmp_buf; GByteArray *array; - + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering _construct_from_stream\n"); g_assert (data_wrapper); g_assert (stream); - if (!size) return; if (!tmp_buf) tmp_buf = g_new (gchar, _CMSDW_TMP_BUF_SIZE); array = simple_data_wrapper->byte_array; @@ -119,14 +139,43 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream, gui g_byte_array_free (array, FALSE); array = g_byte_array_new(); - nb_bytes_left = size; + simple_data_wrapper->byte_array = array; do { - - nb_bytes_read = camel_stream_read (stream, tmp_buf, - MIN (_CMSDW_TMP_BUF_SIZE, nb_bytes_left)); - nb_bytes_left -= nb_bytes_read; - if (nb_bytes_read) g_byte_array_append (array, tmp_buf, nb_bytes_read); - - } while (nb_bytes_read && (nb_bytes_left>0)); + 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"); +} + + + + +/** + * camel_simple_data_wrapper_set_text: set some text as data wrapper content + * @simple_data_wrapper: SimpleDataWrapper object + * @text: the text to use + * + * Utility routine used to set up the content of a SimpleDataWrapper object + * to be a character string. + **/ +void +camel_simple_data_wrapper_set_text (CamelSimpleDataWrapper *simple_data_wrapper, const gchar *text) +{ + GByteArray *array; + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering set_text\n"); + + array = simple_data_wrapper->byte_array; + if (array) { + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::set_text freeing old byte array\n"); + g_byte_array_free (array, FALSE); + } + array = g_byte_array_new (); + simple_data_wrapper->byte_array = array; + + g_byte_array_append (array, text, strlen (text)); + + CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper:: Entering set_text\n"); } + diff --git a/camel/camel-simple-data-wrapper.h b/camel/camel-simple-data-wrapper.h index ce84906bc3..eeefb48921 100644 --- a/camel/camel-simple-data-wrapper.h +++ b/camel/camel-simple-data-wrapper.h @@ -69,6 +69,8 @@ GtkType camel_simple_data_wrapper_get_type (void); /* public methods */ +CamelSimpleDataWrapper *camel_simple_data_wrapper_new (); +void camel_simple_data_wrapper_set_text (CamelSimpleDataWrapper *simple_data_wrapper, const gchar *text); #ifdef __cplusplus } diff --git a/camel/camel-store.c b/camel/camel-store.c index cedd452c44..c58f14c110 100644 --- a/camel/camel-store.c +++ b/camel/camel-store.c @@ -31,7 +31,7 @@ static GtkObjectClass *parent_class=NULL; static void _set_separator(CamelStore *store, gchar sep); static CamelFolder *_get_root_folder(CamelStore *store); static CamelFolder *_get_default_folder(CamelStore *store); -static void _init(CamelStore *store, CamelSession *session, GString *url_name); +static void _init(CamelStore *store, CamelSession *session, gchar *url_name); @@ -95,10 +95,10 @@ camel_store_get_type (void) * **/ void -camel_store_init(CamelStore *store, CamelSession *session, GString *url_name) +camel_store_init(CamelStore *store, CamelSession *session, gchar *url_name) { g_assert(store); - CS_CLASS(store)->init(store, session, url_name); + CS_CLASS(store)->init (store, session, url_name); } @@ -110,11 +110,12 @@ camel_store_init(CamelStore *store, CamelSession *session, GString *url_name) * @url_name: URL defining the store * * This routine is called by the session object from which this - * store is created. + * store is created. Be careful, @url_name is used as a private field + * of the store object. * **/ static void -_init(CamelStore *store, CamelSession *session, GString *url_name) +_init (CamelStore *store, CamelSession *session, gchar *url_name) { @@ -136,7 +137,7 @@ _init(CamelStore *store, CamelSession *session, GString *url_name) * **/ static void -_set_separator(CamelStore *store, gchar sep) +_set_separator (CamelStore *store, gchar sep) { store->separator = sep; } @@ -151,7 +152,7 @@ _set_separator(CamelStore *store, gchar sep) * **/ gchar -camel_store_get_separator(CamelStore *store) +camel_store_get_separator (CamelStore *store) { g_assert(store); return store->separator; @@ -178,7 +179,7 @@ camel_store_get_separator(CamelStore *store) * Return value: the folder **/ CamelFolder * -camel_store_get_folder(CamelStore *store, GString *folder_name) +camel_store_get_folder (CamelStore *store, gchar *folder_name) { #warning fill this part in. @@ -196,7 +197,7 @@ camel_store_get_folder(CamelStore *store, GString *folder_name) * @Return value: the tolevel folder. **/ static CamelFolder * -_get_root_folder(CamelStore *store) +_get_root_folder (CamelStore *store) { return NULL; } @@ -211,7 +212,7 @@ _get_root_folder(CamelStore *store) * @Return value: the default folder. **/ static CamelFolder * -_get_default_folder(CamelStore *store) +_get_default_folder (CamelStore *store) { return NULL; } diff --git a/camel/camel-store.h b/camel/camel-store.h index df8409f92e..38fb0f10f7 100644 --- a/camel/camel-store.h +++ b/camel/camel-store.h @@ -50,7 +50,7 @@ struct _CamelStore CamelService parent_object; CamelSession *session; - GString *url_name; + gchar *url_name; gchar separator; }; @@ -59,10 +59,10 @@ struct _CamelStore typedef struct { CamelServiceClass parent_class; - void (*init) (CamelStore *store, CamelSession *session, GString *url_name); + void (*init) (CamelStore *store, CamelSession *session, gchar *url_name); void (*set_separator) (CamelStore *store, gchar sep); gchar (*get_separator) (CamelStore *store); - CamelFolder * (*get_folder) (CamelStore *store, GString *folder_name); + CamelFolder * (*get_folder) (CamelStore *store, gchar *folder_name); CamelFolder * (*get_root_folder) (CamelStore *store); CamelFolder * (*get_default_folder) (CamelStore *store); @@ -74,8 +74,8 @@ typedef struct { /* Standard Gtk function */ GtkType camel_store_get_type (void); -void camel_store_init(CamelStore *store, CamelSession *session, GString *url_name); -CamelFolder *camel_store_get_folder(CamelStore *store, GString *folder_name); +void camel_store_init(CamelStore *store, CamelSession *session, gchar *url_name); +CamelFolder *camel_store_get_folder(CamelStore *store, gchar *folder_name); gchar camel_store_get_separator(CamelStore *store); #ifdef __cplusplus diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c index 0b70802943..3216f6ffdf 100644 --- a/camel/camel-stream-fs.c +++ b/camel/camel-stream-fs.c @@ -36,7 +36,7 @@ static CamelStreamClass *parent_class=NULL; #define CS_CLASS(so) CAMEL_STREAM_FS_CLASS (GTK_OBJECT(so)->klass) static gint _read (CamelStream *stream, gchar *buffer, gint n); -static gint _write (CamelStream *stream, gchar *buffer, gint n); +static gint _write (CamelStream *stream, const gchar *buffer, gint n); static void _flush (CamelStream *stream); static gint _available (CamelStream *stream); static gboolean _eos (CamelStream *stream); @@ -89,7 +89,7 @@ camel_stream_fs_get_type (void) CamelStream * -camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode) +camel_stream_fs_new_with_name (gchar *name, CamelStreamFsMode mode) { struct stat s; int v, fd; @@ -97,9 +97,8 @@ camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode) CamelStreamFs *stream_fs; g_assert (name); - g_assert (name->str); - CAMEL_LOG (FULL_DEBUG, "Entering CamelStream::new_with_name, name=\"%s\", mode=%d\n", name->str, mode); - v = stat (name->str, &s); + CAMEL_LOG_FULL_DEBUG ( "Entering CamelStream::new_with_name, name=\"%s\", mode=%d\n", name, mode); + v = stat (name, &s); if (mode & CAMEL_STREAM_FS_READ){ if (mode & CAMEL_STREAM_FS_WRITE) @@ -115,10 +114,10 @@ camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode) if ( (mode & CAMEL_STREAM_FS_READ) && !(mode & CAMEL_STREAM_FS_WRITE) ) if (v == -1) return NULL; - fd = open (name->str, flags, 0600); + fd = open (name, flags, 0600); if (fd==-1) { - CAMEL_LOG (FULL_DEBUG, "CamelStreamFs::new_with_name can not obtain fd for file \"%s\"\n", name->str); - CAMEL_LOG (FULL_DEBUG, " Full error text is : %s\n", strerror(errno)); + CAMEL_LOG_FULL_DEBUG ( "CamelStreamFs::new_with_name can not obtain fd for file \"%s\"\n", name); + CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno)); return NULL; } @@ -134,7 +133,7 @@ camel_stream_fs_new_with_fd (int fd) { CamelStreamFs *stream_fs; - CAMEL_LOG (FULL_DEBUG, "Entering CamelStream::new_with_fd fd=%d\n",fd); + CAMEL_LOG_FULL_DEBUG ( "Entering CamelStream::new_with_fd fd=%d\n",fd); stream_fs = gtk_type_new (camel_stream_fs_get_type ()); stream_fs->fd = fd; return CAMEL_STREAM (stream_fs); @@ -154,11 +153,9 @@ static gint _read (CamelStream *stream, gchar *buffer, gint n) { int v; - do { v = read ( (CAMEL_STREAM_FS (stream))->fd, buffer, n); } while (v == -1 && errno == EINTR); - return v; } @@ -175,12 +172,12 @@ _read (CamelStream *stream, gchar *buffer, gint n) * in the stream. **/ static gint -_write (CamelStream *stream, gchar *buffer, gint n) +_write (CamelStream *stream, const gchar *buffer, gint n) { int v; g_assert (stream); g_assert ((CAMEL_STREAM_FS (stream))->fd); - CAMEL_LOG (FULL_DEBUG, "CamelStreamFs:: entering write. n=%d\n", n); + CAMEL_LOG_FULL_DEBUG ( "CamelStreamFs:: entering write. n=%d\n", n); do { v = write ( (CAMEL_STREAM_FS (stream))->fd, buffer, n); } while (v == -1 && errno == EINTR); @@ -188,7 +185,7 @@ _write (CamelStream *stream, gchar *buffer, gint n) #if HARD_LOG_LEVEL >= FULL_DEBUG if (v==-1) { perror(""); - CAMEL_LOG (FULL_DEBUG, "CamelStreamFs::write could not write bytes in stream\n"); + CAMEL_LOG_FULL_DEBUG ( "CamelStreamFs::write could not write bytes in stream\n"); } #endif return v; diff --git a/camel/camel-stream-fs.h b/camel/camel-stream-fs.h index 3570e8a9f9..9f295cdb4a 100644 --- a/camel/camel-stream-fs.h +++ b/camel/camel-stream-fs.h @@ -50,7 +50,7 @@ typedef enum typedef struct { CamelStream parent_object; - GString *name; + gchar *name; int fd; } CamelStreamFs; @@ -70,7 +70,7 @@ GtkType camel_stream_fs_get_type (void); /* public methods */ -CamelStream *camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode); +CamelStream *camel_stream_fs_new_with_name (gchar *name, CamelStreamFsMode mode); CamelStream *camel_stream_fs_new_with_fd (int fd); #ifdef __cplusplus diff --git a/camel/camel-stream.c b/camel/camel-stream.c index 5554b8fe38..c66a950b26 100644 --- a/camel/camel-stream.c +++ b/camel/camel-stream.c @@ -112,7 +112,7 @@ camel_stream_read (CamelStream *stream, gchar *buffer, gint n) * in the stream. **/ gint -camel_stream_write (CamelStream *stream, gchar *buffer, gint n) +camel_stream_write (CamelStream *stream, const gchar *buffer, gint n) { return CS_CLASS (stream)->write (stream, buffer, n); } @@ -135,14 +135,14 @@ camel_stream_flush (CamelStream *stream) * * Return value: the number of bytes available. **/ -static gint +gint camel_stream_available (CamelStream *stream) { return CS_CLASS (stream)->available (stream); } /** - * camle_stream_eos: + * camel_stream_eos: * @stream: a CamelStream object * * Test if there are bytes left to read on the @stream object. @@ -150,7 +150,7 @@ camel_stream_available (CamelStream *stream) * Return value: %TRUE if all the contents on the stream has been read, or * %FALSE if information is still available. **/ -static gboolean +gboolean camel_stream_eos (CamelStream *stream) { return CS_CLASS (stream)->eos (stream); @@ -183,10 +183,10 @@ void camel_stream_write_strings (CamelStream *stream, ... ) { va_list args; - char *string; + const char *string; va_start(args, stream); - string = va_arg (args, char *); + string = va_arg (args, const char *); while (string) { camel_stream_write_string (stream, string); diff --git a/camel/camel-stream.h b/camel/camel-stream.h index 8434002757..9818e492fb 100644 --- a/camel/camel-stream.h +++ b/camel/camel-stream.h @@ -53,7 +53,7 @@ typedef struct { /* Virtual methods */ gint (*read) (CamelStream *stream, gchar *buffer, gint n); - gint (*write) (CamelStream *stream, gchar *buffer, gint n); + gint (*write) (CamelStream *stream, const gchar *buffer, gint n); void (*flush) (CamelStream *stream); gint (*available) (CamelStream *stream); gboolean (*eos) (CamelStream *stream); @@ -68,7 +68,7 @@ GtkType camel_stream_get_type (void); /* public methods */ gint camel_stream_read (CamelStream *stream, gchar *buffer, gint n); -gint camel_stream_write (CamelStream *stream, gchar *buffer, gint n); +gint camel_stream_write (CamelStream *stream, const gchar *buffer, gint n); void camel_stream_flush (CamelStream *stream); gint camel_stream_available (CamelStream *stream); gboolean camel_stream_eos (CamelStream *stream); diff --git a/camel/gmime-content-field.c b/camel/gmime-content-field.c index e37c319b55..b4c8496083 100644 --- a/camel/gmime-content-field.c +++ b/camel/gmime-content-field.c @@ -23,10 +23,10 @@ #include <config.h> #include "gmime-content-field.h" -/* #include "-util.h" */ +#include "string-utils.h" #include "camel-log.h" -/ + /** * gmime_content_field_new: Creates a new GMimeContentField object @@ -41,14 +41,14 @@ * * Return value: The newly created GMimeContentField object **/ -void +GMimeContentField * gmime_content_field_new (const gchar *type, const gchar *subtype) { GMimeContentField *ctf; ctf = g_new (GMimeContentField, 1); - ctf->type = type; - ctf->subtype = subtype; + ctf->type = g_strdup (type); + ctf->subtype = g_strdup (subtype); ctf->parameters = g_hash_table_new (g_str_hash, g_str_equal); return ctf; @@ -73,18 +73,20 @@ gmime_content_field_set_parameter (GMimeContentField *content_field, const gchar gboolean attribute_exists; gchar *old_attribute; gchar *old_value; - + CAMEL_LOG_FULL_DEBUG ("GMimeContentField:: Entering set_parameter\n"); + CAMEL_LOG_FULL_DEBUG ("GMimeContentField:: set_parameter content_field=%p name=%s, value=%s\n", content_field, attribute, value); attribute_exists = g_hash_table_lookup_extended (content_field->parameters, attribute, (gpointer *) &old_attribute, (gpointer *) &old_value); - /** CHECK THAT **/ + /** CHECK THAT : is normal to free pointers before insertion ? **/ if (attribute_exists) { - g_string_free (old_value, TRUE); - g_string_free (old_attribute, TRUE); + g_free (old_value); + g_free (old_attribute); } - g_hash_table_insert (content_field->parameters, attribute, value); + g_hash_table_insert (content_field->parameters, g_strdup (attribute), g_strdup (value)); + CAMEL_LOG_FULL_DEBUG ("GMimeContentField:: Leaving set_parameter\n"); } @@ -112,7 +114,7 @@ _print_parameter (gpointer name, gpointer value, gpointer user_data) } /** - * gmime_content_field_write_to: write a mime content type to a stream + * gmime_content_field_write_to_stream: write a mime content type to a stream * @content_field: content type object * @stream: the stream * @@ -122,7 +124,9 @@ void gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStream *stream) { if (!content_field) return; - if ((content_field->type) && ((content_field->type)->str)) { + + g_assert (stream); + if (content_field->type) { camel_stream_write_strings (stream, "Content-Type: ", content_field->type, NULL); if (content_field->subtype) { camel_stream_write_strings (stream, "/", content_field->subtype, NULL); @@ -130,26 +134,97 @@ gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStre /* print all parameters */ g_hash_table_foreach (content_field->parameters, _print_parameter, stream); camel_stream_write_string (stream, "\n"); - } + } } +/** + * gmime_content_field_get_mime_type: return the mime type of the content field object + * @content_field: content field object + * + * A RFC 2045 content type field contains the mime type in the + * form "type/subtype" (example : "application/postscript") and some + * parameters (attribute/value pairs). This routine returns the mime type + * in a gchar object. + * + * Return value: the mime type in the form "type/subtype" or NULL if not defined. + **/ gchar * gmime_content_field_get_mime_type (GMimeContentField *content_field) { gchar *mime_type; if (!content_field->type) return NULL; - mime_type = g_strdup (content_field->type); - if (content_field->subtype) { - g_string_append_c (mime_type, '/'); - g_string_append_g_string (mime_type, content_field->subtype); - } + + if (content_field->subtype) + mime_type = g_strdup_printf ("%s/%s", content_field->type, content_field->subtype); + else + mime_type = g_strdup (content_field->type); return mime_type; } +static void +___debug_print_parameter (gpointer name, gpointer value, gpointer user_data) +{ + + printf ("****** parameter \"%s\"=\"%s\"\n", (gchar *)name, (gchar *)value); + +} + +/** + * gmime_content_field_get_parameter: return the value of a mime type parameter + * @content_field: content field object + * @name: name of the parameter + * + * Returns the value of a parameter contained in the content field + * object. The content type is formed of a mime type, a mime subtype, + * and a parameter list. Each parameter is a name/value pair. This + * routine returns the value assiciated to a given name. + * When the parameter does not exist, NULL is returned. + * + * Return value: parameter value, or NULL if not found. + **/ +const gchar * +gmime_content_field_get_parameter (GMimeContentField *content_field, const gchar *name) +{ + const gchar *parameter; + const gchar *old_name; + gboolean parameter_exists; + + CAMEL_LOG_FULL_DEBUG ("Entering GMimeContentField::get_parameter content_field =%p\n", content_field); + g_assert (content_field->parameters); + g_assert (name); + CAMEL_LOG_FULL_DEBUG ("GMimeContentField::get_parameter looking for parameter \"%s\"\n", name); + //parameter = (const gchar *)g_hash_table_lookup (content_field->parameters, name); + parameter_exists = g_hash_table_lookup_extended (content_field->parameters, + name, + (gpointer *) &old_name, + (gpointer *) ¶meter); + if (!parameter_exists) { + CAMEL_LOG_FULL_DEBUG ("GMimeContentField::get_parameter, parameter not found\n"); + g_hash_table_foreach (content_field->parameters, ___debug_print_parameter, NULL); + return NULL; + } + CAMEL_LOG_FULL_DEBUG ("Leaving GMimeContentField::get_parameter\n"); + return parameter; +} + + + +/** + * gmime_content_field_construct_from_string: construct a ContentType object + * by parsing a string. + * + * @content_field: content type object to construct + * @string: string containing the content type field + * + * Parse a string containing a content type field as defined in + * RFC 2045, and construct the corresponding ContentType object. + * The string is not modified and not used in the ContentType + * object. It can and must be freed by the calling part. + **/ void -gmime_content_field_construct_from_string (GMimeContentField *content_field, gchar *string) +gmime_content_field_construct_from_string (GMimeContentField *content_field, const gchar *string) { gint first, len; gchar *str; @@ -158,47 +233,48 @@ gmime_content_field_construct_from_string (GMimeContentField *content_field, gch gchar *param_name, *param_value; gboolean param_end; - CAMEL_LOG (TRACE, "Entering gmime_content_field_construct_from_string\n"); + CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, entering\n"); g_assert (string); - g_assert (string->str); g_assert (content_field); if (content_field->type) { - CAMEL_LOG (FULL_DEBUG, "Freeing old mime type string\n"); - g_string_free (content_field->type, FALSE); + CAMEL_LOG_FULL_DEBUG ( "GMimeContentField::construct_from_string, Freeing old mime type string\n"); + g_free (content_field->type); } if (content_field->subtype) { - CAMEL_LOG (FULL_DEBUG, "Freeing old mime type substring\n"); - g_string_free (content_field->subtype, FALSE); + CAMEL_LOG_FULL_DEBUG ( "GMimeContentField::construct_from_string, Freeing old mime type substring\n"); + g_free (content_field->subtype); } - str = string->str; first = 0; - len = string->len; + len = strlen (string); if (!len) return; - CAMEL_LOG (TRACE, "All checks done\n"); + CAMEL_LOG_FULL_DEBUG ("GMimeContentField::construct_from_string, All checks done\n"); /* find the type */ - while ( (i<len) && (!strchr ("/;", str[i])) ) i++; + while ( (i<len) && (!strchr ("/;", string[i])) ) i++; if (i == 0) return; - type = g_string_new (g_strndup (str, i)); + type = g_strndup (string, i); + string_trim (type, " \t", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING); content_field->type = type; - CAMEL_LOG (TRACE, "Found mime type : %s\n", type->str); - if (i == len) { + CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, Found mime type : \"%s\"\n", type); + if (i >= len-1) { content_field->subtype = NULL; return; } first = i+1; /* find the subtype, if any */ - if (str[i++] == '/') { - while ( (i<len) && (str[i] != ';') ) i++; + if (string[i++] == '/') { + while ( (i<len) && (string[i] != ';') ) i++; if (i != first) { - subtype = g_string_new (g_strndup (str+first, i-first)); + subtype = g_strndup (string+first, i-first); + string_trim (subtype, " \t", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING); content_field->subtype = subtype; - if (i == len) return; + CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, Found mime subtype: \"%s\"\n", subtype); + if (i >= len-1) return; } } first = i+1; @@ -206,17 +282,20 @@ gmime_content_field_construct_from_string (GMimeContentField *content_field, gch /* parse parameters list */ param_end = FALSE; do { - while ( (i<len) && (str[i] != '=') ) i++; + while ( (i<len) && (string[i] != '=') ) i++; if ((i == len) || (i==first)) param_end = TRUE; else { /* we have found parameter name */ - param_name = g_string_new (g_strndup (str+first, i-first)); + param_name = g_strndup (string+first, i-first); + string_trim (param_name, " ", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING); i++; first = i; /* Let's find parameter value */ - while ( (i<len) && (str[i] != ';') ) i++; - if (i != first) param_value = g_string_new (g_strndup (str+first, i-first)); - else param_value = g_string_new (""); + while ( (i<len) && (string[i] != ';') ) i++; + if (i != first) param_value = g_strndup (string+first, i-first); + else param_value = g_strdup (""); + CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, Found mime parameter \"%s\"=\"%s\"\n", param_name, param_value); + string_trim (param_value, " \t", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING); gmime_content_field_set_parameter (content_field, param_name, param_value); i++; first = i; @@ -230,16 +309,16 @@ gmime_content_field_construct_from_string (GMimeContentField *content_field, gch static void _free_parameter (gpointer name, gpointer value, gpointer user_data) { - g_string_free (name, FALSE); - g_string_free (value, FALSE); + g_free (name); + g_free (value); } 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_free (content_field->type); + g_free (content_field->subtype); 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 e71b21bb34..663c747291 100644 --- a/camel/gmime-content-field.h +++ b/camel/gmime-content-field.h @@ -46,9 +46,10 @@ typedef struct { GMimeContentField *gmime_content_field_new (const gchar *type, const gchar *subtype); void gmime_content_field_set_parameter (GMimeContentField *content_field, const gchar *attribute, const gchar *value); void gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStream *stream); -void gmime_content_field_construct_from_string (GMimeContentField *content_field, gchar *string); +void gmime_content_field_construct_from_string (GMimeContentField *content_field, const gchar *string); void gmime_content_field_free (GMimeContentField *content_field); gchar * gmime_content_field_get_mime_type (GMimeContentField *content_field); +const gchar *gmime_content_field_get_parameter (GMimeContentField *content_field, const gchar *name); #ifdef __cplusplus diff --git a/camel/gmime-utils.c b/camel/gmime-utils.c index 8c3db96cd4..27cc6b9674 100644 --- a/camel/gmime-utils.c +++ b/camel/gmime-utils.c @@ -23,58 +23,65 @@ #include <config.h> #include "gmime-utils.h" -#include "gstring-util.h" +#include "string-utils.h" #include "camel-log.h" #include "camel-stream.h" void -gmime_write_header_pair_to_stream (CamelStream *stream, gchar* name, GString *value) +gmime_write_header_pair_to_stream (CamelStream *stream, const gchar* name, const gchar *value) { - GString *strtmp; + gchar *strtmp; guint len; - + CAMEL_LOG_FULL_DEBUG ( "gmime_write_header_pair_to_stream:: Entering\n"); g_assert(name); - - if (!value || !(value->str)) return; - len = strlen (name) + strlen (value->str) +3; +#warning use g_strdup_printf instead + + if (!value) return; + len = strlen (name) + strlen (value) +3; /* 3 is for ": " and "\n" */ - strtmp = g_string_sized_new (len); + strtmp = g_new (gchar, len); - sprintf(strtmp->str, "%s: %s\n", name, value->str); - camel_stream_write (stream, strtmp->str, len); - CAMEL_LOG (FULL_DEBUG, "gmime_write_header_pair_to_stream:\n writing %s\n", strtmp->str); - g_string_free (strtmp, FALSE); + 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"); + } static void _write_one_header_to_stream (gpointer key, gpointer value, gpointer user_data) { - GString *header_name = (GString *)key; - GString *header_value = (GString *)value; + gchar *header_name = (gchar *)key; + gchar *header_value = (gchar *)value; CamelStream *stream = (CamelStream *)user_data; - if ( (header_name) && (header_name->str) && - (header_value) && (header_value->str) ) - gmime_write_header_pair_to_stream (stream, header_name->str, header_value); + CAMEL_LOG_FULL_DEBUG ( "_write_one_header_to_stream:: Entering\n"); + if ((header_name) && (header_value)) + gmime_write_header_pair_to_stream (stream, header_name, header_value); + CAMEL_LOG_FULL_DEBUG ( "_write_one_header_to_stream:: Leaving\n"); } void write_header_table_to_stream (CamelStream *stream, GHashTable *header_table) { + CAMEL_LOG_FULL_DEBUG ( "write_header_table_to_stream:: Entering\n"); g_hash_table_foreach (header_table, _write_one_header_to_stream, (gpointer)stream); + CAMEL_LOG_FULL_DEBUG ( "write_header_table_to_stream:: Leaving\n"); } void -write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GList *header_values, gchar *separator) +write_header_with_glist_to_stream (CamelStream *stream, const gchar *header_name, GList *header_values, const gchar *separator) { - GString *current; - + gchar *current; + + CAMEL_LOG_FULL_DEBUG ( "write_header_with_glist_to_stream:: entering\n"); if ( (header_name) && (header_values) ) { gboolean first; @@ -83,16 +90,17 @@ write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GLis camel_stream_write (stream, ": ", 2); first = TRUE; while (header_values) { - current = (GString *)header_values->data; - if ( (current) && (current->str) ) { + current = (gchar *)header_values->data; + if (current) { if (!first) camel_stream_write_string (stream, separator); else first = FALSE; - camel_stream_write (stream, current->str, strlen (current->str)); + camel_stream_write (stream, current, strlen (current)); } header_values = g_list_next(header_values); } camel_stream_write (stream, "\n", 1); } + CAMEL_LOG_FULL_DEBUG ( "write_header_with_glist_to_stream:: leaving\n"); } @@ -104,29 +112,30 @@ write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GLis /* scanning functions */ static void -_store_header_pair_from_gstring (GHashTable *header_table, GString *header_line) +_store_header_pair_from_string (GHashTable *header_table, gchar *header_line) { gchar dich_result; - GString *header_name, *header_value; + gchar *header_name, *header_value; + CAMEL_LOG_FULL_DEBUG ( "_store_header_pair_from_string:: Entering\n"); g_assert (header_table); - if ( (header_line) && (header_line->str) ) { - dich_result = g_string_dichotomy ( - header_line, ':', &header_name, &header_value, - GSTRING_DICHOTOMY_NONE); + g_assert (header_line); + if (header_line) { + dich_result = string_dichotomy ( header_line, ':', + &header_name, &header_value, + STRING_DICHOTOMY_NONE); if (dich_result != 'o') - camel_log(WARNING, - "store_header_pair_from_gstring : dichotomy result is %c" - "header line is :\n--\n%s\n--\n"); - + CAMEL_LOG_WARNING ( + "store_header_pair_from_string : dichotomy result is %c" + "header line is :\n--\n%s\n--\n"); else { - g_string_trim ( - header_value, " \t", - GSTRING_TRIM_STRIP_LEADING | GSTRING_TRIM_STRIP_TRAILING); + string_trim (header_value, " \t", + STRING_TRIM_STRIP_LEADING | STRING_TRIM_STRIP_TRAILING); g_hash_table_insert (header_table, header_name, header_value); } } - + CAMEL_LOG_FULL_DEBUG ( "_store_header_pair_from_string:: Leaving\n"); + } @@ -135,6 +144,10 @@ _store_header_pair_from_gstring (GHashTable *header_table, GString *header_line) GHashTable * get_header_table_from_stream (CamelStream *stream) { +#warning Correct Lazy Implementation + /* should not use GString. */ + /* should read the header line by line */ + /* and not char by char */ gchar next_char; gboolean crlf = FALSE; @@ -142,12 +155,14 @@ get_header_table_from_stream (CamelStream *stream) gboolean end_of_headers = FALSE; gboolean end_of_file = FALSE; GString *header_line=NULL; + gchar *str_header_line; GHashTable *header_table; - - header_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash); +#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); do { - header_line = g_string_new(""); + header_line = g_string_new (""); end_of_header_line = FALSE; crlf = FALSE; @@ -182,13 +197,47 @@ get_header_table_from_stream (CamelStream *stream) if (!end_of_header_line) camel_stream_read (stream, &next_char, 1); } while ( !end_of_header_line ); - if ( strlen(header_line->str) ) - _store_header_pair_from_gstring (header_table, header_line); + if ( strlen(header_line->str) ) { + str_header_line = g_strdup (header_line->str); + _store_header_pair_from_string (header_table, str_header_line); + } g_string_free (header_line, FALSE); } while ( (!end_of_headers) && (!end_of_file) ); - + + CAMEL_LOG_FULL_DEBUG ( "gmime-utils:: Leaving get_header_table_from_stream\n"); return header_table; } +gchar * +gmime_read_line_from_stream (CamelStream *stream) +{ + GString *new_line; + gchar *result; + gchar next_char; + gboolean end_of_line = FALSE; + gboolean end_of_stream = FALSE; + gint nb_char_read; + + new_line = g_string_new (""); + do { + nb_char_read = camel_stream_read (stream, &next_char, 1); + if (nb_char_read>0) { + switch (next_char) { + case '\n': + end_of_line = TRUE; + /* g_string_append_c (new_line, next_char); */ + break; + default: + g_string_append_c (new_line, next_char); + } + } else end_of_stream = TRUE; + } while (!end_of_line && !end_of_stream); + + if ( (new_line->str[0]) != '\0') + result = g_strdup (new_line->str); + else result=NULL; + g_string_free (new_line, TRUE); + return result; +} diff --git a/camel/gmime-utils.h b/camel/gmime-utils.h index a8ff6094e9..5c99ca3d66 100644 --- a/camel/gmime-utils.h +++ b/camel/gmime-utils.h @@ -35,11 +35,12 @@ extern "C" { #include <stdio.h> #include <camel-stream.h> -void gmime_write_header_pair_to_stream (CamelStream *stream, gchar* name, GString *value); +void gmime_write_header_pair_to_stream (CamelStream *stream, const gchar* name, const gchar *value); void write_header_table_to_stream (CamelStream *stream, GHashTable *header_table); -void write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GList *header_values, gchar *separator); +void write_header_with_glist_to_stream (CamelStream *stream, const gchar *header_name, GList *header_values, const gchar *separator); GHashTable *get_header_table_from_stream (CamelStream *stream); +gchar *gmime_read_line_from_stream (CamelStream *stream); diff --git a/camel/gstring-util.c b/camel/gstring-util.c index 89cd263e85..8b89d1d9b4 100644 --- a/camel/gstring-util.c +++ b/camel/gstring-util.c @@ -92,7 +92,7 @@ g_string_dichotomy (GString *string, gchar sep, GString **prefix, GString **suff gchar *str, *tmp; gint pos, len, first; - CAMEL_LOG(FULL_DEBUG,\ + CAMEL_LOG_FULL_DEBUG (\ "Entering string_dichotomy: \n\tseparator=%c \n\tprefix=%p \n\tsuffix=%p \n\toptions=%ld\n",\ sep, prefix, suffix, options); g_assert( tmp=string->str ); @@ -102,7 +102,7 @@ g_string_dichotomy (GString *string, gchar sep, GString **prefix, GString **suff *prefix=NULL; if (suffix) *suffix=NULL; - CAMEL_LOG(FULL_DEBUG,"string_dichotomy: string is empty\n"); + CAMEL_LOG_FULL_DEBUG ("string_dichotomy: string is empty\n"); return 'n'; } first = 0; @@ -117,7 +117,7 @@ g_string_dichotomy (GString *string, gchar sep, GString **prefix, GString **suff if (first==len) { if (prefix) *prefix=NULL; if (suffix) *suffix=NULL; - CAMEL_LOG(FULL_DEBUG,"string_dichotomy: after stripping, string is empty\n"); + CAMEL_LOG_FULL_DEBUG ("string_dichotomy: after stripping, string is empty\n"); return 'n'; } @@ -139,7 +139,7 @@ g_string_dichotomy (GString *string, gchar sep, GString **prefix, GString **suff { if (suffix) *suffix=NULL; if (prefix) *prefix=NULL; - CAMEL_LOG(FULL_DEBUG,"string_dichotomy: separator not found\n"); + CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator not found\n"); return 'n'; } @@ -149,7 +149,7 @@ g_string_dichotomy (GString *string, gchar sep, GString **prefix, GString **suff { if (suffix) *suffix=NULL; if (prefix) *prefix=NULL; - CAMEL_LOG(FULL_DEBUG,"string_dichotomy: separator is last character\n"); + CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator is last character\n"); return 'l'; } /* if we have stripped leading separators, we should */ @@ -158,7 +158,7 @@ g_string_dichotomy (GString *string, gchar sep, GString **prefix, GString **suff { if (suffix) *suffix=NULL; if (prefix) *prefix=NULL; - CAMEL_LOG(FULL_DEBUG,"string_dichotomy: separator is first character\n"); + CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator is first character\n"); return 'l'; } @@ -279,7 +279,7 @@ g_string_split (GString *string, char sep, gchar *trim_chars, GStringTrimOption last--; - CAMEL_LOG(FULL_DEBUG,"g_string_split:: trim options: %d\n", trim_options); + CAMEL_LOG_FULL_DEBUG ("g_string_split:: trim options: %d\n", trim_options); while (first<=last) { pos = first; @@ -308,7 +308,7 @@ g_string_trim (GString *string, gchar *chars, GStringTrimOption options) guint length; gchar *str; - CAMEL_LOG(FULL_DEBUG,"**\nentering g_string_trim::\n"); + CAMEL_LOG_FULL_DEBUG ("**\nentering g_string_trim::\n"); if ((!string) || (!string->str)) return; @@ -320,7 +320,7 @@ g_string_trim (GString *string, gchar *chars, GStringTrimOption options) first_ok = 0; last_ok = length - 1; - CAMEL_LOG (FULL_DEBUG,"g_string_trim:: trim_options:%d\n", options); + CAMEL_LOG_FULL_DEBUG ("g_string_trim:: trim_options:%d\n", options); if (options & GSTRING_TRIM_STRIP_LEADING) while ( (first_ok <= last_ok) && (strchr (chars, str[first_ok])) ) first_ok++; @@ -328,7 +328,7 @@ g_string_trim (GString *string, gchar *chars, GStringTrimOption options) if (options & GSTRING_TRIM_STRIP_TRAILING) while ( (first_ok <= last_ok) && (strchr (chars, str[last_ok])) ) last_ok++; - CAMEL_LOG (FULL_DEBUG,"g_string_trim::\n\t\"%s\":first ok:%d last_ok:%d\n", + CAMEL_LOG_FULL_DEBUG ("g_string_trim::\n\t\"%s\":first ok:%d last_ok:%d\n", string->str, first_ok, last_ok); if (first_ok > 0) diff --git a/configure.in b/configure.in index 91711cd682..975e83f867 100644 --- a/configure.in +++ b/configure.in @@ -43,22 +43,25 @@ GNOME_X_CHECKS dnl ************************************************** dnl * ORBit support dnl ************************************************** -GNOMEGNORBA_LIBS="$GNOMEGNORBA_LIBS" -AC_SUBST(GNOMEGNORBA_LIBS) +dnl GNOMEGNORBA_LIBS="$GNOMEGNORBA_LIBS" +dnl AC_SUBST(GNOMEGNORBA_LIBS) dnl ****************************** dnl Check for Bonobo dnl ****************************** -AM_PATH_BONOBO(0.1.0, [ - AC_DEFINE(HAVE_BONOBO) - have_bonobo=true -],[ - have_bonobo=false -]) -AM_CONDITIONAL(BONOBO, $have_bonobo) - - +dnl AM_PATH_BONOBO(0.1.0, [ +dnl AC_DEFINE(HAVE_BONOBO) +dnl have_bonobo=true +dnl ],[ +dnl have_bonobo=false +dnl ]) +dnl AM_CONDITIONAL(BONOBO, $have_bonobo) + +AC_ARG_WITH(camel-hard-log-level, [ --with-camel-hard-log-level=level value of log level in camel (0-10)], + camel_hard_log_level="$withval", camel_hard_log_level="0") +AC_DEFINE_UNQUOTED(CAMEL_HARD_LOG_LEVEL, $camel_hard_log_level) + AC_OUTPUT([ Makefile macros/Makefile diff --git a/devel-docs/camel/Makefile.am b/devel-docs/camel/Makefile.am index 810c5f5f7f..b32c5b9f69 100644 --- a/devel-docs/camel/Makefile.am +++ b/devel-docs/camel/Makefile.am @@ -20,7 +20,8 @@ HTML_DIR=$(datadir)/gnome/html TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE) tmpl_sources = \ - tmpl/camel-service.sgml + tmpl/camel-service.sgml \ + tmpl/camel-data-wrapper.sgml \ tmpl/camel-store.sgml @@ -50,13 +51,13 @@ scan: camel-scan.c -CFLAGS=$(CFLAGS) LDFLAGS=$(LDFLAGS) gtkdoc-scanobj --module=$(DOC_MODULE) gtkdoc-scan --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) -templates: camel-scan.c +templates: scan gtkdoc-mktmpl --module=$(DOC_MODULE) -sgml: templates +sgml: gtkdoc-mkdb --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) -html: sgml +html: if ! test -d html ; then mkdir html ; fi -cd html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE) diff --git a/devel-docs/camel/camel-docs.sgml b/devel-docs/camel/camel-docs.sgml index c91200eb2e..a510e93675 100644 --- a/devel-docs/camel/camel-docs.sgml +++ b/devel-docs/camel/camel-docs.sgml @@ -2,11 +2,12 @@ <!entity CamelFolder SYSTEM "sgml/camel-folder.sgml"> <!entity CamelService SYSTEM "sgml/camel-service.sgml"> <!entity CamelStore SYSTEM "sgml/camel-store.sgml"> +<!entity CamelDataWrapper SYSTEM "sgml/camel-data-wrapper.sgml"> ]> <book> <bookinfo> - <title>Camel Mail Library Reference Manual</title> + <title>Camel Messaging Library Reference Manual</title> </bookinfo> <chapter id="camel-objects"> @@ -14,5 +15,6 @@ &CamelFolder; &CamelService; &CamelStore; + &CamelDataWrapper; </chapter> </book> diff --git a/devel-docs/camel/camel-sections.txt b/devel-docs/camel/camel-sections.txt index f7b05529cb..81c9c205d4 100644 --- a/devel-docs/camel/camel-sections.txt +++ b/devel-docs/camel/camel-sections.txt @@ -1,6 +1,15 @@ <INCLUDE>gnome.h</INCLUDE> + +<SECTION> +<FILE>camel-data-wrapper</FILE> +CamelDataWrapper +<TITLE>CamelDataWrapper</TITLE> +camel_data_wrapper_write_to_stream +</SECTION> + + <SECTION> <FILE>camel-folder</FILE> CamelFolder @@ -41,8 +50,8 @@ CamelStore camel_store_get_separator camel_store_get_folder <SUBSECTION Standard> -CAMEL_SERVICE +CAMEL_STORE camel_store_get_type -CAMEL_SERVICE_CLASS +CAMEL_STORE_CLASS </SECTION> diff --git a/devel-docs/camel/tmpl/camel-folder.sgml b/devel-docs/camel/tmpl/camel-folder.sgml index 7996505251..882d63499c 100644 --- a/devel-docs/camel/tmpl/camel-folder.sgml +++ b/devel-docs/camel/tmpl/camel-folder.sgml @@ -2,11 +2,11 @@ CamelFolder <!-- ##### SECTION Short_Description ##### --> - +Represents a folder of messages on a store. <!-- ##### SECTION Long_Description ##### --> <para> - +CamelFolder represents a folder in a message store. </para> <!-- ##### SECTION See_Also ##### --> diff --git a/devel-docs/camel/tmpl/camel-store.sgml b/devel-docs/camel/tmpl/camel-store.sgml index 69c98e18e5..25f9cc1283 100644 --- a/devel-docs/camel/tmpl/camel-store.sgml +++ b/devel-docs/camel/tmpl/camel-store.sgml @@ -3,10 +3,13 @@ CamelStore <!-- ##### SECTION Short_Description ##### --> - +A class representing a message (local or distant) repository <!-- ##### SECTION Long_Description ##### --> <para> - +The store class models a place where messages can be stored and retreived. It can be a local +store (for example an mbox-style store) or a distant server (for example an POP3 server). Messages are +not retreived or stored directly with a CamelStore object. Instead, a CamelFolder object must be +obtained from the store first. </para> <!-- ##### SECTION See_Also ##### --> diff --git a/tests/Makefile.am b/tests/Makefile.am index 5e2fd8947c..5bfa054cbf 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,10 +6,11 @@ INCLUDES = -I$(top_srcdir)/intl -I$(top_srcdir)/camel \ LDADD = \ $(top_builddir)/camel/libcamel.la \ $(GNOME_LIBDIR) \ - $(GNOMEUI_LIBS) $(INTLLIBS) \ - $(BONOBO_LIBS) + $(GNOMEUI_LIBS) $(INTLLIBS) +# $(BONOBO_LIBS) noinst_PROGRAMS = \ test1 \ - test2 + test2 \ + test3 diff --git a/tests/test1.c b/tests/test1.c index 65d3b046c7..ecf155fcdc 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -1,43 +1,59 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ #include "camel-mime-message.h" +#include "camel-mime-body-part.h" +#include "camel-multipart.h" #include "stdio.h" #include "camel-stream.h" #include "camel-stream-fs.h" #include "camel-log.h" +#include "camel.h" -void +int main (int argc, char**argv) { CamelMimeMessage *message; + CamelMultipart *multipart; + CamelMimeBodyPart *body_part; + /* FILE *output_file; */ CamelStream *stream; gtk_init (&argc, &argv); + camel_init (); message = camel_mime_message_new_with_session( (CamelSession *)NULL); - camel_mime_part_set_description (CAMEL_MIME_PART (message), g_string_new ("a test")); - camel_mime_part_add_header (CAMEL_MIME_PART (message), g_string_new ("X-test1"), g_string_new ("the value of a test")); - camel_mime_part_add_header (CAMEL_MIME_PART (message), g_string_new ("X-test2"), g_string_new ("the value of another test")); + camel_mime_part_set_description (CAMEL_MIME_PART (message), "a test"); + camel_mime_part_add_header (CAMEL_MIME_PART (message), "X-test1", "the value of a test"); + camel_mime_part_add_header (CAMEL_MIME_PART (message), "X-test2", "the value of another test"); /*camel_mime_part_add_content_language (CAMEL_MIME_PART (message), g_string_new ("es-ca"));*/ - camel_mime_message_set_received_date (message, g_string_new ("Thu, 20 May 1999, 10:39:14 +0200")); - camel_mime_message_set_subject (message, g_string_new ("A test message")); - camel_mime_message_set_reply_to (message, g_string_new ("toto@toto.com")); - camel_mime_message_set_from (message, g_string_new ("Bertrand.Guiheneuf@inria.fr")); + camel_mime_message_set_received_date (message, "Thu, 20 May 1999, 10:39:14 +0200"); + camel_mime_message_set_subject (message, "A test message"); + camel_mime_message_set_reply_to (message, "toto@toto.com"); + camel_mime_message_set_from (message, "Bertrand.Guiheneuf@inria.fr"); - camel_mime_message_add_recipient (message, g_string_new (RECIPIENT_TYPE_TO), g_string_new ("franck.dechamps@alseve.fr")); - camel_mime_message_add_recipient (message, g_string_new (RECIPIENT_TYPE_TO), g_string_new ("mc@alseve.fr")); - camel_mime_message_add_recipient (message, g_string_new (RECIPIENT_TYPE_TO), g_string_new ("richard.lengagne@inria.fr")); - camel_mime_message_add_recipient (message, g_string_new (RECIPIENT_TYPE_CC), g_string_new ("Francois.fleuret@inria.fr")); - camel_mime_message_add_recipient (message, g_string_new (RECIPIENT_TYPE_CC), g_string_new ("maury@justmagic.com")); - camel_mime_message_add_recipient (message, g_string_new (RECIPIENT_TYPE_BCC), g_string_new ("guiheneu@aful.org")); + camel_mime_message_add_recipient (message, RECIPIENT_TYPE_TO, "franck.dechamps@alseve.fr"); + camel_mime_message_add_recipient (message, RECIPIENT_TYPE_TO, "mc@alseve.fr"); + camel_mime_message_add_recipient (message, RECIPIENT_TYPE_TO, "richard.lengagne@inria.fr"); + camel_mime_message_add_recipient (message, RECIPIENT_TYPE_CC, "Francois.fleuret@inria.fr"); + camel_mime_message_add_recipient (message, RECIPIENT_TYPE_CC, "maury@justmagic.com"); + camel_mime_message_add_recipient (message, RECIPIENT_TYPE_BCC, "Bertrand.Guiheneuf@aful.org"); + + multipart = camel_multipart_new (); + body_part = camel_mime_body_part_new (); + camel_mime_part_set_text (CAMEL_MIME_PART (body_part), "This is a test.\nThis is only a test.\n"); + camel_multipart_add_part (multipart, body_part); + camel_mime_part_set_content_object (CAMEL_MIME_PART (message), CAMEL_DATA_WRAPPER (multipart)); - stream = camel_stream_fs_new_with_name (g_string_new ("mail1.test"), CAMEL_STREAM_FS_WRITE ); + stream = camel_stream_fs_new_with_name ("mail1.test", CAMEL_STREAM_FS_WRITE ); if (!stream) { - CAMEL_LOG(WARNING, "could not open output file"); + CAMEL_LOG_FULL_DEBUG ("could not open output file"); exit(2); } camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), stream); camel_stream_close (stream); + + printf ("Test1 finished\n"); } + diff --git a/tests/test2.c b/tests/test2.c index 03f03a105c..154a243007 100644 --- a/tests/test2.c +++ b/tests/test2.c @@ -7,6 +7,7 @@ #include "camel-mime-part.h" #include "camel-stream.h" #include "camel-stream-fs.h" +#include "camel.h" void main (int argc, char**argv) @@ -16,22 +17,23 @@ main (int argc, char**argv) CamelStream *input_stream, *output_stream; gtk_init (&argc, &argv); - camel_debug_level = FULL_DEBUG; + camel_init (); + camel_debug_level = CAMEL_LOG_LEVEL_FULL_DEBUG; message = camel_mime_message_new_with_session( (CamelSession *)NULL); - input_stream = camel_stream_fs_new_with_name (g_string_new ("mail.test"), CAMEL_STREAM_FS_READ); + input_stream = camel_stream_fs_new_with_name ("mail.test", CAMEL_STREAM_FS_READ); if (!input_stream) { - perror("could not open input file"); + perror ("could not open input file"); + printf ("You must create the file mail.test before running this test"); exit(2); } - camel_data_wrapper_construct_from_stream ( CAMEL_DATA_WRAPPER (message), input_stream); camel_stream_close (input_stream); - output_stream = camel_stream_fs_new_with_name (g_string_new ("mail2.test"), CAMEL_STREAM_FS_WRITE); + output_stream = camel_stream_fs_new_with_name ("mail2.test", CAMEL_STREAM_FS_WRITE); camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), output_stream); camel_stream_close (output_stream); |