]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_search.c
* Use syslog-compatible logging levels in lprintf(); the loglevel chosen
[citadel.git] / citadel / imap_search.c
index 96d6737019e1dc58c8b4a8a94c71a315ae80a612..894a96e952158cadd51c9bdf0bc6cbcffbfb2d8c 100644 (file)
@@ -65,10 +65,11 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
                        int num_items, char **itemlist, int is_uid) {
 
        int match = 0;
-       int i;
        int is_not = 0;
        int is_or = 0;
        int pos = 0;
+       int i;
+       char *fieldptr;
 
        if (num_items == 0) return(0);
 
@@ -94,47 +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;
+                       }
+                       phree(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")) {
-               /* FIXME */
+               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;
+                       }
+                       phree(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;
        }
 
@@ -149,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;
        }
 
@@ -164,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;
        }
 
@@ -174,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;
        }
 
@@ -232,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;
        }
 
@@ -257,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;
        }
 
@@ -310,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");