diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | camel/camel-mime-message.c | 123 | ||||
-rw-r--r-- | camel/camel-mime-message.h | 12 | ||||
-rw-r--r-- | camel/camel-mime-part.c | 2 | ||||
-rw-r--r-- | camel/camel-recipient.c | 75 | ||||
-rw-r--r-- | camel/camel-recipient.h | 21 | ||||
-rw-r--r-- | camel/gmime-content-field.c | 5 |
7 files changed, 137 insertions, 112 deletions
@@ -1,8 +1,16 @@ 1999-09-01 bertrand <Bertrand.Guiheneuf@aful.org> + * camel/camel-mime-message.c (_finalize): + (_add_recipient): + (_remove_recipient): + (_get_recipients): now use CamelRecipientTable + + * camel/gmime-content-field.c: + (gmime_content_field_unref): test if object + to free is non void. + * camel/camel-folder.c (_finalize): (_set_name): - * camel/camel-mime-message.c (_finalize): * camel/camel-mime-part.c (_finalize): (_set_description): (_set_disposition): @@ -10,6 +18,7 @@ * camel/camel-stream-fs.c (_finalize): * camel/gmime-content-field.c: (gmime_content_field_construct_from_string): + * camel/url-util.c (g_url_free): When using g_free (obj) don't test if obj != NULL diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c index 9ccf2fc9e4..f26db4b358 100644 --- a/camel/camel-mime-message.c +++ b/camel/camel-mime-message.c @@ -61,7 +61,7 @@ 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 _add_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const 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, const gchar *flag, gboolean value); @@ -141,7 +141,7 @@ 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_strcase_hash, g_strcase_equal); + camel_mime_message->recipients = camel_recipient_table_new (); camel_mime_message->flags = g_hash_table_new (g_strcase_hash, g_strcase_equal); camel_mime_message->received_date = NULL; @@ -190,7 +190,7 @@ _finalize (GtkObject *object) g_free (message->reply_to); g_free (message->from); -#warning free recipients. + if (message->recipients) camel_recipient_table_unref (message->recipients); if (message->folder) gtk_object_unref (GTK_OBJECT (message->folder)); if (message->session) gtk_object_unref (GTK_OBJECT (message->session)); @@ -389,45 +389,27 @@ camel_mime_message_get_from (CamelMimeMessage *mime_message) + +/* **** */ + + + + + static void -_add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient) +_add_recipient (CamelMimeMessage *mime_message, + const gchar *recipient_type, + const gchar *recipient) { - /* be careful, recipient_type and recipient may be freed within this func */ - GList *recipients_list; - GList *existent_list; - - /* see if there is already a list for this recipient type */ - 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, string_equal_for_glist) ) { - g_free (recipient_type); - g_free (recipient); - return; - } - /* append the new recipient to the recipient list - if the existent_list is NULL, then a new GList is - automagically created */ - recipients_list = g_list_append (existent_list, (gpointer)recipient); - - 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_free (recipient_type); -} - - -/** - * add_recipient: - * @mime_message: - * @recipient_type: - * @recipient: - * - * Have to write the doc. IMPORTANT : @recipient_type and - * @recipient may be freed within this func - **/ + camel_recipient_table_add (mime_message->recipients, recipient_type, recipient); +} + + + void -camel_mime_message_add_recipient (CamelMimeMessage *mime_message, gchar *recipient_type, gchar *recipient) +camel_mime_message_add_recipient (CamelMimeMessage *mime_message, + const gchar *recipient_type, + const gchar *recipient) { g_assert (mime_message); g_return_if_fail (_check_not_expunged (mime_message)); @@ -435,50 +417,19 @@ camel_mime_message_add_recipient (CamelMimeMessage *mime_message, gchar *recipie } -/** - * _remove_recipient: remove a recipient from the list of recipients - * @mime_message: the message - * @recipient_type: recipient type from which the recipient should be removed - * @recipient: recipient to remove - * - * Be careful, recipient and recipient_type are not freed. - * calling programns must free them themselves. They can free - * them just after remove_recipient returns. - **/ static void -_remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient) +_remove_recipient (CamelMimeMessage *mime_message, + const gchar *recipient_type, + const gchar *recipient) { - GList *recipients_list; - GList *new_recipients_list; - GList *old_element; - gchar *old_recipient_type; - - /* if the recipient type section does not exist, do nothing */ - if (! g_hash_table_lookup_extended (mime_message->recipients, - recipient_type, - (gpointer)&(old_recipient_type), - (gpointer)&(recipients_list)) - ) return; - - /* look for the recipient to remove */ - /* 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); - - /* if glist head has changed, fix up hash table */ - if (new_recipients_list != recipients_list) - g_hash_table_insert (mime_message->recipients, old_recipient_type, new_recipients_list); - - g_free( (gchar *)(old_element->data)); - g_list_free_1 (old_element); - } + camel_recipient_table_remove (mime_message->recipients, recipient_type, recipient); } void -camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const gchar *recipient) +camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, + const gchar *recipient_type, + const gchar *recipient) { g_assert (mime_message); g_return_if_fail (_check_not_expunged (mime_message)); @@ -487,13 +438,16 @@ camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, const gchar static const GList * -_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type) +_get_recipients (CamelMimeMessage *mime_message, + const gchar *recipient_type) { - return (GList *)g_hash_table_lookup (mime_message->recipients, recipient_type); + return camel_recipient_table_get (mime_message->recipients, recipient_type); } + const GList * -camel_mime_message_get_recipients (CamelMimeMessage *mime_message, const gchar *recipient_type) +camel_mime_message_get_recipients (CamelMimeMessage *mime_message, + const gchar *recipient_type) { g_assert (mime_message); g_return_val_if_fail (_check_not_expunged (mime_message), NULL); @@ -501,6 +455,11 @@ camel_mime_message_get_recipients (CamelMimeMessage *mime_message, const gchar * } + +/* **** */ + + + static void _set_flag (CamelMimeMessage *mime_message, const gchar *flag, gboolean value) { @@ -617,7 +576,7 @@ _write_one_recipient_to_stream (gpointer key, gpointer value, gpointer user_data static void _write_recipients_to_stream (CamelMimeMessage *mime_message, CamelStream *stream) { - g_hash_table_foreach (mime_message->recipients, _write_one_recipient_to_stream, (gpointer)stream); + //g_hash_table_foreach (mime_message->recipients, _write_one_recipient_to_stream, (gpointer)stream); } static void @@ -650,7 +609,7 @@ _set_recipient_list_from_string (CamelMimeMessage *message, gchar *recipient_typ recipients_list = string_split ( recipients_string, ',', "\t ", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING); - g_hash_table_insert (message->recipients, recipient_type, recipients_list); + camel_recipient_table_add_list (message->recipients, recipient_type, recipients_list); } diff --git a/camel/camel-mime-message.h b/camel/camel-mime-message.h index 5f12c70e81..15238782e5 100644 --- a/camel/camel-mime-message.h +++ b/camel/camel-mime-message.h @@ -37,6 +37,7 @@ typedef struct _CamelMimeMessage CamelMimeMessage; #include "camel-mime-part.h" #include "camel-folder.h" #include "camel-session.h" +#include "camel-recipient.h" #define RECIPIENT_TYPE_TO "To" @@ -63,11 +64,8 @@ struct _CamelMimeMessage gchar *reply_to; gchar *from; - GHashTable *recipients; - /* -> each value is a GList of address strings */ - /* each key is a recipient type string in lower-case */ - /* FIXME: these should be relaced by dedicated structure */ - + CamelRecipientTable *recipients; + /* other fields */ GHashTable *flags; /* boolean values */ gboolean expunged; @@ -93,7 +91,7 @@ typedef struct { 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 (*add_recipient) (CamelMimeMessage *mime_message, const gchar *recipient_type, const 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, const gchar *flag, gboolean value); @@ -123,7 +121,7 @@ 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_add_recipient (CamelMimeMessage *mime_message, const gchar *recipient_type, const 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); diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index 1068651da5..99ba85bfa0 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -287,7 +287,7 @@ _set_disposition (CamelMimePart *mime_part, const gchar *disposition) #warning Do not use MimeContentfield here !!! if (mime_part->disposition) g_free ((mime_part->disposition)->type); - g_free(mime_part->disposition); + g_free (mime_part->disposition); mime_part->disposition = g_new0 (GMimeContentField,1); (mime_part->disposition)->type = g_strdup (disposition); diff --git a/camel/camel-recipient.c b/camel/camel-recipient.c index 5db7420b94..b73152c238 100644 --- a/camel/camel-recipient.c +++ b/camel/camel-recipient.c @@ -28,7 +28,7 @@ CamelRecipientTable * -camel_recipient_new () +camel_recipient_table_new () { CamelRecipientTable *recipient_table; @@ -40,7 +40,7 @@ camel_recipient_new () void -camel_recipient_ref (CamelRecipientTable *recipient_table) +camel_recipient_table_ref (CamelRecipientTable *recipient_table) { g_return_if_fail (recipient_table); recipient_table->ref_count += 1; @@ -64,7 +64,7 @@ _free_recipient_list (gpointer key, gpointer value, gpointer user_data) } void -camel_recipient_free (CamelRecipientTable *recipient_table) +camel_recipient_table_free (CamelRecipientTable *recipient_table) { g_return_if_fail (recipient_table); @@ -77,21 +77,29 @@ camel_recipient_free (CamelRecipientTable *recipient_table) void -camel_recipient_unref (CamelRecipientTable *recipient_table) +camel_recipient_table_unref (CamelRecipientTable *recipient_table) { g_return_if_fail (recipient_table); recipient_table->ref_count -= 1; if (recipient_table->ref_count <1) - camel_recipient_free (recipient_table); + camel_recipient_table_free (recipient_table); } +/** + * camel_recipient_table_add: + * @recipient_table: + * @recipient_type: + * @recipient: + * + * + **/ void -camel_recipient_add (CamelRecipientTable *recipient_table, - const gchar *recipient_type, - const gchar *recipient) +camel_recipient_table_add (CamelRecipientTable *recipient_table, + const gchar *recipient_type, + const gchar *recipient) { GList *recipients_list; GList *existent_list; @@ -103,22 +111,49 @@ camel_recipient_add (CamelRecipientTable *recipient_table, /* append the new recipient to the recipient list if the existent_list is NULL, then a new GList is automagically created */ - recipients_list = g_list_append (existent_list, (gpointer)recipient); + recipients_list = g_list_append (existent_list, (gpointer)g_strdup (recipient)); if (!existent_list) /* if there was no recipient of this type create the section */ - g_hash_table_insert (recipient_table->recipient_hash_table, recipient_type, recipients_list); - else - g_free (recipient_type); + g_hash_table_insert (recipient_table->recipient_hash_table, g_strdup (recipient_type), recipients_list); + + +} + +/** + * camel_recipient_table_add_list: + * @recipient_table: + * @recipient_type: + * @recipient_list: + * + * be careful, that the list is used as is, and its element + * will be freed by camel_recipient_table_unref + **/ +void +camel_recipient_table_add_list (CamelRecipientTable *recipient_table, + const gchar *recipient_type, + GList *recipient_list) +{ + GList *recipients_list; + GList *existent_list; + + /* see if there is already a list for this recipient type */ + existent_list = (GList *)g_hash_table_lookup (recipient_table->recipient_hash_table, recipient_type); + + + if (existent_list) + g_list_concat (existent_list, recipient_type); + else + g_hash_table_insert (recipient_table->recipient_hash_table, g_strdup (recipient_type), recipients_list); } -static void -camel_recipient_remove (CamelRecipientTable *recipient_table, - const gchar *recipient_type, - const gchar *recipient) +void +camel_recipient_table_remove (CamelRecipientTable *recipient_table, + const gchar *recipient_type, + const gchar *recipient) { GList *recipients_list; GList *new_recipients_list; @@ -133,8 +168,8 @@ camel_recipient_remove (CamelRecipientTable *recipient_table, ) return; /* look for the recipient to remove */ - /* g_list_find_custom does use "const" for recipient, is it a mistake ? */ - old_element = g_list_find_custom (recipients_list, recipient, g_strcase_equal); + /* g_list_find_custom , use gpointer instead of gconstpointer */ + old_element = g_list_find_custom (recipients_list, (gpointer)recipient, g_strcase_equal); if (old_element) { /* if recipient exists, remove it */ new_recipients_list = g_list_remove_link (recipients_list, old_element); @@ -151,8 +186,8 @@ camel_recipient_remove (CamelRecipientTable *recipient_table, const GList * -camel_recipient_get (CamelRecipientTable *recipient_table, - const gchar *recipient_type) +camel_recipient_table_get (CamelRecipientTable *recipient_table, + const gchar *recipient_type) { return (const GList *)g_hash_table_lookup (recipient_table->recipient_hash_table, recipient_type); } diff --git a/camel/camel-recipient.h b/camel/camel-recipient.h index 6b07d84478..447cf5f10e 100644 --- a/camel/camel-recipient.h +++ b/camel/camel-recipient.h @@ -32,6 +32,8 @@ extern "C" { #pragma } #endif /* __cplusplus }*/ +#include <glib.h> + typedef struct { @@ -43,7 +45,26 @@ typedef struct { +CamelRecipientTable *camel_recipient_table_new (); + +void camel_recipient_table_ref (CamelRecipientTable *recipient_table); + +void camel_recipient_table_unref (CamelRecipientTable *recipient_table); + +void camel_recipient_table_add (CamelRecipientTable *recipient_table, + const gchar *recipient_type, + const gchar *recipient); + +void camel_recipient_table_add_list (CamelRecipientTable *recipient_table, + const gchar *recipient_type, + GList *recipient_list); + +void camel_recipient_table_remove (CamelRecipientTable *recipient_table, + const gchar *recipient_type, + const gchar *recipient); +const GList *camel_recipient_table_get (CamelRecipientTable *recipient_table, + const gchar *recipient_type); diff --git a/camel/gmime-content-field.c b/camel/gmime-content-field.c index d838c5c8de..536d15e82a 100644 --- a/camel/gmime-content-field.c +++ b/camel/gmime-content-field.c @@ -74,7 +74,8 @@ _free_parameter (gpointer name, gpointer value, gpointer user_data) void gmime_content_field_free (GMimeContentField *content_field) { - g_assert (content_field); + if (!content_field) return; + g_hash_table_foreach (content_field->parameters, _free_parameter, NULL); g_free (content_field->type); g_free (content_field->subtype); @@ -110,6 +111,8 @@ gmime_content_field_ref (GMimeContentField *content_field) void gmime_content_field_unref (GMimeContentField *content_field) { + if (!content_field) return; + content_field->ref -= 1; if (content_field->ref <= 0) gmime_content_field_free (content_field); |