4 * Autocompletion of email recipients, etc.
20 #include <sys/types.h>
22 #if TIME_WITH_SYS_TIME
23 # include <sys/time.h>
27 # include <sys/time.h>
38 #include "serv_extensions.h"
39 #include "sysdep_decls.h"
40 #include "citserver.h"
49 #include "serv_autocompletion.h"
58 * Back end for cmd_auto()
60 void hunt_for_autocomplete(long msgnum, void *data) {
62 struct CtdlMessage *msg;
65 search_string = (char *) data;
67 msg = CtdlFetchMessage(msgnum, 1);
68 if (msg == NULL) return;
70 v = vcard_load(msg->cm_fields['M']);
74 * Try to match from a display name or something like that
77 (bmstrcasestr(vcard_get_prop(v, "n", 0, 0, 0), search_string))
79 cprintf("%s\n", vcard_get_prop(v, "email", 1, 0, 0));
88 * Attempt to autocomplete an address based on a partial...
90 void cmd_auto(char *argbuf) {
91 char hold_rm[ROOMNAMELEN];
92 char search_string[256];
94 if (CtdlAccessCheck(ac_logged_in)) return;
95 extract_token(search_string, argbuf, 0, '|', sizeof search_string);
96 if (strlen(search_string) == 0) {
97 cprintf("%d You supplied an empty partial.\n", ERROR + ILLEGAL_VALUE);
101 strcpy(hold_rm, CC->room.QRname); /* save current room */
103 if (getroom(&CC->room, USERCONTACTSROOM) != 0) {
104 getroom(&CC->room, hold_rm);
105 lprintf(CTDL_CRIT, "cannot get user contacts room\n");
106 cprintf("%d Your address book was not found.\n", ERROR + ROOM_NOT_FOUND);
110 cprintf("%d try these:\n", LISTING_FOLLOWS);
111 CtdlForEachMessage(MSGS_ALL, 0, "text/x-vcard", NULL, hunt_for_autocomplete, search_string);
114 getroom(&CC->room, hold_rm); /* return to saved room */
118 char *serv_autocompletion_init(void)
120 CtdlRegisterProtoHook(cmd_auto, "AUTO", "Perform recipient autocompletion");