#include "tools.h"
#include "vcard.h"
#include "serv_ldap.h"
+#include "serv_vcard.h"
/*
* set global flag calling for an aide to validate new users
/*
* See if there is a valid Internet address in a vCard to use for outbound
- * Internet messages. If there is, stick it in CC->cs_inet_email.
+ * Internet messages. If there is, stick it in the buffer.
*/
-void vcard_populate_cs_inet_email(struct vCard *v) {
+void extract_primary_inet_email(char *emailaddrbuf, size_t emailaddrbuf_len, struct vCard *v) {
char *s, *addr;
int continue_searching = 1;
int instance = 0;
if (strlen(addr) > 0) {
if (IsDirectory(addr)) {
continue_searching = 0;
- safestrncpy(CC->cs_inet_email,
- addr,
- sizeof(CC->cs_inet_email)
- );
+ safestrncpy(emailaddrbuf, addr,
+ emailaddrbuf_len);
}
}
free(addr);
/* Store our Internet return address in memory */
v = vcard_load(msg->cm_fields['M']);
- vcard_populate_cs_inet_email(v);
+ extract_primary_inet_email(CC->cs_inet_email,
+ sizeof CC->cs_inet_email, v);
vcard_free(v);
/* Put it in the Global Address Book room... */
FILE *fp;
char *ser;
- strcpy(temp, tmpnam(NULL));
+ CtdlMakeTempFileName(temp, sizeof temp);
ser = vcard_serialize(v);
fp = fopen(temp, "w");
struct vCard *v;
v = vcard_get_user(&CC->user);
- vcard_populate_cs_inet_email(v);
-
+ extract_primary_inet_email(CC->cs_inet_email,
+ sizeof CC->cs_inet_email, v);
vcard_free(v);
vcard_create_room();
}
+/*
+ * Function to output a vCard as plain text. Nobody uses MSG0 anymore, so
+ * really this is just so we expose the vCard data to the full text indexer.
+ */
+void vcard_fixed_output(char *ptr, int len) {
+ char *serialized_vcard;
+ struct vCard *v;
+ char *key, *value;
+ int i = 0;
+
+ cprintf("vCard:\n");
+ serialized_vcard = malloc(len + 1);
+ safestrncpy(serialized_vcard, ptr, len+1);
+ v = vcard_load(serialized_vcard);
+ free(serialized_vcard);
+
+ i = 0;
+ while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
+ value = vcard_get_prop(v, "", 0, i++, 0);
+ cprintf("%20s : %s\n", key, value);
+ }
+
+ vcard_free(v);
+}
+
+
+
char *serv_vcard_init(void)
{
struct ctdlroom qr;
CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER);
CtdlRegisterNetprocHook(vcard_extract_from_network);
CtdlRegisterSessionHook(store_harvested_addresses, EVT_TIMER);
+ CtdlRegisterFixedOutputHook("text/x-vcard", vcard_fixed_output);
/* Create the Global ADdress Book room if necessary */
create_room(ADDRESS_BOOK_ROOM, 3, "", 0, 1, 0, VIEW_ADDRESSBOOK);