]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
customheaders: remove blank prefix and skip empty lines
authorBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 13 Jun 2025 14:04:16 +0000 (16:04 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 13 Jun 2025 14:08:30 +0000 (16:08 +0200)
Remove all the blanks prefixing any lines and skip empty lines when
adding custom headers as it can break email parsers

Fixes: #17

ChangeLog
src/dumpfd2fd.c
tests/mlmmj-receive.in

index 661dfb3c321313b85174cfff9c107186181f0b7c..786f8c2b58dd4a5653985cffb4a35adfe9215ddc 100644 (file)
--- 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)
index 5dbcbdbeeaf9a4206828a8adc74c04014e6fa864..c252d2b5070283f15ec602a9207a77aa127d7860 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj dot dk>
- * Copyright (C) 2023 Baptiste Daroussin <bapt@FreeBSD.org>
+ * Copyright (C) 2023-2025 Baptiste Daroussin <bapt@FreeBSD.org>
  *
  * 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 <errno.h>
 #include <stdbool.h>
 #include <limits.h>
+#include <ctype.h>
 
 #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) {
index 48bd498fd70471675d56ce8083d3bc8acd425d93..0168521772d00879085140477e258e4a0697ea0b 100644 (file)
@@ -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 <<EOF
+From: bob@test
+To: test@mlmmjtest
+Return-path: bob@test
+Subject: yeah
+
+Let's go, first email
+EOF
+
+       atf_check -o empty -s exit:0 $mlmmjreceive -L list -F <first
+       cat >> expected-1.txt <<EOF
+EHLO heloname\r
+MAIL FROM:<test+bounces-1-user=test@mlmmjtest>\r
+RCPT TO:<user@test>\r
+DATA\r
+From: bob@test\r
+To: test@mlmmjtest\r
+Subject: yeah\r
+X-H1: test\r
+Nope: really not\r
+\r
+Let's go, first email\r
+\r
+.\r
+MAIL FROM:<test+bounces-1-user2=test@mlmmjtest>\r
+RCPT TO:<user2@test>\r
+DATA\r
+From: bob@test\r
+To: test@mlmmjtest\r
+Subject: yeah\r
+X-H1: test\r
+Nope: really not\r
+\r
+Let's go, first email\r
+\r
+.\r
+QUIT\r
+EOF
+       atf_check -o file:expected-1.txt sed -e "/^Message-ID:/d; /^Date:/d;" mail-1.txt
+cat > second <<EOF
+From: bob@test
+To: test@mlmmjtest
+Return-path: bob@test
+Mime: really
+Subject: yeah
+
+Let's go, first email
+EOF
+
+       atf_check -s exit:0 $mlmmjreceive -L list -F <second
+       cat >> expected-2.txt <<EOF
+EHLO heloname\r
+MAIL FROM:<test+bounces-2-user=test@mlmmjtest>\r
+RCPT TO:<user@test>\r
+DATA\r
+From: bob@test\r
+To: test@mlmmjtest\r
+X-H1: test\r
+Nope: really not\r
+Mime: really\r
+Subject: yeah\r
+\r
+Let's go, first email\r
+\r
+.\r
+MAIL FROM:<test+bounces-2-user2=test@mlmmjtest>\r
+RCPT TO:<user2@test>\r
+DATA\r
+From: bob@test\r
+To: test@mlmmjtest\r
+X-H1: test\r
+Nope: really not\r
+Mime: really\r
+Subject: yeah\r
+\r
+Let's go, first email\r
+\r
+.\r
+QUIT\r
+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