diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-06-21 05:32:17 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-06-21 05:32:17 +0800 |
commit | 9534ce2e95c2d9886c4cc1e3fdd9e416629422ce (patch) | |
tree | d6560b4e5f7baaba8a0bff4f235a31d9c3c1761b /camel/camel-digest-folder.c | |
parent | ceb0e460e9171234e60bbf9d4c5711eca7be0365 (diff) | |
download | gsoc2013-evolution-9534ce2e95c2d9886c4cc1e3fdd9e416629422ce.tar gsoc2013-evolution-9534ce2e95c2d9886c4cc1e3fdd9e416629422ce.tar.gz gsoc2013-evolution-9534ce2e95c2d9886c4cc1e3fdd9e416629422ce.tar.bz2 gsoc2013-evolution-9534ce2e95c2d9886c4cc1e3fdd9e416629422ce.tar.lz gsoc2013-evolution-9534ce2e95c2d9886c4cc1e3fdd9e416629422ce.tar.xz gsoc2013-evolution-9534ce2e95c2d9886c4cc1e3fdd9e416629422ce.tar.zst gsoc2013-evolution-9534ce2e95c2d9886c4cc1e3fdd9e416629422ce.zip |
Updated to support searching as well as making it use CamelDigestSummary.
2002-06-20 Jeffrey Stedfast <fejj@ximian.com>
* camel-digest-folder.c: Updated to support searching as well as
making it use CamelDigestSummary.
* camel-digest-summary.[c,h]: New class to handle the summary for
CamelDigestFolder.
* camel-tcp-stream-ssl.c (set_errno): PR_IO_TIMEOUT_ERROR should
map to ETIMEDOUT and not EAGAIN.
(stream_connect): Reset the PR_Poll() timeout back to 2 minutes as
this wasn't the problem afterall.
svn path=/trunk/; revision=17249
Diffstat (limited to 'camel/camel-digest-folder.c')
-rw-r--r-- | camel/camel-digest-folder.c | 271 |
1 files changed, 165 insertions, 106 deletions
diff --git a/camel/camel-digest-folder.c b/camel/camel-digest-folder.c index 2454b0f637..070e5aed3b 100644 --- a/camel/camel-digest-folder.c +++ b/camel/camel-digest-folder.c @@ -25,11 +25,12 @@ #endif #include "camel-digest-folder.h" +#include "camel-digest-summary.h" #include "camel-exception.h" #include "camel-multipart.h" #include "camel-mime-message.h" -#include "camel-folder-summary.h" +#include "camel-folder-search.h" #define d(x) @@ -37,11 +38,20 @@ struct _CamelDigestFolderPrivate { CamelMimeMessage *message; - GHashTable *info_hash; - GPtrArray *summary; - GPtrArray *uids; + CamelFolderSearch *search; +#ifdef ENABLE_THREADS + GMutex *search_lock; +#endif }; +#ifdef ENABLE_THREADS +#define CAMEL_DIGEST_FOLDER_LOCK(f, l) (g_mutex_lock(((CamelDigestFolder *)f)->priv->l)) +#define CAMEL_DIGEST_FOLDER_UNLOCK(f, l) (g_mutex_unlock(((CamelDigestFolder *)f)->priv->l)) +#else +#define CAMEL_DIGEST_FOLDER_LOCK(f, l) +#define CAMEL_DIGEST_FOLDER_UNLOCK(f, l) +#endif + static CamelFolderClass *parent_class = NULL; static void digest_refresh_info (CamelFolder *folder, CamelException *ex); @@ -49,10 +59,6 @@ static void digest_sync (CamelFolder *folder, gboolean expunge, CamelException * static const char *digest_get_full_name (CamelFolder *folder); static void digest_expunge (CamelFolder *folder, CamelException *ex); -static GPtrArray *digest_get_uids (CamelFolder *folder); -static void digest_free_uids (CamelFolder *folder, GPtrArray *uids); -static CamelMessageInfo *digest_get_message_info (CamelFolder *folder, const char *uid); - /* message manipulation */ static CamelMimeMessage *digest_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex); @@ -62,6 +68,13 @@ static void digest_transfer_messages_to (CamelFolder *source, GPtrArray *uids, CamelFolder *dest, GPtrArray **transferred_uids, gboolean delete_originals, CamelException *ex); +static GPtrArray *digest_search_by_expression (CamelFolder *folder, const char *expression, + CamelException *ex); + +static GPtrArray *digest_search_by_uids (CamelFolder *folder, const char *expression, + GPtrArray *uids, CamelException *ex); + +static void digest_search_free (CamelFolder *folder, GPtrArray *result); static void camel_digest_folder_class_init (CamelDigestFolderClass *camel_digest_folder_class) @@ -78,13 +91,13 @@ camel_digest_folder_class_init (CamelDigestFolderClass *camel_digest_folder_clas camel_folder_class->expunge = digest_expunge; camel_folder_class->get_full_name = digest_get_full_name; - camel_folder_class->get_uids = digest_get_uids; - camel_folder_class->free_uids = digest_free_uids; - camel_folder_class->get_message_info = digest_get_message_info; - camel_folder_class->get_message = digest_get_message; camel_folder_class->append_message = digest_append_message; camel_folder_class->transfer_messages_to = digest_transfer_messages_to; + + camel_folder_class->search_by_expression = digest_search_by_expression; + camel_folder_class->search_by_uids = digest_search_by_uids; + camel_folder_class->search_free = digest_search_free; } static void @@ -93,34 +106,37 @@ camel_digest_folder_init (gpointer object, gpointer klass) CamelDigestFolder *digest_folder = CAMEL_DIGEST_FOLDER (object); CamelFolder *folder = CAMEL_FOLDER (object); - folder->folder_flags |= CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY; + folder->folder_flags |= CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY | CAMEL_FOLDER_HAS_SEARCH_CAPABILITY; + + folder->summary = camel_digest_summary_new (); - digest_folder->priv = g_new0 (struct _CamelDigestFolderPrivate, 1); - digest_folder->priv->info_hash = g_hash_table_new (g_str_hash, g_str_equal); + digest_folder->priv = g_new (struct _CamelDigestFolderPrivate, 1); + digest_folder->priv->message = NULL; + digest_folder->priv->search = NULL; +#ifdef ENABLE_THREADS + digest_folder->priv->search_lock = g_mutex_new (); +#endif } static void digest_finalize (CamelObject *object) { CamelDigestFolder *digest_folder = CAMEL_DIGEST_FOLDER (object); - GPtrArray *summary; + CamelFolder *folder = CAMEL_FOLDER (object); + + if (folder->summary) { + camel_object_unref (CAMEL_OBJECT (folder->summary)); + folder->summary = NULL; + } camel_object_unref (CAMEL_OBJECT (digest_folder->priv->message)); - g_hash_table_destroy (digest_folder->priv->info_hash); + if (digest_folder->priv->search) + camel_object_unref (CAMEL_OBJECT (digest_folder->priv->search)); - summary = digest_folder->priv->summary; - if (summary) { - int i; - - for (i = 0; i < summary->len; i++) - camel_message_info_free (summary->pdata[i]); - - g_ptr_array_free (summary, TRUE); - } - - if (digest_folder->priv->uids) - g_ptr_array_free (digest_folder->priv->uids, TRUE); +#ifdef ENABLE_THREADS + g_mutex_free (digest_folder->priv->search_lock); +#endif g_free (digest_folder->priv); } @@ -166,6 +182,44 @@ multipart_contains_message_parts (CamelMultipart *multipart) return has_message_parts; } +static void +digest_add_multipart (CamelFolder *folder, CamelMultipart *multipart, const char *preuid) +{ + CamelDataWrapper *wrapper; + CamelMessageInfo *info; + CamelMimePart *part; + int parts, i; + char *uid; + + parts = camel_multipart_get_number (multipart); + for (i = 0; i < parts; i++) { + part = camel_multipart_get_part (multipart, i); + + wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part)); + + if (CAMEL_IS_MULTIPART (wrapper)) { + uid = g_strdup_printf ("%s%d.", preuid, i); + digest_add_multipart (folder, CAMEL_MULTIPART (wrapper), uid); + g_free (uid); + continue; + } else if (!CAMEL_IS_MIME_MESSAGE (wrapper)) { + continue; + } + + info = camel_folder_summary_info_new_from_message (folder->summary, CAMEL_MIME_MESSAGE (wrapper)); + + uid = g_strdup_printf ("%s%d", preuid, i); + camel_message_info_set_uid (info, uid); + camel_folder_summary_add (folder->summary, info); + } +} + +static void +construct_summary (CamelFolder *folder, CamelMultipart *multipart) +{ + digest_add_multipart (folder, multipart, ""); +} + CamelFolder * camel_digest_folder_new (CamelStore *parent_store, CamelMimeMessage *message) { @@ -191,6 +245,8 @@ camel_digest_folder_new (CamelStore *parent_store, CamelMimeMessage *message) camel_object_ref (CAMEL_OBJECT (message)); digest_folder->priv->message = message; + construct_summary (folder, CAMEL_MULTIPART (wrapper)); + return folder; } @@ -212,83 +268,6 @@ digest_expunge (CamelFolder *folder, CamelException *ex) /* no-op */ } -static void -digest_add_multipart (CamelMultipart *multipart, GPtrArray *summary, - GPtrArray *uids, GHashTable *info_hash, - const char *preuid) -{ - CamelDataWrapper *wrapper; - CamelMessageInfo *info; - CamelMimePart *part; - int parts, i; - char *uid; - - parts = camel_multipart_get_number (multipart); - for (i = 0; i < parts; i++) { - part = camel_multipart_get_part (multipart, i); - - wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part)); - - if (CAMEL_IS_MULTIPART (wrapper)) { - uid = g_strdup_printf ("%s%d.", preuid, i); - digest_add_multipart (CAMEL_MULTIPART (wrapper), - summary, uids, info_hash, uid); - g_free (uid); - continue; - } else if (!CAMEL_IS_MIME_MESSAGE (wrapper)) { - continue; - } - - info = camel_message_info_new_from_header (CAMEL_MIME_PART (wrapper)->headers); - - uid = g_strdup_printf ("%s%d", preuid, i); - camel_message_info_set_uid (info, g_strdup (uid)); - - g_ptr_array_add (uids, uid); - g_ptr_array_add (summary, info); - g_hash_table_insert (info_hash, uid, info); - } -} - -static GPtrArray * -digest_get_uids (CamelFolder *folder) -{ - CamelDigestFolder *digest_folder = CAMEL_DIGEST_FOLDER (folder); - CamelDataWrapper *wrapper; - GHashTable *info_hash; - GPtrArray *summary; - GPtrArray *uids; - - if (digest_folder->priv->uids) - return digest_folder->priv->uids; - - uids = g_ptr_array_new (); - summary = g_ptr_array_new (); - info_hash = digest_folder->priv->info_hash; - - wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (digest_folder->priv->message)); - digest_add_multipart (CAMEL_MULTIPART (wrapper), summary, uids, info_hash, ""); - - digest_folder->priv->uids = uids; - digest_folder->priv->summary = summary; - - return uids; -} - -static void -digest_free_uids (CamelFolder *folder, GPtrArray *uids) -{ - /* no-op */ -} - -static CamelMessageInfo * -digest_get_message_info (CamelFolder *folder, const char *uid) -{ - CamelDigestFolder *digest = CAMEL_DIGEST_FOLDER (folder); - - return g_hash_table_lookup (digest->priv->info_hash, uid); -} - static const char * digest_get_full_name (CamelFolder *folder) { @@ -346,3 +325,83 @@ digest_get_message (CamelFolder *folder, const char *uid, CamelException *ex) return message; } + + +static GPtrArray * +digest_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex) +{ + CamelDigestFolder *df = (CamelDigestFolder *) folder; + CamelFolderSearch *search; + GPtrArray *summary, *matches; + + summary = camel_folder_get_summary (folder); + + CAMEL_DIGEST_FOLDER_LOCK (folder, search_lock); + + if (!df->priv->search) + df->priv->search = camel_folder_search_new (); + + search = df->priv->search; + camel_folder_search_set_folder (search, folder); + camel_folder_search_set_summary (search, summary); + + matches = camel_folder_search_execute_expression (search, expression, ex); + + CAMEL_DIGEST_FOLDER_UNLOCK (folder, search_lock); + + camel_folder_free_summary (folder, summary); + + return matches; +} + +static GPtrArray * +digest_search_by_uids (CamelFolder *folder, const char *expression, GPtrArray *uids, CamelException *ex) +{ + CamelDigestFolder *df = (CamelDigestFolder *) folder; + CamelFolderSearch *search; + GPtrArray *summary, *matches; + int i; + + summary = g_ptr_array_new (); + for (i = 0; i < uids->len; i++) { + CamelMessageInfo *info; + + info = camel_folder_get_message_info (folder, uids->pdata[i]); + if (info) + g_ptr_array_add (summary, info); + } + + if (summary->len == 0) + return summary; + + CAMEL_DIGEST_FOLDER_LOCK (folder, search_lock); + + if (!df->priv->search) + df->priv->search = camel_folder_search_new (); + + search = df->priv->search; + camel_folder_search_set_folder (search, folder); + camel_folder_search_set_summary (search, summary); + + matches = camel_folder_search_execute_expression (search, expression, ex); + + CAMEL_DIGEST_FOLDER_UNLOCK (folder, search_lock); + + for (i = 0; i < summary->len; i++) + camel_folder_free_message_info (folder, summary->pdata[i]); + g_ptr_array_free (summary, TRUE); + + return matches; +} + +static void +digest_search_free (CamelFolder *folder, GPtrArray *result) +{ + CamelDigestFolder *digest_folder = CAMEL_DIGEST_FOLDER (folder); + + CAMEL_DIGEST_FOLDER_LOCK (folder, search_lock); + + camel_folder_search_free_result (digest_folder->priv->search, result); + + CAMEL_DIGEST_FOLDER_UNLOCK (folder, search_lock); +} |