aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand Guiheneuf <bertrand@src.gnome.org>1999-05-14 05:36:14 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>1999-05-14 05:36:14 +0800
commit1126db678eea6b5fcde9376b77e5b35694467453 (patch)
tree7acedc65956bdb71ac4f429dc0ca1fb4786e83fd
parent483804aac86969591d7aefa186f52ca167da0381 (diff)
downloadgsoc2013-evolution-1126db678eea6b5fcde9376b77e5b35694467453.tar.gz
gsoc2013-evolution-1126db678eea6b5fcde9376b77e5b35694467453.tar.zst
gsoc2013-evolution-1126db678eea6b5fcde9376b77e5b35694467453.zip
create recipients hash table (_remove_recipient): (_add_recipient):
* camel/camel-mime-message.c (camel_mime_message_init): create recipients hash table (_remove_recipient): (_add_recipient): (_get_recipients): new funcs. Internal Recipients data structure is a bit complicated though. * camel/camel-mime-part.c (camel_mime_part_init): create headers hash table svn path=/trunk/; revision=924
-rw-r--r--ChangeLog11
-rw-r--r--camel/camel-mime-message.c90
-rw-r--r--camel/camel-mime-part.c9
3 files changed, 108 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 2d72005746..3b5c1061fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,15 @@
1999-05-13 bertrand <Bertrand.Guiheneuf@inria.fr>
+
+ * camel/camel-mime-message.c (camel_mime_message_init):
+ create recipients hash table
+ (_remove_recipient):
+ (_add_recipient):
+ (_get_recipients): new funcs.
+ Internal Recipients data structure is
+ a bit complicated though.
+
+ * camel/camel-mime-part.c (camel_mime_part_init):
+ create headers hash table
* camel/camel-mime-message.h:
a bunch of get/set header field
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index b3ce5be357..b39e9e60dd 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -25,6 +25,7 @@
#include "camel-mime-message.h"
#include <stdio.h>
#include "gmime-content-field.h"
+#include "gstring-util.h"
@@ -79,6 +80,16 @@ 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);
+
+ camel_mime_message->recipients = g_hash_table_new(g_string_hash, g_string_equal_for_hash);
+
+}
+
+
@@ -94,7 +105,7 @@ camel_mime_message_get_type (void)
sizeof (CamelMimeMessage),
sizeof (CamelMimeMessageClass),
(GtkClassInitFunc) camel_mime_message_class_init,
- (GtkObjectInitFunc) NULL,
+ (GtkObjectInitFunc) camel_mime_message_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
@@ -257,3 +268,80 @@ get_from (CamelMimeMessage *mime_message)
return CMM_CLASS (mime_message)->get_from (mime_message);
}
+
+
+
+
+
+static void
+_add_recipient (CamelMimeMessage *mime_message, GString *recipient_type, GString *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 (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_hash) )
+ 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);
+}
+
+
+/**
+ * _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, GString *recipient_type, GString *recipient)
+{
+ GList *recipients_list;
+ GList *new_recipients_list;
+ GList *old_element;
+ GString *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 remoce */
+ old_element = g_list_find_custom (recipients_list, recipient, g_string_equal_for_hash);
+ 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_string_free( (GString *)(old_element->data), TRUE);
+ g_list_free_1(old_element);
+ }
+}
+
+
+
+
+
+static GList *
+_get_recipients (CamelMimeMessage *mime_message, GString *recipient_type)
+{
+ return (GList *)g_hash_table_lookup (mime_message->recipients, recipient_type);
+}
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index 35fd0279ed..a79ef7efcc 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -27,6 +27,7 @@
#include "camel-mime-part.h"
#include <stdio.h>
#include "gmime-content-field.h"
+#include "gstring-util.h"
@@ -94,8 +95,14 @@ camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class)
camel_data_wrapper_class->write_to_file = _write_to_file;
}
+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);
+}
@@ -112,7 +119,7 @@ camel_mime_part_get_type (void)
sizeof (CamelMimePart),
sizeof (CamelMimePartClass),
(GtkClassInitFunc) camel_mime_part_class_init,
- (GtkObjectInitFunc) NULL,
+ (GtkObjectInitFunc) camel_mime_part_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,