* File the auto-generated vCards into the users' address books.
authorArt Cancro <ajc@citadel.org>
Sun, 18 Sep 2005 21:51:45 +0000 (21:51 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 18 Sep 2005 21:51:45 +0000 (21:51 +0000)
citadel/ChangeLog
citadel/msgbase.c
citadel/serv_vcard.c
citadel/vcard.c
citadel/vcard.h

index bd1cdf720225434226244184f59dbd542761d5c3..826f78e9794d3f9265e4b632afa8fff6421af0a4 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 655.11  2005/09/18 21:51:44  ajc
+* File the auto-generated vCards into the users' address books.
+
 Revision 655.10  2005/09/18 20:33:13  ajc
 * Now harvesting addresses, converting them to vCards, and storing them in
   the Aide> room.  All that's left to do now is file the messages in the
@@ -7153,3 +7156,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 e20faa973f387cc655e93160bc543beb6dbb9a38..d3d6f17904a7e56c5b38513c3866eb9349a659d3 100644 (file)
@@ -2036,13 +2036,17 @@ int ReplicationChecks(struct CtdlMessage *msg) {
  */
 struct vCard *vcard_new_from_rfc822_addr(char *addr) {
        struct vCard *v;
-       char user[256], node[256], name[256], email[256];
+       char user[256], node[256], name[256], email[256], n[256];
 
        v = vcard_new();
        if (v == NULL) return(NULL);
 
        process_rfc822_addr(addr, user, node, name);
        vcard_set_prop(v, "fn", name, 0);
+
+       vcard_fn_to_n(n, name, sizeof n);
+       vcard_set_prop(v, "n", n, 0);
+
        snprintf(email, sizeof email, "%s@%s", user, node);
        vcard_set_prop(v, "email;internet", email, 0);
 
@@ -2067,12 +2071,13 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
        long newmsgid;
        char *mptr = NULL;
        struct ctdluser userbuf;
-       int a, i;
+       int a, i, j;
        struct MetaData smi;
        FILE *network_fp = NULL;
        static int seqnum = 1;
        struct CtdlMessage *imsg = NULL;
        struct CtdlMessage *vmsg = NULL;
+       long vmsgnum = (-1L);
        char *ser = NULL;
        struct vCard *v = NULL;
        char *instr;
@@ -2413,7 +2418,28 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,      /* message to save */
                                        free(ser);
                                }
                                vcard_free(v);
-                               CtdlSubmitMsg(vmsg, NULL, "Aide");      /* FIXME */
+
+                               if (recps->num_local > 0) {
+                                       for (j=0; j<num_tokens(recps->recp_local, '|'); ++j) {
+                                               extract_token(recipient, recps->recp_local, j,
+                                                       '|', sizeof recipient);
+                                               lprintf(CTDL_DEBUG, "Adding contact for <%s>\n", recipient);
+                                               if (getuser(&userbuf, recipient) == 0) {
+                                                       MailboxName(actual_rm, sizeof actual_rm,
+                                                               &userbuf, USERCONTACTSROOM);
+
+                                                       if (vmsgnum < 0L) {
+                                                               vmsgnum = CtdlSubmitMsg(vmsg,
+                                                                                       NULL, actual_rm);
+                                                       }
+                                                       else {
+                                                               CtdlSaveMsgPointerInRoom(actual_rm,
+                                                                                               vmsgnum, 0);
+                                                       }
+
+                                               }
+                                       }
+                               }
                                CtdlFreeMessage(vmsg);
                        }
                }
index 25b561d9cd1d324cd725bc146fab8c8660cf1533..a586fdfe39bc97d6c5a957363f2dab0c2021ffec 100644 (file)
@@ -707,65 +707,17 @@ void cmd_greg(char *argbuf)
 }
 
 
+
 /*
  * When a user is being created, create his/her vCard.
  */
 void vcard_newuser(struct ctdluser *usbuf) {
-       char buf[256];
        char vname[256];
-
-       char lastname[256];
-       char firstname[256];
-       char middlename[256];
-       char honorific_prefixes[256];
-       char honorific_suffixes[256];
-
-       struct vCard *v;
+       char buf[256];
        int i;
+       struct vCard *v;
 
-       /* Try to intelligently convert the screen name to a
-        * fully expanded vCard name based on the number of
-        * words in the name
-        */
-       safestrncpy(lastname, "", sizeof lastname);
-       safestrncpy(firstname, "", sizeof firstname);
-       safestrncpy(middlename, "", sizeof middlename);
-       safestrncpy(honorific_prefixes, "", sizeof honorific_prefixes);
-       safestrncpy(honorific_suffixes, "", sizeof honorific_suffixes);
-
-       safestrncpy(buf, usbuf->fullname, sizeof buf);
-
-       /* Honorific suffixes */
-       if (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), ' ', sizeof lastname);
-       remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
-
-       /* Find honorific prefixes */
-       if (num_tokens(buf, ' ') > 2) {
-               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), ' ', sizeof middlename);
-               remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
-       }
-
-       /* Anything left is probably the first name */
-       safestrncpy(firstname, buf, sizeof firstname);
-       striplt(firstname);
-
-       /* Compose the structured name */
-       snprintf(vname, sizeof vname, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
-               honorific_prefixes, honorific_suffixes);
-
+       vcard_fn_to_n(vname, usbuf->fullname, sizeof vname);
        lprintf(CTDL_DEBUG, "Converted <%s> to <%s>\n", usbuf->fullname, vname);
 
        /* Create and save the vCard */
index d9b9c7e21a68b03f6d447d4d8f1079c971718ba7..26bb455c408ef776ba017aedefefe850afa0c79a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * vCard implementation for Citadel
  *
- * Copyright (C) 1999 by Art Cancro
+ * Copyright (C) 1999-2005 by Art Cancro
  * This code is freely redistributable under the terms of the GNU General
  * Public License.  All other rights reserved.
  */
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
+#include <string.h>
 
 #include "citadel.h"
 #include "server.h"
 #include "support.h"
 #include "vcard.h"
+#include "tools.h"
 
 /* 
  * Constructor (empty vCard)
@@ -262,3 +264,64 @@ char *vcard_serialize(struct vCard *v)
 
        return ser;
 }
+
+
+
+/*
+ * Convert FN (Friendly Name) into N (Name)
+ */
+void vcard_fn_to_n(char *vname, char *n, size_t vname_size) {
+       char lastname[256];
+       char firstname[256];
+       char middlename[256];
+       char honorific_prefixes[256];
+       char honorific_suffixes[256];
+       char buf[256];
+
+       safestrncpy(buf, n, sizeof buf);
+
+       /* Try to intelligently convert the screen name to a
+        * fully expanded vCard name based on the number of
+        * words in the name
+        */
+       safestrncpy(lastname, "", sizeof lastname);
+       safestrncpy(firstname, "", sizeof firstname);
+       safestrncpy(middlename, "", sizeof middlename);
+       safestrncpy(honorific_prefixes, "", sizeof honorific_prefixes);
+       safestrncpy(honorific_suffixes, "", sizeof honorific_suffixes);
+
+       /* Honorific suffixes */
+       if (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), ' ', sizeof lastname);
+       remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
+
+       /* Find honorific prefixes */
+       if (num_tokens(buf, ' ') > 2) {
+               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), ' ', sizeof middlename);
+               remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
+       }
+
+       /* Anything left is probably the first name */
+       safestrncpy(firstname, buf, sizeof firstname);
+       striplt(firstname);
+
+       /* Compose the structured name */
+       snprintf(vname, vname_size, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
+               honorific_prefixes, honorific_suffixes);
+}
+
+
+
+
index e62e7aeae697029cacfb1504c0ff2406093f41df..077c34345853ee1331ae453705c6bddf2f469717 100644 (file)
@@ -32,3 +32,4 @@ void vcard_set_prop(struct vCard *v, char *name, char *value, int append);
 char *vcard_get_prop(struct vCard *v, char *propname, int is_partial,
                        int instance, int return_propname);
 char *vcard_serialize(struct vCard *);
+void vcard_fn_to_n(char *vname, char *n, size_t vname_size);