aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap/camel-imap-search.c
diff options
context:
space:
mode:
author9 <NotZed@Ximian.com>2001-10-10 06:26:01 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-10-10 06:26:01 +0800
commitd5e090651bbd30ee761624187db6ad7920162aa8 (patch)
tree7ad7107b56496575d6e9914723ff8670a74e7351 /camel/providers/imap/camel-imap-search.c
parent7980990c79feaa36f452d9e2f2f59e8de1b1ec5c (diff)
downloadgsoc2013-evolution-d5e090651bbd30ee761624187db6ad7920162aa8.tar
gsoc2013-evolution-d5e090651bbd30ee761624187db6ad7920162aa8.tar.gz
gsoc2013-evolution-d5e090651bbd30ee761624187db6ad7920162aa8.tar.bz2
gsoc2013-evolution-d5e090651bbd30ee761624187db6ad7920162aa8.tar.lz
gsoc2013-evolution-d5e090651bbd30ee761624187db6ad7920162aa8.tar.xz
gsoc2013-evolution-d5e090651bbd30ee761624187db6ad7920162aa8.tar.zst
gsoc2013-evolution-d5e090651bbd30ee761624187db6ad7920162aa8.zip
Implement.
2001-10-09 <NotZed@Ximian.com> * providers/local/camel-spool-folder.c (spool_search_by_uids): Implement. * providers/imap/camel-imap-search.c (imap_body_contains): If searching a sub-set of the total message count, then use a UID range to search only specific messages. * camel-vee-folder.c (vee_folder_change_match): Removed. (folder_changed_add_uid): Helper func for changed code. (folder_changed_remove_uid): " (folder_changed_change_uid): " (folder_changed): Rewritten. Supports proper auto-updating of changes, but not removals till a sync occurs. (vee_search_by_uids): Implement. (folder_changed): Changed to call an async threaded function to do the actual folder updating. * camel-folder-summary.c (camel_flag_list_copy): New func to copy a whole list of flags. (camel_tag_list_copy): New func to copy a whole list of flags. * providers/imap/camel-imap-folder.c (imap_search_by_uids): Implement. * providers/local/camel-local-folder.c (local_search_by_uids): Implement. * camel-folder.c (camel_folder_search_by_uids): New function, search a subset of uid's. (search_by_uids): Default impl, return error. svn path=/trunk/; revision=13532
Diffstat (limited to 'camel/providers/imap/camel-imap-search.c')
-rw-r--r--camel/providers/imap/camel-imap-search.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/camel/providers/imap/camel-imap-search.c b/camel/providers/imap/camel-imap-search.c
index 3c96449963..0418a34617 100644
--- a/camel/providers/imap/camel-imap-search.c
+++ b/camel/providers/imap/camel-imap-search.c
@@ -34,6 +34,7 @@
#include "camel-imap-store.h"
#include "camel-imap-search.h"
#include "camel-imap-private.h"
+#include "camel-imap-utils.h"
static ESExpResult *
imap_body_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv,
@@ -67,6 +68,21 @@ camel_imap_search_get_type (void)
return camel_imap_search_type;
}
+static int
+cmp_uid(const void *ap, const void *bp)
+{
+ unsigned int a, b;
+
+ a = strtoul(((char **)ap)[0], NULL, 10);
+ b = strtoul(((char **)bp)[0], NULL, 10);
+ if (a<b)
+ return -1;
+ else if (a>b)
+ return 1;
+
+ return 0;
+}
+
static ESExpResult *
imap_body_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv,
CamelFolderSearch *s)
@@ -79,6 +95,9 @@ imap_body_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv,
ESExpResult *r;
CamelMessageInfo *info;
GHashTable *uid_hash = NULL;
+ char *set;
+ GPtrArray *sorted;
+ int i;
if (s->current) {
uid = camel_message_info_uid (s->current);
@@ -100,11 +119,29 @@ imap_body_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv,
g_ptr_array_add (r->value.ptrarray, (char *)camel_message_info_uid (info));
}
} else {
- /* FIXME: danw: what if we have multiple string args? */
+ /* If searching a (reasonably small) subset of
+ the real folder size, then use a
+ message-set to optimise it */
+ /* TODO: This peeks a bunch of 'private'ish data */
+ if (s->summary->len < camel_folder_get_message_count(s->folder)/2) {
+ sorted = g_ptr_array_new();
+ g_ptr_array_set_size(sorted, s->summary->len);
+ for (i=0;i<s->summary->len;i++)
+ sorted->pdata[i] = (void *)camel_message_info_uid((CamelMessageInfo *)s->summary->pdata[i]);
+ qsort(sorted->pdata, sorted->len, sizeof(sorted->pdata[0]), cmp_uid);
+ set = imap_uid_array_to_set(s->folder->summary, sorted);
+ response = camel_imap_command (store, s->folder, NULL,
+ "UID SEARCH UID %s BODY \"%s\"",
+ set, value);
+ g_free(set);
+ g_ptr_array_free(sorted, TRUE);
+ } else {
+ response = camel_imap_command (store, s->folder, NULL,
+ "UID SEARCH BODY \"%s\"",
+ value);
+ }
+
r->value.ptrarray = g_ptr_array_new ();
- response = camel_imap_command (store, s->folder, NULL,
- "UID SEARCH BODY \"%s\"",
- value);
}
}