* More code for the Global Address Book
authorArt Cancro <ajc@citadel.org>
Fri, 11 Jan 2002 04:37:04 +0000 (04:37 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 11 Jan 2002 04:37:04 +0000 (04:37 +0000)
citadel/ChangeLog
citadel/internet_addressing.c
citadel/msgbase.c
citadel/serv_vcard.c

index 84ec5ef5f3d10ce187dfe4b5b26bfb959ef9df52..b42f4f9546f908b80a429c8c626348dea24c233b 100644 (file)
@@ -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 <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
index 4e634006de361707aeeb45db7c17cf4949705f43..4b803096c697db6c76fba1f587a49ac42714c2ac 100644 (file)
@@ -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<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
@@ -673,14 +691,16 @@ void CtdlDirectoryInit(void) {
  * 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 );
 }
 
 
@@ -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);
 }
index b1b9884fc746bed0fef61b695e0026593c176e7a..f13e75aac6fda049f025e04f5da6ed6769c3a758 100644 (file)
@@ -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
index 36f4b2316cb2ad9a63af636df1b3fa86913bc25e..8fb21d976b65aa746df1cc93215c0b47511f54b5 100644 (file)
@@ -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);
 }