]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_search.c
* Removed the built-in memory leak checker. It wasn't threadsafe and
[citadel.git] / citadel / imap_search.c
index 683a6650c36f5b63f48c4c44db698b915a7c6dd0..dce7e605dad2a1395615f2bdd3c6e5a351a13be9 100644 (file)
@@ -68,6 +68,8 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        int is_not = 0;
        int is_or = 0;
        int pos = 0;
+       int i;
+       char *fieldptr;
 
        if (num_items == 0) return(0);
 
@@ -93,49 +95,76 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
        
        else if (!strcasecmp(itemlist[pos], "ANSWERED")) {
-               /* FIXME */
+               if (IMAP->flags[seq-1] & IMAP_ANSWERED) {
+                       match = 1;
+               }
                ++pos;
        }
 
        else if (!strcasecmp(itemlist[pos], "BCC")) {
-               /* FIXME */
+               fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Bcc");
+               if (fieldptr != NULL) {
+                       if (bmstrstr(fieldptr, itemlist[pos+1], strncasecmp)) {
+                               match = 1;
+                       }
+                       free(fieldptr);
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "BEFORE")) {
-               /* FIXME */
+               if (msg->cm_fields['T'] != NULL) {
+                       if (imap_datecmp(itemlist[pos+1],
+                                       atol(msg->cm_fields['T'])) < 0) {
+                               match = 1;
+                       }
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "BODY")) {
-               if (bmstrcasestr(msg->cm_fields['M'], itemlist[pos+1])) {
+               if (bmstrstr(msg->cm_fields['M'], itemlist[pos+1], strncasecmp)) {
                        match = 1;
                }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "CC")) {
-               /* FIXME */
+               fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Cc");
+               if (fieldptr != NULL) {
+                       if (bmstrstr(fieldptr, itemlist[pos+1], strncasecmp)) {
+                               match = 1;
+                       }
+                       free(fieldptr);
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "DELETED")) {
-               /* FIXME */
+               if (IMAP->flags[seq-1] & IMAP_DELETED) {
+                       match = 1;
+               }
                ++pos;
        }
 
        else if (!strcasecmp(itemlist[pos], "DRAFT")) {
-               /* FIXME */
+               if (IMAP->flags[seq-1] & IMAP_DRAFT) {
+                       match = 1;
+               }
                ++pos;
        }
 
        else if (!strcasecmp(itemlist[pos], "FLAGGED")) {
-               /* FIXME */
+               if (IMAP->flags[seq-1] & IMAP_FLAGGED) {
+                       match = 1;
+               }
                ++pos;
        }
 
        else if (!strcasecmp(itemlist[pos], "FROM")) {
-               /* FIXME */
+               if (bmstrstr(msg->cm_fields['A'], itemlist[pos+1], strncasecmp)) {
+                       match = 1;
+               }
                pos += 2;
        }
 
@@ -150,7 +179,9 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
 
        else if (!strcasecmp(itemlist[pos], "LARGER")) {
-               /* FIXME */
+               if (strlen(msg->cm_fields['M']) > atoi(itemlist[pos+1])) {
+                       match = 1;
+               }
                pos += 2;
        }
 
@@ -165,7 +196,12 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
 
        else if (!strcasecmp(itemlist[pos], "ON")) {
-               /* FIXME */
+               if (msg->cm_fields['T'] != NULL) {
+                       if (imap_datecmp(itemlist[pos+1],
+                                       atol(msg->cm_fields['T'])) == 0) {
+                               match = 1;
+                       }
+               }
                pos += 2;
        }
 
@@ -175,47 +211,79 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
 
        else if (!strcasecmp(itemlist[pos], "SEEN")) {
-               /* FIXME */
+               if (IMAP->flags[seq-1] & IMAP_SEEN) {
+                       match = 1;
+               }
                ++pos;
        }
 
        else if (!strcasecmp(itemlist[pos], "SENTBEFORE")) {
-               /* FIXME */
+               if (msg->cm_fields['T'] != NULL) {
+                       if (imap_datecmp(itemlist[pos+1],
+                                       atol(msg->cm_fields['T'])) < 0) {
+                               match = 1;
+                       }
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "SENTON")) {
-               /* FIXME */
+               if (msg->cm_fields['T'] != NULL) {
+                       if (imap_datecmp(itemlist[pos+1],
+                                       atol(msg->cm_fields['T'])) == 0) {
+                               match = 1;
+                       }
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "SENTSINCE")) {
-               /* FIXME */
+               if (msg->cm_fields['T'] != NULL) {
+                       if (imap_datecmp(itemlist[pos+1],
+                                       atol(msg->cm_fields['T'])) >= 0) {
+                               match = 1;
+                       }
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "SINCE")) {
-               /* FIXME */
+               if (msg->cm_fields['T'] != NULL) {
+                       if (imap_datecmp(itemlist[pos+1],
+                                       atol(msg->cm_fields['T'])) >= 0) {
+                               match = 1;
+                       }
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "SMALLER")) {
-               /* FIXME */
+               if (strlen(msg->cm_fields['M']) < atoi(itemlist[pos+1])) {
+                       match = 1;
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "SUBJECT")) {
-               /* FIXME */
+               if (bmstrstr(msg->cm_fields['U'], itemlist[pos+1], strncasecmp)) {
+                       match = 1;
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "TEXT")) {
-               /* FIXME */
+               for (i='A'; i<='Z'; ++i) {
+                       if (bmstrstr(msg->cm_fields[i], itemlist[pos+1], strncasecmp)) {
+                               match = 1;
+                       }
+               }
                pos += 2;
        }
 
        else if (!strcasecmp(itemlist[pos], "TO")) {
-               /* FIXME */
+               if (bmstrstr(msg->cm_fields['R'], itemlist[pos+1], strncasecmp)) {
+                       match = 1;
+               }
                pos += 2;
        }
 
@@ -233,22 +301,30 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
         */
 
        else if (!strcasecmp(itemlist[pos], "UNANSWERED")) {
-               /* FIXME */
+               if ((IMAP->flags[seq-1] & IMAP_ANSWERED) == 0) {
+                       match = 1;
+               }
                ++pos;
        }
 
        else if (!strcasecmp(itemlist[pos], "UNDELETED")) {
-               /* FIXME */
+               if ((IMAP->flags[seq-1] & IMAP_DELETED) == 0) {
+                       match = 1;
+               }
                ++pos;
        }
 
        else if (!strcasecmp(itemlist[pos], "UNDRAFT")) {
-               /* FIXME */
+               if ((IMAP->flags[seq-1] & IMAP_DRAFT) == 0) {
+                       match = 1;
+               }
                ++pos;
        }
 
        else if (!strcasecmp(itemlist[pos], "UNFLAGGED")) {
-               /* FIXME */
+               if ((IMAP->flags[seq-1] & IMAP_FLAGGED) == 0) {
+                       match = 1;
+               }
                ++pos;
        }
 
@@ -258,7 +334,9 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
 
        else if (!strcasecmp(itemlist[pos], "UNSEEN")) {
-               /* FIXME */
+               if ((IMAP->flags[seq-1] & IMAP_SEEN) == 0) {
+                       match = 1;
+               }
                ++pos;
        }
 
@@ -311,7 +389,7 @@ void imap_do_search(int num_items, char **itemlist, int is_uid) {
                        CtdlFreeMessage(msg);
                }
                else {
-                       lprintf(1, "SEARCH internal error\n");
+                       lprintf(CTDL_ERR, "SEARCH internal error\n");
                }
        }
        cprintf("\r\n");