From 19e94482677c45f538c716e1d4604fd5f0b3682e Mon Sep 17 00:00:00 2001 From: NotZed Date: Fri, 28 Apr 2000 03:06:44 +0000 Subject: Dont try and check a NULL header. 2000-04-27 NotZed * camel-mime-utils.c (check_header): Dont try and check a NULL header. * camel-recipient.[ch]: Dead. Its not pining. * camel-mime-message.h: Dont include recipients.h anymore. * camel-mime-message.c (camel_mime_message_add_recipient): Accept name/address separately, and store in an CamelInternetAddress. (add_recipient): Removed. (remove_recipient): Removed. (remove_recipient_address): Renamed from remove_receipient, works via address. (camel_mime_message_remove_recipient_name): New function to remove by name. (get_recipients): Removed. (camel_mime_message_get_recipients): Return a camel-internet-address. (write_to_stream): No longer write receipients directly. (write_recipients_to_stream): Removed. (write_one_recipient_to_stream): Removed. (camel_mime_message_init): Setup recipients hashtable, rather than usign the recipients stuff. (set_recipient_list_from_string): Killed, a violent and lengthy death. (process_header): Simplified recipient handling code a lot. (received_date_str, sent_date_str, reply_to_str, subject_str, from_str): Removed some oddly-defined global statics. (camel_mime_message_class_init): Dont initialise above variables anymore. (init_header_name_table): Removed, use a table to init this, and do it in class init (2 lines of code ...). * camel-news-address.c: Class to represent news addresses - currently empty, and not built. * camel-internet-address.h: Class to represent internet (email) addresses. * camel-address.h: Abstract class to represent (lists of) addresses. svn path=/trunk/; revision=2671 --- camel/ChangeLog | 32 +++++ camel/Makefile.am | 2 - camel/camel-internet-address.c | 2 +- camel/camel-mime-message.c | 258 ++++++++++++++++------------------- camel/camel-mime-message.h | 24 ++-- camel/camel-mime-part.c | 8 +- camel/camel-mime-part.h | 12 +- camel/camel-mime-utils.c | 2 +- camel/camel-recipient.c | 303 ----------------------------------------- camel/camel-recipient.h | 88 ------------ camel/camel.h | 1 - 11 files changed, 176 insertions(+), 556 deletions(-) delete mode 100644 camel/camel-recipient.c delete mode 100644 camel/camel-recipient.h diff --git a/camel/ChangeLog b/camel/ChangeLog index ff11d0e06d..e6d7a081a3 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,5 +1,37 @@ 2000-04-27 NotZed + * camel-mime-utils.c (check_header): Dont try and check a NULL + header. + + * camel-recipient.[ch]: Dead. Its not pining. + + * camel-mime-message.h: Dont include recipients.h anymore. + + * camel-mime-message.c (camel_mime_message_add_recipient): Accept + name/address separately, and store in an CamelInternetAddress. + (add_recipient): Removed. + (remove_recipient): Removed. + (remove_recipient_address): Renamed from remove_receipient, works + via address. + (camel_mime_message_remove_recipient_name): New function to remove + by name. + (get_recipients): Removed. + (camel_mime_message_get_recipients): Return a camel-internet-address. + (write_to_stream): No longer write receipients directly. + (write_recipients_to_stream): Removed. + (write_one_recipient_to_stream): Removed. + (camel_mime_message_init): Setup recipients hashtable, rather than + usign the recipients stuff. + (set_recipient_list_from_string): Killed, a violent and lengthy + death. + (process_header): Simplified recipient handling code a lot. + (received_date_str, sent_date_str, reply_to_str, subject_str, + from_str): Removed some oddly-defined global statics. + (camel_mime_message_class_init): Dont initialise above variables + anymore. + (init_header_name_table): Removed, use a table to init this, and + do it in class init (2 lines of code ...). + * camel-news-address.c: Class to represent news addresses - currently empty, and not built. diff --git a/camel/Makefile.am b/camel/Makefile.am index de66c39d2c..288eb72023 100644 --- a/camel/Makefile.am +++ b/camel/Makefile.am @@ -45,7 +45,6 @@ libcamel_la_SOURCES = \ camel-multipart.c \ camel-op-queue.c \ camel-provider.c \ - camel-recipient.c \ camel-seekable-stream.c \ camel-seekable-substream.c \ camel-service.c \ @@ -89,7 +88,6 @@ libcamelinclude_HEADERS = \ camel-multipart.h \ camel-op-queue.h \ camel-provider.h \ - camel-recipient.h \ camel-seekable-stream.h \ camel-seekable-substream.h \ camel-service.h \ diff --git a/camel/camel-internet-address.c b/camel/camel-internet-address.c index 451a83ddc4..08fb6dfa30 100644 --- a/camel/camel-internet-address.c +++ b/camel/camel-internet-address.c @@ -135,8 +135,8 @@ static char * internet_encode (CamelAddress *a) } g_string_sprintfa(out, "<%s>", addr->address); } - g_string_free(out, FALSE); ret = out->str; + g_string_free(out, FALSE); return ret; } diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c index 60a518acec..39da00593a 100644 --- a/camel/camel-mime-message.c +++ b/camel/camel-mime-message.c @@ -33,6 +33,7 @@ #define d(x) +/* these 2 below should be kept in sync */ typedef enum { HEADER_UNKNOWN, HEADER_FROM, @@ -44,20 +45,20 @@ typedef enum { HEADER_DATE } CamelHeaderType; +static char *header_names[] = { + /* dont include HEADER_UNKNOWN string */ + "From", "Reply-To", "Subject", "To", "Cc", "Bcc", "Date", NULL +}; + static GHashTable *header_name_table; static CamelMimePartClass *parent_class=NULL; -/* WTF are these for?? */ -static gchar *received_date_str; -static gchar *sent_date_str; -static gchar *reply_to_str; -static gchar *subject_str; -static gchar *from_str; +static char *recipient_names[] = { + "To", "Cc", "Bcc", NULL +}; + -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); static gboolean get_flag (CamelMimeMessage *mime_message, const gchar *flag); static GList *get_flag_list (CamelMimeMessage *mime_message); @@ -75,20 +76,6 @@ static int construct_from_parser (CamelMimePart *, CamelMimeParser *); #define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (GTK_OBJECT(so)->klass) #define CMD_CLASS(so) CAMEL_MEDIUM_CLASS (GTK_OBJECT(so)->klass) - -static void -init_header_name_table() -{ - 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); - g_hash_table_insert (header_name_table, "Date", (gpointer)HEADER_DATE); -} - static void camel_mime_message_class_init (CamelMimeMessageClass *camel_mime_message_class) { @@ -96,20 +83,15 @@ camel_mime_message_class_init (CamelMimeMessageClass *camel_mime_message_class) CamelMimePartClass *camel_mime_part_class = CAMEL_MIME_PART_CLASS (camel_mime_message_class); GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_mime_message_class); CamelMediumClass *camel_medium_class = CAMEL_MEDIUM_CLASS (camel_mime_message_class); + int i; parent_class = gtk_type_class (camel_mime_part_get_type ()); - init_header_name_table(); - - received_date_str = ""; - sent_date_str = ""; - reply_to_str = "Reply-To"; - subject_str = "Subject"; - from_str = "From"; - + + header_name_table = g_hash_table_new (g_str_hash, g_str_equal); + for (i=0;header_names[i];i++) + g_hash_table_insert (header_name_table, header_names[i], (gpointer)i+1); + /* virtual method definition */ - camel_mime_message_class->add_recipient = add_recipient; - camel_mime_message_class->remove_recipient = remove_recipient; - camel_mime_message_class->get_recipients = get_recipients; camel_mime_message_class->set_flag = set_flag; camel_mime_message_class->get_flag = get_flag; camel_mime_message_class->get_flag_list = get_flag_list; @@ -134,22 +116,25 @@ camel_mime_message_class_init (CamelMimeMessageClass *camel_mime_message_class) static void camel_mime_message_init (gpointer object, gpointer klass) { - CamelMimeMessage *camel_mime_message = CAMEL_MIME_MESSAGE (object); + CamelMimeMessage *mime_message = (CamelMimeMessage *)object; + int i; - camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (object), - "message/rfc822"); + camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (object), "message/rfc822"); + + mime_message->recipients = g_hash_table_new(g_strcase_hash, g_strcase_equal); + for (i=0;recipient_names[i];i++) { + g_hash_table_insert(mime_message->recipients, recipient_names[i], camel_internet_address_new()); + } - camel_mime_message->recipients = camel_recipient_table_new (); - camel_mime_message->flags = - g_hash_table_new (g_strcase_hash, g_strcase_equal); + mime_message->flags = g_hash_table_new (g_strcase_hash, g_strcase_equal); - camel_mime_message->subject = NULL; - camel_mime_message->reply_to = NULL; - camel_mime_message->from = NULL; - camel_mime_message->folder = NULL; - camel_mime_message->date = CAMEL_MESSAGE_DATE_CURRENT; - camel_mime_message->date_offset = 0; - camel_mime_message->date_str = NULL; + mime_message->subject = NULL; + mime_message->reply_to = NULL; + mime_message->from = NULL; + mime_message->folder = NULL; + mime_message->date = CAMEL_MESSAGE_DATE_CURRENT; + mime_message->date_offset = 0; + mime_message->date_str = NULL; } GtkType @@ -176,6 +161,12 @@ camel_mime_message_get_type (void) return camel_mime_message_type; } +/* annoying way to free objects in a hashtable, i mean, its not like anyone + would want to store them in a hashtable, really */ +static void g_lib_is_uber_crappy_shit(gpointer whocares, gpointer getlost, gpointer blah) +{ + gtk_object_unref((GtkObject *)getlost); +} static void finalize (GtkObject *object) @@ -187,8 +178,10 @@ finalize (GtkObject *object) g_free (message->reply_to); g_free (message->from); - if (message->recipients) camel_recipient_table_unref (message->recipients); - if (message->folder) gtk_object_unref (GTK_OBJECT (message->folder)); + g_hash_table_foreach (message->recipients, g_lib_is_uber_crappy_shit, NULL); + + if (message->folder) + gtk_object_unref (GTK_OBJECT (message->folder)); if (message->flags) g_hash_table_foreach (message->flags, g_hash_table_generic_free, NULL); @@ -321,62 +314,98 @@ camel_mime_message_get_from (CamelMimeMessage *mime_message) /* **** */ -static void -add_recipient (CamelMimeMessage *mime_message, - const gchar *recipient_type, - const gchar *recipient) +void +camel_mime_message_add_recipient (CamelMimeMessage *mime_message, + const gchar *type, + const gchar *name, const char *address) { - camel_recipient_table_add (mime_message->recipients, recipient_type, recipient); -} + CamelInternetAddress *addr; + char *text; + + g_assert (mime_message); + addr = g_hash_table_lookup(mime_message->recipients, type); + if (addr == NULL) { + g_warning("trying to add a non-valid receipient type: %s = %s %s", type, name, address); + return; + } + camel_internet_address_add(addr, name, address); + + /* FIXME: maybe this should be delayed till we're ready to write out? */ + text = camel_address_encode((CamelAddress*)addr); + CAMEL_MEDIUM_CLASS(parent_class)->set_header((CamelMedium *)mime_message, type, text); + g_free(text); +} void -camel_mime_message_add_recipient (CamelMimeMessage *mime_message, - const gchar *recipient_type, - const gchar *recipient) +camel_mime_message_remove_recipient_address (CamelMimeMessage *mime_message, + const gchar *type, + const gchar *address) { + CamelInternetAddress *addr; + int index; + char *text; + + g_assert (mime_message); - g_return_if_fail (!mime_message->expunged); - CMM_CLASS (mime_message)->add_recipient (mime_message, recipient_type, recipient); -} + addr = g_hash_table_lookup(mime_message->recipients, type); + if (addr == NULL) { + g_warning("trying to remove a non-valid receipient type: %s = %s", type, address); + return; + } + index = camel_internet_address_find_address(addr, address, NULL); + if (index == -1) { + g_warning("trying to remove address for nonexistand address: %s", address); + return; + } -static void -remove_recipient (CamelMimeMessage *mime_message, - const gchar *recipient_type, - const gchar *recipient) -{ - camel_recipient_table_remove (mime_message->recipients, recipient_type, recipient); -} + camel_address_remove((CamelAddress *)addr, index); + /* FIXME: maybe this should be delayed till we're ready to write out? */ + text = camel_address_encode((CamelAddress *)addr); + CAMEL_MEDIUM_CLASS(parent_class)->set_header((CamelMedium *)mime_message, type, text); + g_free(text); +} void -camel_mime_message_remove_recipient (CamelMimeMessage *mime_message, - const gchar *recipient_type, - const gchar *recipient) +camel_mime_message_remove_recipient_name (CamelMimeMessage *mime_message, + const gchar *type, + const gchar *name) { + CamelInternetAddress *addr; + int index; + char *text; + g_assert (mime_message); - g_return_if_fail (!mime_message->expunged); - CMM_CLASS (mime_message)->remove_recipient (mime_message, recipient_type, recipient); -} + addr = g_hash_table_lookup(mime_message->recipients, type); + if (addr == NULL) { + g_warning("trying to remove a non-valid receipient type: %s = %s", type, name); + return; + } + index = camel_internet_address_find_name(addr, name, NULL); + if (index == -1) { + g_warning("trying to remove address for nonexistand name: %s", name); + return; + } -static const GList * -get_recipients (CamelMimeMessage *mime_message, - const gchar *recipient_type) -{ - return camel_recipient_table_get (mime_message->recipients, recipient_type); -} + camel_address_remove((CamelAddress *)addr, index); + /* FIXME: maybe this should be delayed till we're ready to write out? */ + text = camel_address_encode((CamelAddress *)addr); + CAMEL_MEDIUM_CLASS(parent_class)->set_header((CamelMedium *)mime_message, type, text); + g_free(text); +} -const GList * +const CamelInternetAddress * camel_mime_message_get_recipients (CamelMimeMessage *mime_message, - const gchar *recipient_type) + const gchar *type) { g_assert (mime_message); - g_return_val_if_fail (!mime_message->expunged, NULL); - return CMM_CLASS (mime_message)->get_recipients (mime_message, recipient_type); + + return g_hash_table_lookup(mime_message->recipients, type); } @@ -511,25 +540,6 @@ construct_from_parser(CamelMimePart *dw, CamelMimeParser *mp) return 0; } -static void -write_one_recipient_to_stream (gchar *recipient_type, - GList *recipient_list, - gpointer user_data) -{ - - CamelStream *stream = (CamelStream *)user_data; - if (recipient_type) - gmime_write_header_with_glist_to_stream (stream, recipient_type, recipient_list, ", "); -} - -static void -write_recipients_to_stream (CamelMimeMessage *mime_message, CamelStream *stream) -{ - camel_recipient_foreach_recipient_type (mime_message->recipients, - write_one_recipient_to_stream, - (gpointer)stream); -} - static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { @@ -549,41 +559,20 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) camel_mime_message_set_subject(mm, "No Subject"); } - camel_medium_set_header((CamelMedium *)mm, "Mime-Version", "1.0"); + /* FIXME: "To" header needs to be set explcitly as well ... */ -#if 1 -#warning need to store receipients lists to headers - /* FIXME: remove this snot ... */ - write_recipients_to_stream (mm, stream); -#endif + camel_medium_set_header((CamelMedium *)mm, "Mime-Version", "1.0"); return CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_stream (data_wrapper, stream); } -/*******************************/ -/* mime message header parsing */ - -/* FIXME: This is totally totally broken */ -static void -set_recipient_list_from_string (CamelMimeMessage *message, const char *recipient_type, const char *recipients_string) -{ - GList *recipients_list; - -#warning need to parse receipient lists properly - BROKEN!!! - recipients_list = string_split ( - recipients_string, ',', "\t ", - STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING); - - camel_recipient_table_add_list (message->recipients, recipient_type, recipients_list); - -} - /* FIXME: check format of fields. */ static gboolean process_header(CamelMedium *medium, const char *header_name, const char *header_value) { CamelHeaderType header_type; CamelMimeMessage *message = CAMEL_MIME_MESSAGE (medium); + CamelInternetAddress *addr; header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, header_name); switch (header_type) { @@ -600,22 +589,13 @@ process_header(CamelMedium *medium, const char *header_name, const char *header_ message->subject = header_decode_string(header_value); break; case HEADER_TO: - if (header_value) - set_recipient_list_from_string (message, "To", header_value); - else - camel_recipient_table_remove_type (message->recipients, "To"); - break; case HEADER_CC: - if (header_value) - set_recipient_list_from_string (message, "Cc", header_value); - else - camel_recipient_table_remove_type (message->recipients, "Cc"); - break; case HEADER_BCC: + addr = g_hash_table_lookup(message->recipients, header_name); if (header_value) - set_recipient_list_from_string (message, "Bcc", header_value); + camel_address_decode((CamelAddress *)addr, header_value); else - camel_recipient_table_remove_type (message->recipients, "Bcc"); + camel_address_remove((CamelAddress *)addr, -1); break; case HEADER_DATE: g_free(message->date_str); diff --git a/camel/camel-mime-message.h b/camel/camel-mime-message.h index 7142d876de..141747e3cb 100644 --- a/camel/camel-mime-message.h +++ b/camel/camel-mime-message.h @@ -37,8 +37,8 @@ extern "C" { #include #include #include -#include #include +#include #define CAMEL_RECIPIENT_TYPE_TO "To" #define CAMEL_RECIPIENT_TYPE_CC "Cc" @@ -67,7 +67,8 @@ struct _CamelMimeMessage gchar *reply_to; gchar *from; - CamelRecipientTable *recipients; + + GHashTable *recipients; /* hash table of CamelInternetAddress's */ /* other fields */ GHashTable *flags; /* boolean values */ @@ -145,14 +146,17 @@ void camel_mime_message_set_from (CamelMimeMessage *mi const gchar *from); const gchar * camel_mime_message_get_from (CamelMimeMessage *mime_message); -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); + +void camel_mime_message_add_recipient (CamelMimeMessage *mime_message, + const char *type, const char *name, const char *address); +void camel_mime_message_remove_recipient_address (CamelMimeMessage *mime_message, + const char *type, const char *address); +void camel_mime_message_remove_recipient_name (CamelMimeMessage *mime_message, + const char *type, const char *name); + +const CamelInternetAddress *camel_mime_message_get_recipients (CamelMimeMessage *mime_message, + const char *type); + void camel_mime_message_set_flag (CamelMimeMessage *mime_message, const gchar *flag, diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index 6e2276df90..1d885991b8 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */ /* camelMimePart.c : Abstract class for a mime_part */ /* @@ -654,8 +654,8 @@ camel_mime_part_new (void) **/ void camel_mime_part_set_content (CamelMimePart *camel_mime_part, - const gchar *data, guint length, - const gchar *type) + const char *data, int length, + const char *type) /* why on earth is the type last? */ { CamelMedium *medium = CAMEL_MEDIUM (camel_mime_part); @@ -670,7 +670,7 @@ camel_mime_part_set_content (CamelMimePart *camel_mime_part, camel_medium_set_content_object (medium, dw); } else { if (medium->content) - gtk_object_unref (GTK_OBJECT (medium->content)); + gtk_object_unref ( (GtkObject *)medium->content); medium->content = NULL; } } diff --git a/camel/camel-mime-part.h b/camel/camel-mime-part.h index cfced58723..b2c87b8f9f 100644 --- a/camel/camel-mime-part.h +++ b/camel/camel-mime-part.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */ /* camel-mime-part.h : class for a mime part */ /* @@ -88,6 +88,8 @@ typedef struct _CamelMimePartClass { GtkType camel_mime_part_get_type (void); /* public methods */ +CamelMimePart * camel_mime_part_new (void); + void camel_mime_part_set_description (CamelMimePart *mime_part, const gchar *description); const gchar *camel_mime_part_get_description (CamelMimePart *mime_part); @@ -120,12 +122,8 @@ CamelMimePartEncodingType camel_mime_part_encoding_from_string (const gchar *str int camel_mime_part_construct_from_parser (CamelMimePart *, CamelMimeParser *); /* utility functions */ -CamelMimePart * camel_mime_part_new (void); -void camel_mime_part_set_content (CamelMimePart *camel_mime_part, - const gchar *content, - guint length, - const gchar *type); - +void camel_mime_part_set_content (CamelMimePart *camel_mime_part, + const char *content, int length, const char *type); #ifdef __cplusplus } diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index fe1e7d51d8..7967ff8e45 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -1966,7 +1966,7 @@ check_header(struct _header_raw *h) unsigned char *p; p = h->value; - while (*p) { + while (p && *p) { if (!isascii(*p)) { g_warning("Appending header violates rfc: %s: %s", h->name, h->value); return; diff --git a/camel/camel-recipient.c b/camel/camel-recipient.c deleted file mode 100644 index 0ed028763b..0000000000 --- a/camel/camel-recipient.c +++ /dev/null @@ -1,303 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-recipient.h : handle recipients (addresses) and recipiemt lists */ - -/* - * - * Authors: Bertrand Guiheneuf - * Michael Zucchi - * - * Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - - -#include "glib.h" -#include "hash-table-utils.h" -#include "camel-recipient.h" - - -/** - * camel_recipient_table_new: Create a new recipient table object - * - * - * creates a new recipient table object. A recipient table - * objects merely associates a recipient list (GList) to - * recipient types (as for example "To", "Cc" for mime - * maile messages - * - * Return value: the newly created recipient table object - **/ -CamelRecipientTable * -camel_recipient_table_new () -{ - CamelRecipientTable *recipient_table; - - recipient_table = g_new0 (CamelRecipientTable, 1); - recipient_table->recipient_hash_table = g_hash_table_new (g_strcase_hash, g_strcase_equal); - recipient_table->ref_count = 1; - return recipient_table; -} - - -/** - * camel_recipient_table_ref: add a reference to a recipient table object - * @recipient_table: the recipient table object - * - * Add a reference to a recipient table object. - **/ -void -camel_recipient_table_ref (CamelRecipientTable *recipient_table) -{ - g_return_if_fail (recipient_table); - recipient_table->ref_count += 1; -} - - - -static void -_free_recipient_list (gpointer key, gpointer value, gpointer user_data) -{ - GList *recipient_list = (GList *)value; - gchar *recipient_name = (gchar *)key; - - while (recipient_list) { - g_free (recipient_list->data); - recipient_list = recipient_list->next; - } - - g_list_free ((GList *)value); - g_free (recipient_name); - -} - -/** - * camel_recipient_table_free: Free a recipient table object - * @recipient_table: the recipient table object to free - * - * Free a recipient table object. All recipients and recipient - * are freed. - **/ -void -camel_recipient_table_free (CamelRecipientTable *recipient_table) -{ - if (!recipient_table) return; - - /* free each recipient list */ - g_hash_table_foreach (recipient_table->recipient_hash_table, _free_recipient_list, NULL); - g_hash_table_destroy (recipient_table->recipient_hash_table); - g_free(recipient_table); -} - - - - -/** - * camel_recipient_table_unref: Removes a reference to a recipient table object - * @recipient_table: the recipient table object - * - * Removes a reference to the reference count of a recipient - * table object. If the reference count falls to zero, the - * recipient table object is freed. - * - **/ -void -camel_recipient_table_unref (CamelRecipientTable *recipient_table) -{ - if (!recipient_table) return; - - recipient_table->ref_count -= 1; - if (recipient_table->ref_count <1) - camel_recipient_table_free (recipient_table); - -} - - - - -/** - * camel_recipient_table_add: Add a recipient to a recipient table object. - * @recipient_table: The recipient table object - * @recipient_type: Recipient type string - * @recipient: The recipient to add - * - * Add a recipient to a recipient table object. - * The recipient is appended to the list of recipients - * of type @recipient_type. @recipient and @recipient_type - * are duplicated if necessary and freed when - * camel_recipient_table_free is called. - **/ -void -camel_recipient_table_add (CamelRecipientTable *recipient_table, - const gchar *recipient_type, - const gchar *recipient) -{ - 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); - - /* 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)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, g_strdup (recipient_type), recipients_list); - - -} - - -/** - * camel_recipient_table_add_list: Add a full list of recipients to a recipient table. - * @recipient_table: The recipient table object - * @recipient_type: Recipient type string. - * @recipient_list: Recipient list to add. - * - * Add a full list of recipients to a recipient table. - * The new recipients are appended at the end of the - * existing recipient list corresponding to @recipient_type. - * Be careful, 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 *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_list); - else - g_hash_table_insert (recipient_table->recipient_hash_table, g_strdup (recipient_type), recipient_list); - -} - - - - -/** - * camel_recipient_table_remove: Remove a recipient from a recipient table. - * @recipient_table: The recipient table object - * @recipient_type: Recipient type string. - * @recipient: Recipient to remove from the table - * - * Remove a recipient from a recipient table. The recipient is - * only removed from the recipient list corresponding to - * @recipient_type. The removed recipient is freed. - * - **/ -void -camel_recipient_table_remove (CamelRecipientTable *recipient_table, - 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 (recipient_table->recipient_hash_table, - recipient_type, - (gpointer)&(old_recipient_type), - (gpointer)&(recipients_list)) - ) return; - - /* look for the recipient to remove */ - /* 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); - - /* if glist head has changed, fix up hash table */ - if (new_recipients_list != recipients_list) - g_hash_table_insert (recipient_table->recipient_hash_table, old_recipient_type, new_recipients_list); - - g_free( (gchar *)(old_element->data)); - g_list_free_1 (old_element); - } -} - -void -camel_recipient_table_remove_type (CamelRecipientTable *recipient_table, - const gchar *recipient_type) -{ - GList *l, *n; - gchar *old_recipient_type; - - /* if the recipient type section does not exist, do nothing */ - if (! g_hash_table_lookup_extended (recipient_table->recipient_hash_table, - recipient_type, - (gpointer)&(old_recipient_type), - (void *)&l)) - return; - - g_hash_table_remove(recipient_table->recipient_hash_table, old_recipient_type); - g_free(old_recipient_type); - n = l; - while (l) { - g_free(l->data); - l = l->next; - } - g_list_free(n); -} - -/** - * camel_recipient_table_get: Get the recipients corresponding to a recipient type. - * @recipient_table: The recipient table object - * @recipient_type: Recipient type string. - * - * Return the list of recipients corresponding to - * @recipient_type. The returned list is not a copy - * of the internal list used by the recipient table object - * but the list itself. It thus must not be freed. - * The recipients it contains can be modified. - * - * Return value: The list of recipients. - **/ -const GList * -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); -} - - - - -/** - * camel_recipient_foreach_recipient_type: Runs a function over over all recipients type lists. - * @recipient_table: The recipient table object. - * @func: The function to run. - * @user_data: User data to pass to the function. - * - * Runs a function over over all recipients type lists. - **/ -void -camel_recipient_foreach_recipient_type (CamelRecipientTable *recipient_table, - CRLFunc func, - gpointer user_data) -{ - g_hash_table_foreach (recipient_table->recipient_hash_table, (GHFunc)func, user_data); -} diff --git a/camel/camel-recipient.h b/camel/camel-recipient.h deleted file mode 100644 index 1136cf36ae..0000000000 --- a/camel/camel-recipient.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-recipient.h : handle recipients (addresses) and recipiemt lists */ - -/* - * - * Author : - * Bertrand Guiheneuf - * - * Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - - - -#ifndef CAMEL_RECIPIENT_H -#define CAMEL_RECIPIENT_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include - - - -typedef struct { - GHashTable *recipient_hash_table; - gint ref_count; - -} CamelRecipientTable; - - -typedef void (*CRLFunc) (gchar *recipient_type, - GList *recipient_list, - gpointer user_data); - - - - -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); -void camel_recipient_table_remove_type (CamelRecipientTable *recipient_table, - const gchar *recipient_type); -const GList *camel_recipient_table_get (CamelRecipientTable *recipient_table, - const gchar *recipient_type); - -void camel_recipient_foreach_recipient_type (CamelRecipientTable *recipient_table, - CRLFunc func, - gpointer user_data); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_RECIPIENT_H */ - diff --git a/camel/camel.h b/camel/camel.h index 57a26a2e94..e97260bc77 100644 --- a/camel/camel.h +++ b/camel/camel.h @@ -54,7 +54,6 @@ extern "C" { #include #include #include -#include #include #include #include -- cgit v1.2.3