From: Art Cancro Date: Mon, 23 Oct 2006 19:06:06 +0000 (+0000) Subject: Keep track of envelope from and to headers X-Git-Tag: v7.86~3888 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=4452cc5785cead33a6af5df79ee2cdf72d296e48 Keep track of envelope from and to headers so we can use them in Sieve scripts. --- diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index a456e3266..41666dfef 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -381,6 +381,18 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) { processed = 1; } + else if (!strcasecmp(key, "Return-Path")) { + if (msg->cm_fields['P'] == NULL) + msg->cm_fields['P'] = strdup(value); + processed = 1; + } + + else if (!strcasecmp(key, "Envelope-To")) { + if (msg->cm_fields['V'] == NULL) + msg->cm_fields['V'] = strdup(value); + processed = 1; + } + /* Clean up and move on. */ free(key); /* Don't free 'value', it's actually the same buffer */ return(processed); diff --git a/citadel/msgbase.c b/citadel/msgbase.c index b6d6a0bc3..a098a5cb8 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -1584,6 +1584,12 @@ int CtdlOutputPreLoadedMsg( else if (i == 'Y') { cprintf("CC: %s%s", mptr, nl); } + else if (i == 'P') { + cprintf("Return-Path: %s%s", mptr, nl); + } + else if (i == 'V') { + cprintf("Envelope-To: %s%s", mptr, nl); + } else if (i == 'U') { cprintf("Subject: %s%s", mptr, nl); subject_found = 1; diff --git a/citadel/serv_sieve.c b/citadel/serv_sieve.c index 7306041de..cf5305b95 100644 --- a/citadel/serv_sieve.c +++ b/citadel/serv_sieve.c @@ -300,7 +300,8 @@ int ctdl_vacation(sieve2_context_t *s, void *my) vptr->next = cs->u->first_vacation; cs->u->first_vacation = vptr; - return SIEVE2_ERROR_UNSUPPORTED; + return SIEVE2_OK; + /* return SIEVE2_ERROR_UNSUPPORTED; */ } @@ -329,12 +330,15 @@ int ctdl_getsubaddress(sieve2_context_t *s, void *my) /* * Callback function to parse message envelope */ -#if 0 int ctdl_getenvelope(sieve2_context_t *s, void *my) { - return SIEVE2_ERROR_UNSUPPORTED; + struct ctdl_sieve *cs = (struct ctdl_sieve *)my; + + lprintf(CTDL_DEBUG, "Action is GETENVELOPE\n"); + sieve2_setvalue_string(s, "to", cs->envelope_to); + sieve2_setvalue_string(s, "from", cs->envelope_from); + return SIEVE2_OK; } -#endif /* @@ -474,7 +478,25 @@ void sieve_do_msg(long msgnum, void *userdata) { else { strcpy(my.subject, ""); } - + + /* Keep track of the envelope-from address (use body-from if not found) */ + if (msg->cm_fields['P'] != NULL) { + safestrncpy(my.envelope_from, msg->cm_fields['P'], sizeof my.envelope_from); + } + else if (msg->cm_fields['F'] != NULL) { + safestrncpy(my.envelope_from, msg->cm_fields['F'], sizeof my.envelope_from); + } + else { + strcpy(my.envelope_from, ""); + } + + /* Keep track of the envelope-to address */ + if (msg->cm_fields['V'] != NULL) { + safestrncpy(my.envelope_to, msg->cm_fields['V'], sizeof my.envelope_to); + } + else { + strcpy(my.envelope_to, ""); + } free(msg); @@ -657,12 +679,12 @@ sieve2_callback_t ctdl_sieve_callbacks[] = { { SIEVE2_DEBUG_TRACE, ctdl_debug }, { SIEVE2_MESSAGE_GETALLHEADERS, ctdl_getheaders }, { SIEVE2_MESSAGE_GETSIZE, ctdl_getsize }, + { SIEVE2_MESSAGE_GETENVELOPE, ctdl_getenvelope }, /* * These actions are unsupported by Citadel so we don't declare them. * { SIEVE2_ACTION_NOTIFY, ctdl_notify }, { SIEVE2_MESSAGE_GETSUBADDRESS, ctdl_getsubaddress }, - { SIEVE2_MESSAGE_GETENVELOPE, ctdl_getenvelope }, { SIEVE2_MESSAGE_GETBODY, ctdl_getbody }, * */ diff --git a/citadel/serv_sieve.h b/citadel/serv_sieve.h index 481d160a4..e4ded2897 100644 --- a/citadel/serv_sieve.h +++ b/citadel/serv_sieve.h @@ -42,6 +42,8 @@ struct ctdl_sieve { char recp_name[256]; char sender[256]; /* To whom shall we send reject bounces or vacation messages? */ char subject[1024]; /* Retain msg subject so we can use it in vacation messages */ + char envelope_from[1024]; + char envelope_to[1024]; }; diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index 718439093..ba8ae9959 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -753,6 +753,18 @@ void smtp_data(void) { msg->cm_fields['O'] = strdup(MAILROOM); } + /* Set the "envelope from" address */ + if (msg->cm_fields['P'] != NULL) { + free(msg->cm_fields['P']); + } + msg->cm_fields['P'] = strdup(SMTP->from); + + /* Set the "envelope to" address */ + if (msg->cm_fields['V'] != NULL) { + free(msg->cm_fields['V']); + } + msg->cm_fields['V'] = strdup(SMTP->recipients); + /* Submit the message into the Citadel system. */ valid = validate_recipients(SMTP->recipients); diff --git a/citadel/techdoc/hack.txt b/citadel/techdoc/hack.txt index aea90918f..0345beb96 100644 --- a/citadel/techdoc/hack.txt +++ b/citadel/techdoc/hack.txt @@ -285,6 +285,7 @@ T date/Time A 32-bit integer containing the date and time of of seconds since January 1, 1970 GMT). U sUbject Optional. Developers may choose whether they wish to generate or display subject fields. +V enVelope-to The recipient specified in incoming SMTP messages. Y carbon copY Optional, and only in Mail messages. 0 Error This field is typically never found in a message on disk or in transit. Message scanning modules are