aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap/camel-imap-search.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2002-04-18 10:18:55 +0800
committerMichael Zucci <zucchi@src.gnome.org>2002-04-18 10:18:55 +0800
commit6ccd0e6f59bec5f1900c49cd1868fca998570fc7 (patch)
treeeac70d58c4d79bfbc73d7592ad5f303f7f8c044e /camel/providers/imap/camel-imap-search.c
parente5e67a6644e4d0ac41c270a4bcd18e5c6e2b7667 (diff)
downloadgsoc2013-evolution-6ccd0e6f59bec5f1900c49cd1868fca998570fc7.tar
gsoc2013-evolution-6ccd0e6f59bec5f1900c49cd1868fca998570fc7.tar.gz
gsoc2013-evolution-6ccd0e6f59bec5f1900c49cd1868fca998570fc7.tar.bz2
gsoc2013-evolution-6ccd0e6f59bec5f1900c49cd1868fca998570fc7.tar.lz
gsoc2013-evolution-6ccd0e6f59bec5f1900c49cd1868fca998570fc7.tar.xz
gsoc2013-evolution-6ccd0e6f59bec5f1900c49cd1868fca998570fc7.tar.zst
gsoc2013-evolution-6ccd0e6f59bec5f1900c49cd1868fca998570fc7.zip
When doing a contains match, split the words and perform an and on it.
2002-04-18 Not Zed <NotZed@Ximian.com> * camel-folder-search.c (check_header): When doing a contains match, split the words and perform an and on it. (match_words_messages): If we have an index, but were forced to do a full search, first lookup a subset of messages using the index and a simplified word set. Only do a manual search of this subset. 2002-04-17 Not Zed <NotZed@Ximian.com> * camel-folder-search.c (match_message_index): Changed to take a utf8 string not a regex pattern. (match_words_index): Matches against a camel_search_words list. (match_words_1message): Matches a single message against a camel_search_words list. (match_words_message): Same, but gets the message from the folder for you. (match_words_messages): Matches a list of messages against a words list. (search_body_contains): Rewritten to handle multiple word searches. For #23371. * providers/imap/camel-imap-search.c (sync_match): Split words when searching, to support multiple search words. Also, try searching specifying charset of utf8 if we can, if that fails, fall back to not specifying charset. TODO: It should translate the strings into the locale default charset? * providers/imap/camel-imap-store.c (connect_to_server): Added new cap - utf8_search, if set, we tell the server we're searching using utf8, otherwise we dont (incorrectly, since we always use utf8 to search). * camel-search-private.c (camel_ustrstrcase): Make this class public. (camel_search_words_split): Split a word into multiple words based on whitespace, and keep track of whether the word is simple (indexable directly), or not. (camel_search_words_free): Free 'em. svn path=/trunk/; revision=16501
Diffstat (limited to 'camel/providers/imap/camel-imap-search.c')
-rw-r--r--camel/providers/imap/camel-imap-search.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/camel/providers/imap/camel-imap-search.c b/camel/providers/imap/camel-imap-search.c
index 8463eb202b..c30fa5611e 100644
--- a/camel/providers/imap/camel-imap-search.c
+++ b/camel/providers/imap/camel-imap-search.c
@@ -42,6 +42,7 @@
#include "camel-mime-utils.h" /* base64 encoding */
#include "camel-seekable-stream.h"
+#include "camel-search-private.h"
#define d(x) x
@@ -304,10 +305,13 @@ static int
sync_match(CamelImapSearch *is, struct _match_record *mr)
{
char *p, *result, *lasts = NULL;
- CamelImapResponse *response;
+ CamelImapResponse *response = NULL;
guint32 uid;
CamelFolder *folder = ((CamelFolderSearch *)is)->folder;
CamelImapStore *store = (CamelImapStore *)folder->parent_store;
+ struct _camel_search_words *words;
+ GString *search;
+ int i;
if (mr->lastuid >= is->lastuid && mr->validity == is->validity)
return 0;
@@ -316,9 +320,36 @@ sync_match(CamelImapSearch *is, struct _match_record *mr)
/* TODO: Handle multiple search terms */
- response = camel_imap_command (store, folder, NULL,
- "UID SEARCH UID %d:%d BODY \"%s\"",
- mr->lastuid+1, is->lastuid, mr->terms[0]);
+ /* This handles multiple search words within a single term */
+ words = camel_search_words_split(mr->terms[0]);
+ search = g_string_new("");
+ g_string_sprintfa(search, "UID %d:%d", mr->lastuid+1, is->lastuid);
+ for (i=0;i<words->len;i++) {
+ char *w = words->words[i]->word, c;
+
+ g_string_sprintfa(search, " BODY \"");
+ while ((c = *w++)) {
+ if (c == '\\' || c == '"')
+ g_string_append_c(search, '\\');
+ g_string_append_c(search, c);
+ }
+ g_string_append_c(search, '"');
+ }
+ camel_search_words_free(words);
+
+ /* We only try search using utf8 if its non us-ascii text? */
+ if ((words->type & CAMEL_SEARCH_WORD_8BIT) && (store->capabilities & IMAP_CAPABILITY_utf8_search)) {
+ response = camel_imap_command(store, folder, NULL,
+ "UID SEARCH CHARSET UTF-8 %s", search->str);
+ /* We can't actually tell if we got a NO response, so assume always */
+ if (response == NULL)
+ store->capabilities &= ~IMAP_CAPABILITY_utf8_search;
+ }
+ if (response == NULL)
+ response = camel_imap_command (store, folder, NULL,
+ "UID SEARCH %s", search->str);
+ g_string_free(search, TRUE);
+
if (!response)
return -1;
result = camel_imap_response_extract (store, response, "SEARCH", NULL);