diff --git a/conf.c b/conf.c index 0c88bb1..69f08fb 100644 --- a/conf.c +++ b/conf.c @@ -246,6 +246,9 @@ parse_conf(const char *config_path) config.features |= FULLBOUNCE; else if (strcmp(word, "NULLCLIENT") == 0 && data == NULL) config.features |= NULLCLIENT; + else if (strcmp(word, "REPLACEFROM") == 0 && data != NULL) { + config.header_from_address = data; + } else { errlogx(EX_CONFIG, "syntax error in %s:%d", config_path, lineno); /* NOTREACHED */ diff --git a/dma.8 b/dma.8 index cf8eb6a..6db8ee6 100644 --- a/dma.8 +++ b/dma.8 @@ -315,6 +315,9 @@ setting it to will send all mails as .Ql Sm off Va username @percolator . .Sm on +.Pp +It can be useful to combine this setting with +.Sq REPLACEFROM . .It Ic NULLCLIENT Xo (boolean, default=commented) .Xc @@ -325,6 +328,10 @@ the defined requires .Sq SMARTHOST to be set. +.It Ic REPLACEFROM Xo +(string, default=empty) +.Xc +Replace the message header "From" address with the given address. .El .Ss Environment variables The behavior of diff --git a/dma.c b/dma.c index ae0018a..314d1c4 100644 --- a/dma.c +++ b/dma.c @@ -86,6 +86,7 @@ struct config config = { .masquerade_host = NULL, .masquerade_user = NULL, .fingerprint = NULL, + .header_from_address = NULL, }; diff --git a/dma.conf b/dma.conf index fa95fc1..0708573 100644 --- a/dma.conf +++ b/dma.conf @@ -66,5 +66,10 @@ # MASQUERADE percolator will send mails as $username@percolator, e.g. fish@percolator # MASQUERADE herb@ert will send all mails as herb@ert +# Replace the message header "From" address with the given address. +# Example: +# REPLACEFROM user@domain.local + + # Directly forward the mail to the SMARTHOST bypassing aliases and local delivery #NULLCLIENT diff --git a/dma.h b/dma.h index 9e7f6cd..3a2f7b4 100644 --- a/dma.h +++ b/dma.h @@ -139,6 +139,7 @@ struct config { const char *masquerade_host; const char *masquerade_user; const unsigned char *fingerprint; + const char *header_from_address; /* XXX does not belong into config */ SSL *ssl; diff --git a/mail.c b/mail.c index 40fb5db..3f83884 100644 --- a/mail.c +++ b/mail.c @@ -413,8 +413,11 @@ readmail(struct queue *queue, int nodot, int recp_from_header) had_date = 1; else if (strprefixcmp(line, "Message-Id:") == 0) had_messagid = 1; - else if (strprefixcmp(line, "From:") == 0) + else if (strprefixcmp(line, "From:") == 0) { had_from = 1; + if (config.header_from_address) + snprintf(line, sizeof(line), "From: <%s>\n", config.header_from_address); + } else if (strprefixcmp(line, "Bcc:") == 0) nocopy = 1; @@ -453,7 +456,10 @@ readmail(struct queue *queue, int nodot, int recp_from_header) hostname()); } else if (!had_from) { had_from = 1; - snprintf(line, sizeof(line), "From: <%s>\n", queue->sender); + if (config.header_from_address) + snprintf(line, sizeof(line), "From: <%s>\n", config.header_from_address); + else + snprintf(line, sizeof(line), "From: <%s>\n", queue->sender); } if (fwrite(line, strlen(line), 1, queue->mailf) != 1) return (-1);