* Cc: and Bcc: support. Not finished yet.
[citadel.git] / citadel / serv_vcard.c
index 5dd95868fceee53ad929d75178303c55cea90062..fd197c16e8b9c65be10d3fbbfd27127e95b4a4c7 100644 (file)
@@ -7,13 +7,6 @@
  * Copyright (c) 1999-2002 / released under the GNU General Public License
  */
 
-/*
- * Where we keep messages containing the vCards that source our directory.  It
- * makes no sense to change this, because you'd have to change it on every
- * system on the network.  That would be stupid.
- */
-#define ADDRESS_BOOK_ROOM      "Global Address Book"
-
 /*
  * Format of the "Exclusive ID" field of the message containing a user's
  * vCard.  Doesn't matter what it really looks like as long as it's both
@@ -128,7 +121,6 @@ void vcard_extract_internet_addresses(struct CtdlMessage *msg,
 /*
  * Callback for vcard_add_to_directory()
  * (Lotsa ugly nested callbacks.  Oh well.)
- * This little shim function makes sure we're not 
  */
 void vcard_directory_add_user(char *internet_addr, char *citadel_addr) {
        char buf[SIZ];
@@ -139,7 +131,7 @@ void vcard_directory_add_user(char *internet_addr, char *citadel_addr) {
         */
        if (CC->logged_in) {
                lprintf(CTDL_DEBUG, "Checking for <%s>...\n", internet_addr);
-               if (CtdlDirectoryLookup(buf, internet_addr) == 0) {
+               if (CtdlDirectoryLookup(buf, internet_addr, sizeof buf) == 0) {
                        if (strcasecmp(buf, citadel_addr)) {
                                /* This address belongs to someone else.
                                 * Bail out silently without saving.
@@ -323,7 +315,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                                 * vCard in the user's config room at all times.
                                 */
                                CtdlDeleteMessages(CC->room.QRname,
-                                               0L, "text/x-vcard");
+                                               0L, "text/x-vcard", 1);
 
                                /* Make the author of the message the name of the user.
                                 */
@@ -368,7 +360,6 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
 
                                /* 
                                 * Set the EUID of the message to the UID of the vCard.
-                                * Also set the Subject if there isn't already one.
                                 */
                                if (msg->cm_fields['E'] != NULL) free(msg->cm_fields['E']);
                                s = vcard_get_prop(v, "UID", 0, 0, 0);
@@ -379,6 +370,20 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                                        }
                                }
 
+                               /*
+                                * Set the Subject to the name in the vCard.
+                                */
+                               s = vcard_get_prop(v, "FN", 0, 0, 0);
+                               if (s == NULL) {
+                                       s = vcard_get_prop(v, "N", 0, 0, 0);
+                               }
+                               if (s != NULL) {
+                                       if (msg->cm_fields['U'] != NULL) {
+                                               free(msg->cm_fields['U']);
+                                       }
+                                       msg->cm_fields['U'] = strdup(s);
+                               }
+
                                /* Re-serialize it back into the msg body */
                                ser = vcard_serialize(v);
                                if (ser != NULL) {
@@ -636,11 +641,11 @@ void cmd_greg(char *argbuf)
        struct ctdluser usbuf;
        struct vCard *v;
        char *s;
-       char who[SIZ];
-       char adr[SIZ];
-       char buf[SIZ];
+       char who[USERNAME_SIZE];
+       char adr[256];
+       char buf[256];
 
-       extract(who, argbuf, 0);
+       extract_token(who, argbuf, 0, '|', sizeof who);
 
        if (!(CC->logged_in)) {
                cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
@@ -671,13 +676,13 @@ void cmd_greg(char *argbuf)
        s = vcard_get_prop(v, "adr", 0, 0, 0);
        snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
 
-       extract_token(buf, adr, 2, ';');
+       extract_token(buf, adr, 2, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* street */
-       extract_token(buf, adr, 3, ';');
+       extract_token(buf, adr, 3, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* city */
-       extract_token(buf, adr, 4, ';');
+       extract_token(buf, adr, 4, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* state */
-       extract_token(buf, adr, 5, ';');
+       extract_token(buf, adr, 5, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* zip */
 
        s = vcard_get_prop(v, "tel;home", 0, 0, 0);
@@ -696,7 +701,7 @@ void cmd_greg(char *argbuf)
        s = vcard_get_prop(v, "adr", 0, 0, 0);
        snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
 
-       extract_token(buf, adr, 6, ';');
+       extract_token(buf, adr, 6, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* country */
        cprintf("000\n");
 }
@@ -706,14 +711,14 @@ void cmd_greg(char *argbuf)
  * When a user is being created, create his/her vCard.
  */
 void vcard_newuser(struct ctdluser *usbuf) {
-       char buf[SIZ];
-       char vname[SIZ];
+       char buf[256];
+       char vname[256];
 
-       char lastname[SIZ];
-       char firstname[SIZ];
-       char middlename[SIZ];
-       char honorific_prefixes[SIZ];
-       char honorific_suffixes[SIZ];
+       char lastname[256];
+       char firstname[256];
+       char middlename[256];
+       char honorific_prefixes[256];
+       char honorific_suffixes[256];
 
        struct vCard *v;
        int i;
@@ -722,42 +727,43 @@ void vcard_newuser(struct ctdluser *usbuf) {
         * fully expanded vCard name based on the number of
         * words in the name
         */
-       strcpy(lastname, "");
-       strcpy(firstname, "");
-       strcpy(middlename, "");
-       strcpy(honorific_prefixes, "");
-       strcpy(honorific_suffixes, "");
+       safestrncpy(lastname, "", sizeof lastname);
+       safestrncpy(firstname, "", sizeof firstname);
+       safestrncpy(middlename, "", sizeof middlename);
+       safestrncpy(honorific_prefixes, "", sizeof honorific_prefixes);
+       safestrncpy(honorific_suffixes, "", sizeof honorific_suffixes);
 
-       strcpy(buf, usbuf->fullname);
+       safestrncpy(buf, usbuf->fullname, sizeof buf);
 
        /* Honorific suffixes */
        if (num_tokens(buf, ',') > 1) {
-               extract_token(honorific_suffixes, buf, (num_tokens(buf, ' ') - 1), ',');
+               extract_token(honorific_suffixes, buf, (num_tokens(buf, ' ') - 1), ',',
+                       sizeof honorific_suffixes);
                remove_token(buf, (num_tokens(buf, ',') - 1), ',');
        }
 
        /* Find a last name */
-       extract_token(lastname, buf, (num_tokens(buf, ' ') - 1), ' ');
+       extract_token(lastname, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof lastname);
        remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
 
        /* Find honorific prefixes */
        if (num_tokens(buf, ' ') > 2) {
-               extract_token(honorific_prefixes, buf, 0, ' ');
+               extract_token(honorific_prefixes, buf, 0, ' ', sizeof honorific_prefixes);
                remove_token(buf, 0, ' ');
        }
 
        /* Find a middle name */
        if (num_tokens(buf, ' ') > 1) {
-               extract_token(middlename, buf, (num_tokens(buf, ' ') - 1), ' ');
+               extract_token(middlename, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof middlename);
                remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
        }
 
        /* Anything left is probably the first name */
-       strcpy(firstname, buf);
+       safestrncpy(firstname, buf, sizeof firstname);
        striplt(firstname);
 
        /* Compose the structured name */
-       sprintf(vname, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
+       snprintf(vname, sizeof vname, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
                honorific_prefixes, honorific_suffixes);
 
        lprintf(CTDL_DEBUG, "Converted <%s> to <%s>\n", usbuf->fullname, vname);
@@ -805,7 +811,7 @@ void vcard_purge(struct ctdluser *usbuf) {
 
        msg->cm_fields['S'] = strdup("CANCEL");
 
-        CtdlSubmitMsg(msg, NULL, ADDRESS_BOOK_ROOM);
+        CtdlSubmitMsg(msg, NULL, NULL, NULL, ADDRESS_BOOK_ROOM);
         CtdlFreeMessage(msg);
 }
 
@@ -894,14 +900,14 @@ EOH:      CtdlFreeMessage(msg);
  * Query Directory
  */
 void cmd_qdir(char *argbuf) {
-       char citadel_addr[SIZ];
-       char internet_addr[SIZ];
+       char citadel_addr[256];
+       char internet_addr[256];
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
-       extract(internet_addr, argbuf, 0);
+       extract_token(internet_addr, argbuf, 0, '|', sizeof internet_addr);
 
-       if (CtdlDirectoryLookup(citadel_addr, internet_addr) != 0) {
+       if (CtdlDirectoryLookup(citadel_addr, internet_addr, sizeof citadel_addr) != 0) {
                cprintf("%d %s was not found.\n",
                        ERROR + NO_SUCH_USER, internet_addr);
                return;