From eb7010b4f40377ed47459da4704dfc0675a387b2 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 19 Apr 2007 20:46:30 +0000 Subject: [PATCH] Completed DVCA (Dump VCard Addresses) function. This function outputs a list of names and email addresses found in all vCards within the current room. Useful for address book clients. --- citadel/citadel.h | 2 +- citadel/citadel.nsi | 2 +- citadel/configure.ac | 2 +- citadel/journaling.c | 2 +- citadel/serv_vcard.c | 91 ++++++++++++++++++++++++++++++++++++++++++-- citadel/serv_vcard.h | 2 +- 6 files changed, 92 insertions(+), 9 deletions(-) diff --git a/citadel/citadel.h b/citadel/citadel.h index 6f3bceb3e..b790f860b 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -47,7 +47,7 @@ extern "C" { * usually more strict because you're not really supposed to dump/load and * upgrade at the same time. */ -#define REV_LEVEL 709 /* This version */ +#define REV_LEVEL 710 /* This version */ #define REV_MIN 591 /* Oldest compatible database */ #define EXPORT_REV_MIN 706 /* Oldest compatible export files */ diff --git a/citadel/citadel.nsi b/citadel/citadel.nsi index 2904a0cc3..c40dbef49 100644 --- a/citadel/citadel.nsi +++ b/citadel/citadel.nsi @@ -4,7 +4,7 @@ !include "${NSISDIR}\Contrib\Modern UI\System.nsh" !define MUI_PRODUCT "Citadel" -!define MUI_VERSION "7.09" +!define MUI_VERSION "7.10" !define MUI_WELCOMEPAGE !define MUI_LICENSEPAGE !define MUI_COMPONENTSPAGE diff --git a/citadel/configure.ac b/citadel/configure.ac index de0330c49..a3932c0f7 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. dnl $Id$ AC_PREREQ(2.52) -AC_INIT([Citadel], [7.09], [http://www.citadel.org/]) +AC_INIT([Citadel], [7.10], [http://www.citadel.org/]) AC_REVISION([$Revision$]) AC_CONFIG_SRCDIR([citserver.c]) AC_PREFIX_DEFAULT(/usr/local/citadel) diff --git a/citadel/journaling.c b/citadel/journaling.c index c30c5d63a..38629ab41 100644 --- a/citadel/journaling.c +++ b/citadel/journaling.c @@ -107,7 +107,7 @@ void local_to_inetemail(char *inetemail, char *localuser, size_t inetemail_len) return; } - extract_inet_email_addrs(inetemail, inetemail_len, NULL, 0, v); + extract_inet_email_addrs(inetemail, inetemail_len, NULL, 0, v, 1); vcard_free(v); } diff --git a/citadel/serv_vcard.c b/citadel/serv_vcard.c index ec8089d39..8fbaf44ff 100644 --- a/citadel/serv_vcard.c +++ b/citadel/serv_vcard.c @@ -206,7 +206,7 @@ void cmd_igab(char *argbuf) { */ void extract_inet_email_addrs(char *emailaddrbuf, size_t emailaddrbuf_len, char *secemailaddrbuf, size_t secemailaddrbuf_len, - struct vCard *v) { + struct vCard *v, int local_addrs_only) { char *s, *addr; int instance = 0; int saved_instance = 0; @@ -218,7 +218,7 @@ void extract_inet_email_addrs(char *emailaddrbuf, size_t emailaddrbuf_len, addr = strdup(s); striplt(addr); if (strlen(addr) > 0) { - if (IsDirectory(addr)) { + if ( (IsDirectory(addr)) || (!local_addrs_only) ) { ++saved_instance; if ((saved_instance == 1) && (emailaddrbuf != NULL)) { safestrncpy(emailaddrbuf, addr, emailaddrbuf_len); @@ -499,7 +499,7 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) { v = vcard_load(msg->cm_fields['M']); 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); + v, 1); extract_friendly_name(CC->cs_inet_fn, sizeof CC->cs_inet_fn, v); vcard_free(v); @@ -944,6 +944,88 @@ void cmd_gvea(char *argbuf) } + + +/* + * Callback function for cmd_dvca() that hunts for vCard content types + * and outputs any email addresses found within. + */ +void dvca_mime_callback(char *name, char *filename, char *partnum, char *disp, + void *content, char *cbtype, char *cbcharset, size_t length, char *encoding, + void *cbuserdata) { + + struct vCard *v; + char displayname[256]; + int displayname_len; + char emailaddr[256]; + int i; + int has_commas = 0; + + if ( (strcasecmp(cbtype, "text/vcard")) && (strcasecmp(cbtype, "text/x-vcard")) ) { + return; + } + + v = vcard_load(content); + if (v == NULL) return; + + extract_friendly_name(displayname, sizeof displayname, v); + extract_inet_email_addrs(emailaddr, sizeof emailaddr, NULL, 0, v, 0); + + displayname_len = strlen(displayname); + for (i=0; i\n", + (has_commas ? "\"" : ""), + displayname, + (has_commas ? "\"" : ""), + emailaddr + ); + + vcard_free(v); +} + + +/* + * Back end callback function for cmd_dvca() + * + * It's basically just passed a list of message numbers, which we're going + * to fetch off the disk and then pass along to the MIME parser via another + * layer of callback... + */ +void dvca_callback(long msgnum, void *userdata) { + struct CtdlMessage *msg = NULL; + + msg = CtdlFetchMessage(msgnum, 1); + if (msg == NULL) return; + mime_parser(msg->cm_fields['M'], + NULL, + *dvca_mime_callback, /* callback function */ + NULL, NULL, + NULL, /* user data */ + 0 + ); + CtdlFreeMessage(msg); +} + + +/* + * Dump VCard Addresses + */ +void cmd_dvca(char *argbuf) +{ + if (CtdlAccessCheck(ac_logged_in)) return; + + cprintf("%d addresses:\n", LISTING_FOLLOWS); + CtdlForEachMessage(MSGS_ALL, 0, NULL, NULL, NULL, dvca_callback, NULL); + cprintf("000\n"); +} + + /* * Query Directory */ @@ -1054,7 +1136,7 @@ void vcard_session_login_hook(void) { v = vcard_get_user(&CC->user); 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); + v, 1); extract_friendly_name(CC->cs_inet_fn, sizeof CC->cs_inet_fn, v); vcard_free(v); @@ -1265,6 +1347,7 @@ char *serv_vcard_init(void) CtdlRegisterProtoHook(cmd_qdir, "QDIR", "Query Directory"); CtdlRegisterProtoHook(cmd_gvsn, "GVSN", "Get Valid Screen Names"); CtdlRegisterProtoHook(cmd_gvea, "GVEA", "Get Valid Email Addresses"); + CtdlRegisterProtoHook(cmd_dvca, "DVCA", "Dump VCard Addresses"); CtdlRegisterUserHook(vcard_newuser, EVT_NEWUSER); CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER); CtdlRegisterNetprocHook(vcard_extract_from_network); diff --git a/citadel/serv_vcard.h b/citadel/serv_vcard.h index 4e6f52758..0533cc8ff 100644 --- a/citadel/serv_vcard.h +++ b/citadel/serv_vcard.h @@ -1,5 +1,5 @@ /* * $Id: $ */ -void extract_inet_email_addrs(char *, size_t, char *, size_t, struct vCard *v); +void extract_inet_email_addrs(char *, size_t, char *, size_t, struct vCard *v, int local_addrs_only); struct vCard *vcard_get_user(struct ctdluser *u); -- 2.30.2