]> 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 70abccf65fc2674f221ac980fb882d9dd1857d1d..894a96e952158cadd51c9bdf0bc6cbcffbfb2d8c 100644 (file)
@@ -69,6 +69,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        int is_or = 0;
        int pos = 0;
        int i;
+       char *fieldptr;
 
        if (num_items == 0) return(0);
 
@@ -101,24 +102,41 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
 
        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")) {
-               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;
+                       }
+                       phree(fieldptr);
+               }
                pos += 2;
        }
 
@@ -144,7 +162,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
 
        else if (!strcasecmp(itemlist[pos], "FROM")) {
-               if (bmstrcasestr(msg->cm_fields['A'], itemlist[pos+1])) {
+               if (bmstrstr(msg->cm_fields['A'], itemlist[pos+1], strncasecmp)) {
                        match = 1;
                }
                pos += 2;
@@ -178,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;
        }
 
@@ -195,22 +218,42 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
 
        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;
        }
 
@@ -222,7 +265,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
 
        else if (!strcasecmp(itemlist[pos], "SUBJECT")) {
-               if (bmstrcasestr(msg->cm_fields['U'], itemlist[pos+1])) {
+               if (bmstrstr(msg->cm_fields['U'], itemlist[pos+1], strncasecmp)) {
                        match = 1;
                }
                pos += 2;
@@ -230,7 +273,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
 
        else if (!strcasecmp(itemlist[pos], "TEXT")) {
                for (i='A'; i<='Z'; ++i) {
-                       if (bmstrcasestr(msg->cm_fields[i], itemlist[pos+1])) {
+                       if (bmstrstr(msg->cm_fields[i], itemlist[pos+1], strncasecmp)) {
                                match = 1;
                        }
                }
@@ -238,7 +281,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *msg,
        }
 
        else if (!strcasecmp(itemlist[pos], "TO")) {
-               if (bmstrcasestr(msg->cm_fields['R'], itemlist[pos+1])) {
+               if (bmstrstr(msg->cm_fields['R'], itemlist[pos+1], strncasecmp)) {
                        match = 1;
                }
                pos += 2;
@@ -346,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");