From: Baptiste Daroussin Date: Fri, 13 Jun 2025 14:04:16 +0000 (+0200) Subject: customheaders: remove blank prefix and skip empty lines X-Git-Tag: RELEASE_1.6.0~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99e1e0bc55e2c6aa1e38f92dc5b04c681722fcb9;p=thirdparty%2Fmlmmj.git customheaders: remove blank prefix and skip empty lines Remove all the blanks prefixing any lines and skip empty lines when adding custom headers as it can break email parsers Fixes: #17 --- diff --git a/ChangeLog b/ChangeLog index 661dfb3c..786f8c2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ master + o Remove blanks in customheaders prefix and skip empty lines o $bouncenumbers$ in probe are now expended to number, messageid when possible o customheaeders allow now substitution of $posteraddr$ (Erwan Mas) diff --git a/src/dumpfd2fd.c b/src/dumpfd2fd.c index 5dbcbdbe..c252d2b5 100644 --- a/src/dumpfd2fd.c +++ b/src/dumpfd2fd.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Mads Martin Joergensen - * Copyright (C) 2023 Baptiste Daroussin + * Copyright (C) 2023-2025 Baptiste Daroussin * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -27,6 +27,7 @@ #include #include #include +#include #include "config.h" #include "log_error.h" @@ -87,6 +88,11 @@ int process_headers_fd(int infd, int outfd,const char *from) int r; while((line = mygetline(infd))) { + /* skip empty lines */ + while (isspace(*line)) + line++; + if (line[0] == '\0') + continue; char *to_be_subst ; char *new_line ; to_be_subst = strstr(line,"$posteraddr$") ; if ( to_be_subst != NULL) { diff --git a/tests/mlmmj-receive.in b/tests/mlmmj-receive.in index 48bd498f..01685217 100644 --- a/tests/mlmmj-receive.in +++ b/tests/mlmmj-receive.in @@ -26,6 +26,7 @@ tests_init \ normal_email \ delheaders \ customheaders \ + customheaders_blanks \ customheaders_with_subst \ verp \ normal_email_with_dot \ @@ -2838,6 +2839,102 @@ EOF atf_check -o file:expected-2.txt sed -e "/^Message-ID:/d; /^Date:/d;" mail-2.txt } +customheaders_blanks_body() +{ + atf_check $top_builddir/tests/fakesmtpd + trap kill_fakesmtp EXIT TERM + init_ml list + rmdir list/text + ln -s ${top_srcdir}/listtexts/en list/text + echo test@mlmmjtest > list/control/listaddress + echo "25678" > list/control/smtpport + echo "heloname" > list/control/smtphelo + printf "X-H1: test\nNope: really not\n\n \n" > list/control/customheaders + + printf "user@test\nuser2@test" > list/subscribers.d/u +cat > first <> expected-1.txt < +RCPT TO: +DATA +From: bob@test +To: test@mlmmjtest +Subject: yeah +X-H1: test +Nope: really not + +Let's go, first email + +. +MAIL FROM: +RCPT TO: +DATA +From: bob@test +To: test@mlmmjtest +Subject: yeah +X-H1: test +Nope: really not + +Let's go, first email + +. +QUIT +EOF + atf_check -o file:expected-1.txt sed -e "/^Message-ID:/d; /^Date:/d;" mail-1.txt +cat > second <> expected-2.txt < +RCPT TO: +DATA +From: bob@test +To: test@mlmmjtest +X-H1: test +Nope: really not +Mime: really +Subject: yeah + +Let's go, first email + +. +MAIL FROM: +RCPT TO: +DATA +From: bob@test +To: test@mlmmjtest +X-H1: test +Nope: really not +Mime: really +Subject: yeah + +Let's go, first email + +. +QUIT +EOF + atf_check -o file:expected-2.txt sed -e "/^Message-ID:/d; /^Date:/d;" mail-2.txt +} + customheaders_with_subst_body() { atf_check $top_builddir/tests/fakesmtpd