From c2294166820ecfc8ccc87d5491d207cf74a795ee Mon Sep 17 00:00:00 2001 From: Trevor Branson Date: Sun, 30 Oct 2022 19:49:57 +0100 Subject: [PATCH 1/3] Added function to set a custom header-from --- conf.c | 3 +++ dma.8 | 7 +++++++ dma.c | 1 + dma.h | 1 + mail.c | 10 ++++++++-- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/conf.c b/conf.c index 0c88bb1..e2ba131 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..d04d1df 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.h b/dma.h index 9e7f6cd..24ecd14 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..ab0a724 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); From 7caece44072a25216fa76c5cefc2493d5a64bf67 Mon Sep 17 00:00:00 2001 From: Trevor Branson Date: Sun, 30 Oct 2022 20:02:52 +0100 Subject: [PATCH 2/3] converted spaces to tabs --- conf.c | 2 +- dma.c | 2 +- dma.h | 2 +- mail.c | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/conf.c b/conf.c index e2ba131..69f08fb 100644 --- a/conf.c +++ b/conf.c @@ -246,7 +246,7 @@ 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) { + else if (strcmp(word, "REPLACEFROM") == 0 && data != NULL) { config.header_from_address = data; } else { diff --git a/dma.c b/dma.c index d04d1df..314d1c4 100644 --- a/dma.c +++ b/dma.c @@ -86,7 +86,7 @@ struct config config = { .masquerade_host = NULL, .masquerade_user = NULL, .fingerprint = NULL, - .header_from_address = NULL, + .header_from_address = NULL, }; diff --git a/dma.h b/dma.h index 24ecd14..3a2f7b4 100644 --- a/dma.h +++ b/dma.h @@ -139,7 +139,7 @@ struct config { const char *masquerade_host; const char *masquerade_user; const unsigned char *fingerprint; - const char *header_from_address; + const char *header_from_address; /* XXX does not belong into config */ SSL *ssl; diff --git a/mail.c b/mail.c index ab0a724..3f83884 100644 --- a/mail.c +++ b/mail.c @@ -415,9 +415,9 @@ readmail(struct queue *queue, int nodot, int recp_from_header) had_messagid = 1; 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); - } + if (config.header_from_address) + snprintf(line, sizeof(line), "From: <%s>\n", config.header_from_address); + } else if (strprefixcmp(line, "Bcc:") == 0) nocopy = 1; @@ -456,10 +456,10 @@ readmail(struct queue *queue, int nodot, int recp_from_header) hostname()); } else if (!had_from) { had_from = 1; - 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 (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); From 9f3d1c72e193ac247c9984c743a1d9026665a98c Mon Sep 17 00:00:00 2001 From: Trevor Branson Date: Sun, 30 Oct 2022 20:27:35 +0100 Subject: [PATCH 3/3] Updated config file --- dma.conf | 5 +++++ 1 file changed, 5 insertions(+) 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