#include "user_ops.h"
#include "room_ops.h"
#include "parsedate.h"
+#include "database.h"
#ifndef HAVE_SNPRINTF
* DIRECTORY MANAGEMENT FUNCTIONS *
*****************************************************************************/
+/*
+ * Generate the index key for an Internet e-mail address to be looked up
+ * in the database.
+ */
+void directory_key(char *key, char *addr) {
+ int i;
+ int keylen = 0;
+
+ for (i=0; i<strlen(addr); ++i) {
+ if (!isspace(addr[i])) {
+ key[keylen++] = tolower(addr[i]);
+ }
+ }
+ key[keylen++] = 0;
+}
+
+
/* Return nonzero if the supplied address is in a domain we keep in
* the directory
* Add an Internet e-mail address to the directory for a user
*/
void CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
+ char key[SIZ];
lprintf(9, "Dir: %s --> %s\n",
internet_addr, citadel_addr);
if (IsDirectory(internet_addr) == 0) return;
- lprintf(9, "** FIXME write to db\n");
- /* FIXME ... write this */
+ directory_key(key, internet_addr);
+ cdb_store(CDB_DIRECTORY, key, strlen(key),
+ citadel_addr, strlen(citadel_addr)+1 );
}
* Delete an Internet e-mail address from the directory
*/
void CtdlDirectoryDelUser(char *internet_addr) {
- /* FIXME ... write this */
+ char key[SIZ];
+
+ directory_key(key, internet_addr);
+ cdb_delete(CDB_DIRECTORY, key, strlen(key) );
}
* On failure: returns nonzero
*/
int CtdlDirectoryLookup(char *target, char *internet_addr) {
+ struct cdbdata *cdbrec;
+ char key[SIZ];
if (IsDirectory(internet_addr) == 0) return(-1);
- /* FIXME ... write this */
+ directory_key(key, internet_addr);
+ cdbrec = cdb_fetch(CDB_DIRECTORY, key, strlen(key) );
+ if (cdbrec != NULL) {
+ safestrncpy(target, cdbrec->ptr, SIZ);
+ cdb_free(cdbrec);
+ return(0);
+ }
+
return(-1);
}
char testnode[SIZ];
char buf[SIZ];
+ striplt(name);
remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
fp = fopen("network/mail.aliases", "r");
}
}
- /* determine local or remote type, see citadel.h */
+ /* Hit the Global Address Book */
+ if (CtdlDirectoryLookup(aaa, name) == 0) {
+ strcpy(name, aaa);
+ }
+ /* determine local or remote type, see citadel.h */
at = haschar(name, '@');
if (at == 0) return(MES_LOCAL); /* no @'s - local address */
if (at > 1) return(MES_ERROR); /* >1 @'s - invalid address */
remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
/* figure out the delivery mode */
-
extract_token(node, name, 1, '@');
/* If there are one or more dots in the nodename, we assume that it
/*
* Back end function for cmd_igab()
- * FIXME use a callback that actually writes to the database, dumbass...
*/
void vcard_add_to_directory(long msgnum, void *data) {
struct CtdlMessage *msg;
return;
}
- /* FIXME empty the existing database first. And don't be a
- * freakin' momo and dump addresses to the client. We want to write
- * the harvested addresses into the database and send an OK to the
- * client when finished.
+ /* Empty the existing database first.
*/
-
- cprintf("%d Directory will be rebuilt\n", OK);
+ CtdlDirectoryInit();
/* We want the last (and probably only) vcard in this room */
CtdlForEachMessage(MSGS_ALL, 0, (-127), "text/x-vcard",
NULL, vcard_add_to_directory, NULL);
getroom(&CC->quickroom, hold_rm); /* return to saved room */
+ cprintf("%d Directory has been rebuilt.\n", OK);
}