CtdlDirectoryInit();
/* We want *all* vCards in this room */
- CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/x-vcard",
+ CtdlForEachMessage(MSGS_ALL, 0, NULL, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$",
NULL, vcard_add_to_directory, NULL);
getroom(&CC->room, hold_rm); /* return to saved room */
* See if there is a valid Internet address in a vCard to use for outbound
* Internet messages. If there is, stick it in the buffer.
*/
-void extract_primary_inet_email(char *emailaddrbuf, size_t emailaddrbuf_len, struct vCard *v) {
+void extract_inet_email_addrs(char *emailaddrbuf, size_t emailaddrbuf_len,
+ char *secemailaddrbuf, size_t secemailaddrbuf_len,
+ struct vCard *v) {
char *s, *addr;
- int continue_searching = 1;
int instance = 0;
+ int saved_instance = 0;
/* Go through the vCard searching for *all* instances of
* the "email;internet" key
*/
- do {
- s = vcard_get_prop(v, "email;internet", 0, instance++, 0);
- if (s != NULL) {
- continue_searching = 1;
- addr = strdup(s);
- striplt(addr);
- if (strlen(addr) > 0) {
- if (IsDirectory(addr)) {
- continue_searching = 0;
- safestrncpy(emailaddrbuf, addr,
- emailaddrbuf_len);
+ while (s = vcard_get_prop(v, "email;internet", 0, instance++, 0), s != NULL) {
+ addr = strdup(s);
+ striplt(addr);
+ if (strlen(addr) > 0) {
+ if (IsDirectory(addr)) {
+ ++saved_instance;
+ if ((saved_instance == 1) && (emailaddrbuf != NULL)) {
+ safestrncpy(emailaddrbuf, addr, emailaddrbuf_len);
+ }
+ else if ((saved_instance == 2) && (secemailaddrbuf != NULL)) {
+ safestrncpy(secemailaddrbuf, addr, secemailaddrbuf_len);
+ }
+ else if ((saved_instance > 2) && (secemailaddrbuf != NULL)) {
+ if ( (strlen(addr) + strlen(secemailaddrbuf) + 2)
+ < secemailaddrbuf_len ) {
+ strcat(secemailaddrbuf, "|");
+ strcat(secemailaddrbuf, addr);
+ }
}
}
- free(addr);
- }
- else {
- continue_searching = 0;
}
- } while(continue_searching);
+ free(addr);
+ }
}
* want to make sure there is absolutely only one
* vCard in the user's config room at all times.
*
- * FIXME also handle text/vcard by implementing regexp
*/
- CtdlDeleteMessages(CC->room.QRname, NULL, 0, "text/x-vcard");
+ CtdlDeleteMessages(CC->room.QRname, NULL, 0, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$");
/* Make the author of the message the name of the user. */
if (msg->cm_fields['A'] != NULL) {
if (ser != NULL) {
msg->cm_fields['M'] = realloc(msg->cm_fields['M'], strlen(ser) + 1024);
sprintf(msg->cm_fields['M'],
- "Content-type: text/x-vcard"
+ "Content-type: text/vcard"
"\r\n\r\n%s\r\n", ser);
free(ser);
}
linelen = strcspn(ptr, "\n");
if (linelen == 0) return(0); /* end of headers */
- if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
- /* Bingo! The user is uploading a new vCard, so
+ if ( (!strncasecmp(ptr, "Content-type: text/x-vcard", 26))
+ || (!strncasecmp(ptr, "Content-type: text/vcard", 24)) ) {
+ /*
+ * Bingo! The user is uploading a new vCard, so
* copy it to the Global Address Book room.
*/
/* Store our Internet return address in memory */
v = vcard_load(msg->cm_fields['M']);
- extract_primary_inet_email(CC->cs_inet_email, sizeof CC->cs_inet_email, v);
+ extract_inet_email_addrs(CC->cs_inet_email, sizeof CC->cs_inet_email,
+ CC->cs_inet_other_emails, sizeof CC->cs_inet_other_emails,
+ v);
extract_friendly_name(CC->cs_inet_fn, sizeof CC->cs_inet_fn, v);
vcard_free(v);
/* We want the last (and probably only) vcard in this room */
VCmsgnum = (-1);
- CtdlForEachMessage(MSGS_LAST, 1, NULL, "text/x-vcard",
+ CtdlForEachMessage(MSGS_LAST, 1, NULL, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$",
NULL, vcard_gu_backend, (void *)&VCmsgnum );
getroom(&CC->room, hold_rm); /* return to saved room */
* is going to notice what we're trying to do, and delete the old vCard.
*/
CtdlWriteObject(USERCONFIGROOM, /* which room */
- "text/x-vcard", /* MIME type */
+ "text/vcard", /* MIME type */
temp, /* temp file */
u, /* which user */
0, /* not binary */
linelen = strcspn(ptr, "\n");
if (linelen == 0) return(0); /* end of headers */
- if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
- /* It's a vCard. Add it to the directory. */
- vcard_extract_internet_addresses(msg,
- CtdlDirectoryAddUser);
+ if ( (!strncasecmp(ptr, "Content-type: text/x-vcard", 26))
+ || (!strncasecmp(ptr, "Content-type: text/vcard", 24)) ) {
+ /* It's a vCard. Add it to the directory. */
+ vcard_extract_internet_addresses(msg, CtdlDirectoryAddUser);
return(0);
}
linelen = strcspn(ptr, "\n");
if (linelen == 0) goto EOH;
- if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
- /* Bingo! A vCard is being deleted.
- */
- vcard_extract_internet_addresses(msg,
- CtdlDirectoryDelUser);
+ if ( (!strncasecmp(ptr, "Content-type: text/x-vcard", 26))
+ || (!strncasecmp(ptr, "Content-type: text/vcard", 24)) ) {
+ /* Bingo! A vCard is being deleted. */
+ vcard_extract_internet_addresses(msg, CtdlDirectoryDelUser);
#ifdef HAVE_LDAP
ctdl_vcard_to_ldap(msg, V2L_DELETE);
#endif
}
+/*
+ * Get Valid Email Addresses
+ */
+void cmd_gvea(char *argbuf)
+{
+ int num_secondary_emails = 0;
+ int i;
+ char buf[256];
+
+ if (CtdlAccessCheck(ac_logged_in)) return;
+
+ cprintf("%d valid email addresses:\n", LISTING_FOLLOWS);
+ if (strlen(CC->cs_inet_email) > 0) {
+ cprintf("%s\n", CC->cs_inet_email);
+ }
+ if (strlen(CC->cs_inet_other_emails) > 0) {
+ num_secondary_emails = num_tokens(CC->cs_inet_other_emails, '|');
+ for (i=0; i<num_secondary_emails; ++i) {
+ extract_token(buf, CC->cs_inet_other_emails,i,'|',sizeof CC->cs_inet_other_emails);
+ cprintf("%s\n", buf);
+ }
+ }
+ cprintf("000\n");
+}
+
+
/*
* Query Directory
*/
struct vCard *v = NULL;
v = vcard_get_user(&CC->user);
- extract_primary_inet_email(CC->cs_inet_email, sizeof CC->cs_inet_email, v);
+ extract_inet_email_addrs(CC->cs_inet_email, sizeof CC->cs_inet_email,
+ CC->cs_inet_other_emails, sizeof CC->cs_inet_other_emails,
+ v);
extract_friendly_name(CC->cs_inet_fn, sizeof CC->cs_inet_fn, v);
vcard_free(v);
/* First remove any addresses we already have in the address book */
usergoto(aptr->roomname, 0, 0, NULL, NULL);
- CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/x-vcard", NULL,
+ CtdlForEachMessage(MSGS_ALL, 0, NULL, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$", NULL,
strip_addresses_already_have, aptr->collected_addresses);
if (strlen(aptr->collected_addresses) > 0)
if (ser != NULL) {
vmsg->cm_fields['M'] = malloc(strlen(ser) + 1024);
sprintf(vmsg->cm_fields['M'],
- "Content-type: text/x-vcard"
+ "Content-type: text/vcard"
"\r\n\r\n%s\r\n", ser);
free(ser);
}
"Initialize Global Address Book");
CtdlRegisterProtoHook(cmd_qdir, "QDIR", "Query Directory");
CtdlRegisterProtoHook(cmd_gvsn, "GVSN", "Get Valid Screen Names");
+ CtdlRegisterProtoHook(cmd_gvea, "GVEA", "Get Valid Email Addresses");
CtdlRegisterUserHook(vcard_newuser, EVT_NEWUSER);
CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER);
CtdlRegisterNetprocHook(vcard_extract_from_network);
CtdlRegisterSessionHook(store_harvested_addresses, EVT_TIMER);
CtdlRegisterFixedOutputHook("text/x-vcard", vcard_fixed_output);
+ CtdlRegisterFixedOutputHook("text/vcard", vcard_fixed_output);
/* Create the Global ADdress Book room if necessary */
create_room(ADDRESS_BOOK_ROOM, 3, "", 0, 1, 0, VIEW_ADDRESSBOOK);