From 7f22c47809a3e10566f791acb7e6cb52197e6626 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 27 Dec 2000 05:09:58 +0000 Subject: [PATCH] * Added a skeleton IMAP "SEARCH" command (based on the FETCH logic) --- citadel/ChangeLog | 4 + citadel/Makefile.in | 9 ++- citadel/imap_fetch.c | 8 +- citadel/imap_fetch.h | 2 + citadel/imap_search.c | 165 ++++++++++++++++++++++++++++++++++++++++++ citadel/imap_search.h | 7 ++ citadel/serv_imap.c | 10 +++ 7 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 citadel/imap_search.c create mode 100644 citadel/imap_search.h diff --git a/citadel/ChangeLog b/citadel/ChangeLog index fcf957f36..a1f0afc01 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 573.58 2000/12/27 05:09:58 ajc + * Added a skeleton IMAP "SEARCH" command (based on the FETCH logic) + Revision 573.57 2000/12/26 03:46:50 ajc * More IMAP tweaks @@ -2245,3 +2248,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/Makefile.in b/citadel/Makefile.in index 6d6ac0e51..c32cd5bdc 100644 --- a/citadel/Makefile.in +++ b/citadel/Makefile.in @@ -90,7 +90,7 @@ SOURCES=aidepost.c citadel.c citmail.c citserver.c client_chat.c commands.c \ serv_smtp.c serv_pop3.c internet_addressing.c parsedate.c genstamp.c \ domain.c clientsocket.c serv_inetcfg.c serv_rwho.c serv_bio.c \ serv_moderate.c client_passwords.c \ - serv_imap.c imap_tools.c imap_fetch.c \ + serv_imap.c imap_tools.c imap_fetch.c imap_search.c \ serv_network.c serv_pas2.c md5.c DEP_FILES=$(SOURCES:.c=.d) @@ -234,9 +234,9 @@ modules/serv_smtp.mo: serv_smtp.mo modules/domain.mo: domain.mo ln -f domain.mo modules -modules/serv_imap.so: serv_imap.mo imap_tools.mo imap_fetch.mo +modules/serv_imap.so: serv_imap.mo imap_tools.mo imap_fetch.mo imap_search.mo $(LINK_SHARED) -o modules/serv_imap.so imap_tools.mo serv_imap.mo \ - imap_fetch.mo + imap_fetch.mo imap_search.mo modules/serv_imap.mo: serv_imap.mo ln -f serv_imap.mo modules @@ -247,6 +247,9 @@ modules/imap_tools.mo: imap_tools.mo modules/imap_fetch.mo: imap_fetch.mo ln -f imap_fetch.mo modules +modules/imap_search.mo: imap_search.mo + ln -f imap_search.mo modules + aidepost: aidepost.o config.o $(LIBOBJS) $(CC) aidepost.o config.o $(LIBOBJS) $(LDFLAGS) -o aidepost diff --git a/citadel/imap_fetch.c b/citadel/imap_fetch.c index 5bfc50520..e97704866 100644 --- a/citadel/imap_fetch.c +++ b/citadel/imap_fetch.c @@ -735,6 +735,10 @@ void imap_pick_range(char *range, int is_uid) { int s; char setstr[1024], lostr[1024], histr[1024]; int lo, hi; + char *actual_range; + + actual_range = range; + if (!strcasecmp(range, "ALL")) actual_range = "1:*"; /* * Clear out the IMAP_FETCHED flags for all messages. @@ -746,9 +750,9 @@ void imap_pick_range(char *range, int is_uid) { /* * Now set it for all specified messages. */ - num_sets = num_tokens(range, ','); + num_sets = num_tokens(actual_range, ','); for (s=0; s= 2) { diff --git a/citadel/imap_fetch.h b/citadel/imap_fetch.h index 31c2dd9ef..b3f80dfc9 100644 --- a/citadel/imap_fetch.h +++ b/citadel/imap_fetch.h @@ -3,5 +3,7 @@ * */ +void imap_pick_range(char *range, int is_uid); void imap_fetch(int num_parms, char *parms[]); void imap_uidfetch(int num_parms, char *parms[]); +int imap_extract_data_items(char **argv, char *items); diff --git a/citadel/imap_search.c b/citadel/imap_search.c new file mode 100644 index 000000000..065e4ad92 --- /dev/null +++ b/citadel/imap_search.c @@ -0,0 +1,165 @@ +/* + * $Id$ + * + * Implements the SEARCH command in IMAP. + * This command is way too convoluted. Marc Crispin is a fscking idiot. + * + */ + + +#include "sysdep.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "citadel.h" +#include "server.h" +#include +#include "sysdep_decls.h" +#include "citserver.h" +#include "support.h" +#include "config.h" +#include "dynloader.h" +#include "room_ops.h" +#include "user_ops.h" +#include "policy.h" +#include "database.h" +#include "msgbase.h" +#include "tools.h" +#include "internet_addressing.h" +#include "mime_parser.h" +#include "serv_imap.h" +#include "imap_tools.h" +#include "imap_fetch.h" +#include "imap_search.h" +#include "genstamp.h" + + + + + + +/* + * imap_do_search() calls imap_do_search_msg() to output the deta of an + * individual message, once it has been successfully loaded from disk. + */ +void imap_do_search_msg(int seq, struct CtdlMessage *msg, + int num_items, char **itemlist, int is_uid) { + + int is_valid = 0; + + is_valid = 1; /* FIXME ... replace with a real test */ + + /* + * If the message meets the specified search criteria, output its + * sequence number *or* UID, depending on what the client wants. + */ + if (is_valid) { + if (is_uid) cprintf("%ld ", IMAP->msgids[seq-1]); + else cprintf("%d ", seq); + } + +} + + + +/* + * imap_search() calls imap_do_search() to do its actual work, once it's + * validated and boiled down the request a bit. + */ +void imap_do_search(int num_items, char **itemlist, int is_uid) { + int i; + struct CtdlMessage *msg; + + cprintf("* SEARCH "); + if (IMAP->num_msgs > 0) + for (i = 0; i < IMAP->num_msgs; ++i) + if (IMAP->flags[i] && IMAP_FETCHED) { + msg = CtdlFetchMessage(IMAP->msgids[i]); + if (msg != NULL) { + imap_do_search_msg(i+1, msg, num_items, + itemlist, is_uid); + CtdlFreeMessage(msg); + } + else { + lprintf(1, "SEARCH internal error\n"); + } + } + cprintf("\r\n"); +} + + +/* + * This function is called by the main command loop. + */ +void imap_search(int num_parms, char *parms[]) { + char items[1024]; + char *itemlist[256]; + int num_items; + int i; + + if (num_parms < 4) { + cprintf("%s BAD invalid parameters\r\n", parms[0]); + return; + } + + imap_pick_range(parms[2], 0); + + strcpy(items, ""); + for (i=3; i