* 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, int local_addrs_only) {
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)) || (!local_addrs_only) ) {
+ ++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);
+ }
}
if (v == NULL) return(0); /* no vCards were found in this message */
+ /* If users cannot create their own accounts, they cannot re-register either. */
+ if ( (yes_my_citadel_config) && (config.c_disable_newu) && (CC->user.axlevel < 6) ) {
+ return(1);
+ }
+
s = vcard_get_prop(v, "FN", 0, 0, 0);
if (s) lprintf(CTDL_DEBUG, "vCard beforesave hook running for <%s>\n", s);
/* 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, 1);
extract_friendly_name(CC->cs_inet_fn, sizeof CC->cs_inet_fn, v);
vcard_free(v);
return;
}
+ /* If users cannot create their own accounts, they cannot re-register either. */
+ if ( (config.c_disable_newu) && (CC->user.axlevel < 6) ) {
+ cprintf("%d Self-service registration is not allowed here.\n",
+ ERROR + HIGHER_ACCESS_REQUIRED);
+ }
+
my_vcard = vcard_get_user(&CC->user);
strcpy(tmpaddr, "");
strcpy(tmpcity, "");
}
+/*
+ * 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");
+}
+
+
+
+
+/*
+ * 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<displayname_len; ++i) {
+ if (displayname[i] == '\"') displayname[i] = ' ';
+ if (displayname[i] == ';') displayname[i] = ',';
+ if (displayname[i] == ',') has_commas = 1;
+ }
+ striplt(displayname);
+
+ cprintf("%s%s%s <%s>\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
*/
lprintf(CTDL_INFO, "sending 500 REJECT noone here by that name: %s\n", internet_addr);
}
- if (rcpt != NULL) free (rcpt);
+ if (rcpt != NULL) free_recipients(rcpt);
}
-/// CC->kill_me = 1;
}
void check_get_greeting(void) {
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, 1);
extract_friendly_name(CC->cs_inet_fn, sizeof CC->cs_inet_fn, v);
vcard_free(v);
"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");
+ CtdlRegisterProtoHook(cmd_dvca, "DVCA", "Dump VCard Addresses");
CtdlRegisterUserHook(vcard_newuser, EVT_NEWUSER);
CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER);
CtdlRegisterNetprocHook(vcard_extract_from_network);