* More license declarations
[citadel.git] / citadel / modules / imap / imap_search.c
index 64f26f648870cfc45cee8e2d3367a0bd36e25ad9..1cb38c97b940472232e5f29be992a33d0c0afd64 100644 (file)
@@ -3,6 +3,22 @@
  *
  * Implements IMAP's gratuitously complex SEARCH command.
  *
+ *
+ * Copyright (c) 2001-2009 by the citadel.org team
+ *
+ *  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 3 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 "sysdep.h"
@@ -30,6 +46,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
 #include "imap_fetch.h"
 #include "imap_search.h"
 #include "genstamp.h"
-#include "serv_fulltext.h"     /* Needed for ft_search */
 
 
 /*
@@ -242,7 +257,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg,
                        CC->redirect_buffer = malloc(SIZ);
                        CC->redirect_len = 0;
                        CC->redirect_alloc = SIZ;
-                       CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1);
+                       CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_FAST, 0, 1, 0);
        
                        fieldptr = rfc822_fetch_field(CC->redirect_buffer, itemlist[pos+1]);
                        if (fieldptr != NULL) {
@@ -539,13 +554,26 @@ void imap_do_search(int num_items, char **itemlist, int is_uid) {
        int is_in_list = 0;
        int num_results = 0;
 
+       /* Strip parentheses.  We realize that this method will not work
+        * in all cases, but it seems to work with all currently available
+        * client software.  Revisit later...
+        */
+       for (i=0; i<num_items; ++i) {
+               if (itemlist[i][0] == '(') {
+                       strcpy(&itemlist[i][0], &itemlist[i][1]);
+               }
+               if (itemlist[i][strlen(itemlist[i])-1] == ')') {
+                       itemlist[i][strlen(itemlist[i])-1] = 0;
+               }
+       }
+
        /* If there is a BODY search criterion in the query, use our full
         * text index to disqualify messages that don't have any chance of
         * matching.  (Only do this if the index is enabled!!)
         */
        if (config.c_enable_fulltext) for (i=0; i<(num_items-1); ++i) {
                if (!strcasecmp(itemlist[i], "BODY")) {
-                       ft_search(&fts_num_msgs, &fts_msgs, itemlist[i+1]);
+                       CtdlModuleDoSearch(&fts_num_msgs, &fts_msgs, itemlist[i+1], "fulltext");
                        if (fts_num_msgs > 0) {
                                for (j=0; j < IMAP->num_msgs; ++j) {
                                        if (IMAP->flags[j] & IMAP_SELECTED) {