From f582ce612a254f8e55275c56335d2a234aab8170 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 11 Jan 2002 04:37:04 +0000 Subject: [PATCH] * More code for the Global Address Book --- citadel/ChangeLog | 4 ++++ citadel/internet_addressing.c | 40 +++++++++++++++++++++++++++++++---- citadel/msgbase.c | 8 +++++-- citadel/serv_vcard.c | 10 +++------ 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 84ec5ef5f..b42f4f954 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 590.55 2002/01/11 04:37:03 ajc + * More code for the Global Address Book + Revision 590.54 2002/01/11 02:57:35 error * Don't print **** when sending a page or mail from an anonymous-only room @@ -3130,3 +3133,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index 4e634006d..4b803096c 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -47,6 +47,7 @@ #include "user_ops.h" #include "room_ops.h" #include "parsedate.h" +#include "database.h" #ifndef HAVE_SNPRINTF @@ -639,6 +640,23 @@ char *rfc822_fetch_field(char *rfc822, char *fieldname) { * 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 %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 ); } @@ -688,7 +708,10 @@ void CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) { * 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) ); } @@ -698,9 +721,18 @@ void CtdlDirectoryDelUser(char *internet_addr) { * 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); } diff --git a/citadel/msgbase.c b/citadel/msgbase.c index b1b9884fc..f13e75aac 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -131,6 +131,7 @@ int alias(char *name) 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"); @@ -169,15 +170,18 @@ int alias(char *name) } } - /* 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 diff --git a/citadel/serv_vcard.c b/citadel/serv_vcard.c index 36f4b2316..8fb21d976 100644 --- a/citadel/serv_vcard.c +++ b/citadel/serv_vcard.c @@ -109,7 +109,6 @@ void vcard_extract_internet_addresses(struct CtdlMessage *msg, /* * 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; @@ -139,19 +138,16 @@ void cmd_igab(char *argbuf) { 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); } -- 2.39.2