Keep track of envelope from and to headers
authorArt Cancro <ajc@citadel.org>
Mon, 23 Oct 2006 19:06:06 +0000 (19:06 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 23 Oct 2006 19:06:06 +0000 (19:06 +0000)
so we can use them in Sieve scripts.

citadel/internet_addressing.c
citadel/msgbase.c
citadel/serv_sieve.c
citadel/serv_sieve.h
citadel/serv_smtp.c
citadel/techdoc/hack.txt

index a456e3266d418ec1efb2484d481e10cbce0f53df..41666dfef3725060a748e3142f45ea72ddbebf28 100644 (file)
@@ -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);
index b6d6a0bc36168cfcd6e1cb440cc7af15d5add2ea..a098a5cb879c90a5ae9b9e4d82e70bf882427cf3 100644 (file)
@@ -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;
index 7306041de1d983e2369b2be34658b36913197ac2..cf5305b95717425b669dd177444e57221f25ad8b 100644 (file)
@@ -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            },
  *
  */
index 481d160a4e61e42cc2605f8d45d8164780bed84e..e4ded2897cf297db13baf24db448d55d416911f6 100644 (file)
@@ -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];
 };
 
 
index 718439093570e588ef5eee6abefa946e6b33542d..ba8ae9959a3d884fbb12416dcc0a1acae1b32442 100644 (file)
@@ -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);
 
index aea90918f98b664049ea7a4658b993b82f51d5e5..0345beb96a58fe47c0e37a07b493ea0062a57a0d 100644 (file)
@@ -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