* Now harvesting addresses, converting them to vCards, and storing them in
authorArt Cancro <ajc@citadel.org>
Sun, 18 Sep 2005 20:33:13 +0000 (20:33 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 18 Sep 2005 20:33:13 +0000 (20:33 +0000)
  the Aide> room.  All that's left to do now is file the messages in the
  appropriate users' address books.

citadel/ChangeLog
citadel/msgbase.c
citadel/sysconfig.h

index 0722424db739cf222f7142b2ff20575c7a40fd8b..bd1cdf720225434226244184f59dbd542761d5c3 100644 (file)
@@ -1,4 +1,9 @@
 $Log$
+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
+  appropriate users' address books.
+
 Revision 655.9  2005/09/18 19:34:26  ajc
 * When submitting a message, harvest non-local addresses for potential
   inclusion in a user's Collected Addresses book.  Note: we don't actually
@@ -7148,4 +7153,3 @@ 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 59c11abb8c330744587c22165d632f4b668c9910..e20faa973f387cc655e93160bc543beb6dbb9a38 100644 (file)
@@ -52,6 +52,7 @@
 #include "genstamp.h"
 #include "internet_addressing.h"
 #include "serv_fulltext.h"
+#include "vcard.h"
 
 long config_msgnum;
 
@@ -2029,6 +2030,26 @@ int ReplicationChecks(struct CtdlMessage *msg) {
 
 
 
+/* 
+ * Turn an arbitrary RFC822 address into a struct vCard for possible
+ * inclusion into an address book.
+ */
+struct vCard *vcard_new_from_rfc822_addr(char *addr) {
+       struct vCard *v;
+       char user[256], node[256], name[256], email[256];
+
+       v = vcard_new();
+       if (v == NULL) return(NULL);
+
+       process_rfc822_addr(addr, user, node, name);
+       vcard_set_prop(v, "fn", name, 0);
+       snprintf(email, sizeof email, "%s@%s", user, node);
+       vcard_set_prop(v, "email;internet", email, 0);
+
+       return(v);
+}
+
+
 /*
  * Save a message to disk and submit it into the delivery system.
  */
@@ -2051,6 +2072,9 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
        FILE *network_fp = NULL;
        static int seqnum = 1;
        struct CtdlMessage *imsg = NULL;
+       struct CtdlMessage *vmsg = NULL;
+       char *ser = NULL;
+       struct vCard *v = NULL;
        char *instr;
        struct ser_ret smr;
        char *hold_R, *hold_D;
@@ -2357,14 +2381,44 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
        }
 
        /*
-        * Any addresses to collect?  (FIXME do something with them!!)
+        * Any addresses to harvest for someone's address book?
+        * (Don't do this if this is not a message with recipients, otherwise we will
+        * send this function into infinite recursion!!!!!)
         */
-       collected_addresses = harvest_collected_addresses(msg);
+       if (recps != NULL) {
+               collected_addresses = harvest_collected_addresses(msg);
+       }
+
        if (collected_addresses != NULL) {
-               lprintf(CTDL_DEBUG, "FIXME collected addresses: %s\n", collected_addresses);
+               for (i=0; i<num_tokens(collected_addresses, ','); ++i) {
+
+                       /* Make a vCard out of each address */
+                       extract_token(recipient, collected_addresses, i, ',', sizeof recipient);
+                       striplt(recipient);
+                       v = vcard_new_from_rfc822_addr(recipient);
+                       if (v != NULL) {
+                               vmsg = malloc(sizeof(struct CtdlMessage));
+                               memset(vmsg, 0, sizeof(struct CtdlMessage));
+                               vmsg->cm_magic = CTDLMESSAGE_MAGIC;
+                               vmsg->cm_anon_type = MES_NORMAL;
+                               vmsg->cm_format_type = FMT_RFC822;
+                               vmsg->cm_fields['A'] = strdup("Citadel");
+                               vmsg->cm_fields['E'] = strdup(recipient);       /* this handles dups */
+                               ser = vcard_serialize(v);
+                               if (ser != NULL) {
+                                       vmsg->cm_fields['M'] = malloc(strlen(ser) + 1024);
+                                       sprintf(vmsg->cm_fields['M'],
+                                               "Content-type: text/x-vcard"
+                                               "\r\n\r\n%s\r\n", ser);
+                                       free(ser);
+                               }
+                               vcard_free(v);
+                               CtdlSubmitMsg(vmsg, NULL, "Aide");      /* FIXME */
+                               CtdlFreeMessage(vmsg);
+                       }
+               }
                free(collected_addresses);
        }
-
        return(newmsgid);
 }
 
@@ -3385,7 +3439,6 @@ void AdjRefCount(long msgnum, int incr)
 
        /* If the reference count is now zero, delete the message
         * (and its supplementary record as well).
-        * FIXME ... defer this so it doesn't keep the user waiting.
         */
        if (smi.meta_refcount == 0) {
                lprintf(CTDL_DEBUG, "Deleting message <%ld>\n", msgnum);
index 895dc41c97ea21a9e2cec152ad9f320d491b8a4b..545ddfee16a4139b471a83c3bf0ccab8aa49c562 100644 (file)
 #define USERCALENDARROOM       "Calendar"
 #define USERTASKSROOM          "Tasks"
 #define USERCONTACTSROOM       "Contacts"
-#define USERCOLLECTEDROOM      "Collected Addresses"
 #define USERNOTESROOM          "Notes"
 #define PAGELOGROOM            "Sent/Received Pages"
 #define SYSCONFIGROOM          "Local System Configuration"