4 * Implements the SEARCH command in IMAP.
5 * This command is way too convoluted. Marc Crispin is a fscking idiot.
18 #include <sys/types.h>
20 #if TIME_WITH_SYS_TIME
21 # include <sys/time.h>
25 # include <sys/time.h>
37 #include "sysdep_decls.h"
38 #include "citserver.h"
41 #include "dynloader.h"
48 #include "internet_addressing.h"
49 #include "serv_imap.h"
50 #include "imap_tools.h"
51 #include "imap_fetch.h"
52 #include "imap_search.h"
61 * imap_do_search() calls imap_do_search_msg() to output the deta of an
62 * individual message, once it has been successfully loaded from disk.
64 void imap_do_search_msg(int seq, struct CtdlMessage *msg,
65 int num_items, char **itemlist, int is_uid) {
70 * We haven't written the search command logic yet. Instead we
71 * simply return every message as valid. This will probably surprise
72 * some users. Could someone out there please be the hero of the
73 * century and write this function?
78 * If the message meets the specified search criteria, output its
79 * sequence number *or* UID, depending on what the client wants.
82 if (is_uid) cprintf("%ld ", IMAP->msgids[seq-1]);
83 else cprintf("%d ", seq);
91 * imap_search() calls imap_do_search() to do its actual work, once it's
92 * validated and boiled down the request a bit.
94 void imap_do_search(int num_items, char **itemlist, int is_uid) {
96 struct CtdlMessage *msg;
99 if (IMAP->num_msgs > 0)
100 for (i = 0; i < IMAP->num_msgs; ++i)
101 if (IMAP->flags[i] && IMAP_SELECTED) {
102 msg = CtdlFetchMessage(IMAP->msgids[i]);
104 imap_do_search_msg(i+1, msg, num_items,
106 CtdlFreeMessage(msg);
109 lprintf(1, "SEARCH internal error\n");
117 * This function is called by the main command loop.
119 void imap_search(int num_parms, char *parms[]) {
126 cprintf("%s BAD invalid parameters\r\n", parms[0]);
130 for (i=1; i<num_parms; ++i) {
131 if (imap_is_message_set(parms[i])) {
132 imap_pick_range(parms[i], 0);
137 for (i=2; i<num_parms; ++i) {
138 strcat(items, parms[i]);
139 if (i < (num_parms-1)) strcat(items, " ");
142 num_items = imap_extract_data_items(itemlist, items);
144 cprintf("%s BAD invalid data item list\r\n", parms[0]);
148 imap_do_search(num_items, itemlist, 0);
149 cprintf("%s OK SEARCH completed\r\n", parms[0]);
153 * This function is called by the main command loop.
155 void imap_uidsearch(int num_parms, char *parms[]) {
162 cprintf("%s BAD invalid parameters\r\n", parms[0]);
166 for (i=1; i<num_parms; ++i) {
167 if (imap_is_message_set(parms[i])) {
168 imap_pick_range(parms[i], 1);
173 for (i=4; i<num_parms; ++i) {
174 strcat(items, parms[i]);
175 if (i < (num_parms-1)) strcat(items, " ");
178 num_items = imap_extract_data_items(itemlist, items);
180 cprintf("%s BAD invalid data item list\r\n", parms[0]);
184 imap_do_search(num_items, itemlist, 1);
185 cprintf("%s OK UID SEARCH completed\r\n", parms[0]);