From fd794bb7f3c995998fe2b525fa02cf1a366290d9 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 25 Aug 2013 14:56:50 -0400 Subject: [PATCH] Observe the 'preferred sender email' and 'preferred sender name' preferences when submitting email via SMTP. --- citadel/modules/smtp/serv_smtp.c | 52 ++++++++++++++++++++++++-------- citadel/modules/smtp/smtp_util.h | 23 ++++++-------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index 813d303a4..be6347466 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -20,15 +20,15 @@ * The VRFY and EXPN commands have been removed from this implementation * because nobody uses these commands anymore, except for spammers. * - * Copyright (c) 1998-2012 by the citadel.org team + * Copyright (c) 1998-2013 by the citadel.org team * - * This program is open source software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3. + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ #include "sysdep.h" @@ -147,6 +147,8 @@ void smtp_greeting(int is_msa) sSMTP->from = NewStrBufPlain(NULL, SIZ); sSMTP->recipients = NewStrBufPlain(NULL, SIZ); sSMTP->OneRcpt = NewStrBufPlain(NULL, SIZ); + sSMTP->preferred_sender_email = NULL; + sSMTP->preferred_sender_name = NULL; /* If this config option is set, reject connections from problem * addresses immediately instead of after they execute a RCPT @@ -336,6 +338,7 @@ void smtp_webcit_preferences_hack_backend(long msgnum, void *userdata) { void smtp_webcit_preferences_hack(void) { char config_roomname[ROOMNAMELEN]; char *webcit_conf = NULL; + citsmtp *sSMTP = SMTP; snprintf(config_roomname, sizeof config_roomname, "%010ld.%s", CC->user.usernum, USERCONFIGROOM); if (CtdlGetRoom(&CC->room, config_roomname) != 0) { @@ -352,10 +355,24 @@ void smtp_webcit_preferences_hack(void) { return; } - /* FIXME : now do something with this data */ + /* Parse the webcit configuration and attempt to do something useful with it */ + char *str = webcit_conf; + char *saveptr = str; + char *this_line = NULL; + while (this_line = strtok_r(str, "\n", &saveptr), this_line != NULL) { + str = NULL; + if (!strncasecmp(this_line, "defaultfrom|", 12)) { + sSMTP->preferred_sender_email = NewStrBufPlain(&this_line[12], -1); + } + if (!strncasecmp(this_line, "defaultname|", 12)) { + sSMTP->preferred_sender_name = NewStrBufPlain(&this_line[12], -1); + } + if ((!strncasecmp(this_line, "defaultname|", 12)) && (sSMTP->preferred_sender_name == NULL)) { + sSMTP->preferred_sender_name = NewStrBufPlain(&this_line[12], -1); + } + } free(webcit_conf); - abort(); } @@ -444,7 +461,7 @@ void smtp_try_plain(long offset, long Flags) if (result == login_ok) { if (CtdlTryPassword(pass, len) == pass_ok) { -//// smtp_webcit_preferences_hack(); + smtp_webcit_preferences_hack(); smtp_auth_greeting(offset, Flags); return; } @@ -843,14 +860,23 @@ void smtp_data(long offset, long flags) if (msg->cm_fields['N'] != NULL) free(msg->cm_fields['N']); if (msg->cm_fields['H'] != NULL) free(msg->cm_fields['H']); if (msg->cm_fields['O'] != NULL) free(msg->cm_fields['O']); - msg->cm_fields['A'] = strdup(CCC->user.fullname); msg->cm_fields['N'] = strdup(config.c_nodename); msg->cm_fields['H'] = strdup(config.c_humannode); msg->cm_fields['O'] = strdup(MAILROOM); + msg->cm_fields['A'] = + ((sSMTP->preferred_sender_name != NULL) + ? strdup(ChrPtr(sSMTP->preferred_sender_name)) + : strdup(CCC->user.fullname) + ); + if (!validemail) { if (msg->cm_fields['F'] != NULL) free(msg->cm_fields['F']); - msg->cm_fields['F'] = strdup(CCC->cs_inet_email); + msg->cm_fields['F'] = + ((sSMTP->preferred_sender_email != NULL) + ? strdup(ChrPtr(sSMTP->preferred_sender_email)) + : strdup(CCC->cs_inet_email) + ); } } @@ -1056,6 +1082,8 @@ void smtp_cleanup_function(void) FreeStrBuf(&sSMTP->from); FreeStrBuf(&sSMTP->recipients); FreeStrBuf(&sSMTP->OneRcpt); + FreeStrBuf(&sSMTP->preferred_sender_email); + FreeStrBuf(&sSMTP->preferred_sender_name); free(sSMTP); } diff --git a/citadel/modules/smtp/smtp_util.h b/citadel/modules/smtp/smtp_util.h index 1da497de0..7666a34df 100644 --- a/citadel/modules/smtp/smtp_util.h +++ b/citadel/modules/smtp/smtp_util.h @@ -20,21 +20,16 @@ * The VRFY and EXPN commands have been removed from this implementation * because nobody uses these commands anymore, except for spammers. * - * Copyright (c) 1998-2012 by the citadel.org team + * Copyright (c) 1998-2013 by the citadel.org team * - * This program is open source software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3. - * - * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * - * - * */ const char *smtp_get_Recipients(void); @@ -52,7 +47,9 @@ typedef struct _citsmtp { /* Information about the current session */ int is_lmtp; int is_unfiltered; int is_msa; -}citsmtp; + StrBuf *preferred_sender_email; + StrBuf *preferred_sender_name; +} citsmtp; #define SMTP ((citsmtp *)CC->session_specific_data) -- 2.30.2