]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-maintd: fix and test resend_requeue
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 8 Mar 2023 10:08:56 +0000 (11:08 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 8 Mar 2023 10:08:56 +0000 (11:08 +0100)
Pass the list of target mails to resend to via file descriptor:
This allows to stop creating a "resending" file and controls the life
cycle of the mail to be resent (deleted or not) from the mmlmmj-maintd
code

src/mlmmj-maintd.c
tests/mlmmj-maintd.sh
tests/mlmmj-sub.sh
tests/test_env.sh.in

index a0338bba34a0c7d20d75521c3f8eaa3ef50393d5..31e89f2417f53d2c53d89f2c58e18c70ca3914fa 100644 (file)
@@ -326,21 +326,16 @@ resend_requeue(struct ml *ml, const char *mlmmjsend, int logfd)
                        continue;
                }
 
-               xasprintf(&subnewname, "%s.resending", subfilename);
-
-               if(renameat(fd, subfilename, fd, subnewname) == -1) {
-                       log(" - Could not rename(requeue/%s, requeue/%s): %s\n",
-                           subfilename, subnewname, strerror(errno));
-                       ret = false;
-                       free(archivefilename);
-                       free(subfilename);
-                       free(subnewname);
-                       continue;
-               }
-               free(subfilename);
+               int subfd = openat(fd, subfilename, O_RDONLY);
+               unlinkat(fd, subfilename, 0);
 
+               xasprintf(&subnewname, "%d", subfd);
                exec_and_wait(mlmmjsend, "-l", "3", "-L", ml->dir, "-m",
                    archivefilename, "-s", subnewname, "-a", "-D", NULL);
+               free(subnewname);
+               if (fromrequeuedir)
+                       unlinkat(ml->fd, archivefilename, 0);
+               close(subfd);
        }
 
        closedir(queuedir);
index 30ce4c349fed32e4b8e2c2c6bd7f2add50af5777..e0deb63f7f6e046de4d7da984ff3508ab4384f4a 100755 (executable)
@@ -32,7 +32,8 @@ tests_init \
        basics_8 \
        basics_9 \
        basics_10 \
-       basics_11
+       basics_11 \
+       resend_requeue
 
 nolongerbouncing_body()
 {
@@ -698,3 +699,146 @@ run_digests
 "
        atf_check -o "inline:$output" sed -e "s/at .*/at/" list/mlmmj-maintd.lastrun.log
 }
+
+resend_requeue_body()
+{
+       mlmmjmaintd=$(command -v mlmmj-maintd)
+       atf_check $srcdir/fakesmtpd
+       trap kill_fakesmtp EXIT TERM
+       init_ml list
+       echo "test@test" > list/control/listaddress
+       echo "25678" > list/control/smtpport
+       echo "heloname" > list/control/smtphelo
+       # Not a directory
+cat >> list/requeue/1 <<EOF
+user1@test1
+user2@test2
+user3@test3
+EOF
+       atf_check $mlmmjmaintd -L list -F
+
+cat >> expect1.txt <<EOF
+Starting maintenance run at
+
+clean_moderation
+clean_discarded
+clean_subconf
+clean_unsubconf
+resend_queue
+resend_requeue
+clean_nolongerbouncing
+unsub_bouncers
+probe_bouncers
+run_digests
+ - No readable index file: no digest
+EOF
+
+       atf_check -o file:expect1.txt sed -e "s/at .*/at/" list/mlmmj-maintd.lastrun.log
+       # no archive and don't remove empty dir
+       rm list/requeue/1
+       mkdir list/requeue/1
+       mkdir list/requeue/2
+       touch -t 000101010101 list/requeue/2
+       mkdir list/requeue/3
+       cat >> list/requeue/1/subscribers <<EOF
+user1@test1
+user2@test2
+user3@test3
+EOF
+       atf_check $mlmmjmaintd -L list -F
+       atf_check -o file:expect1.txt sed -e "s/at .*/at/" list/mlmmj-maintd.lastrun.log
+       test -d list/requeue/3 || atf_fail "list/requeue/3 should not have been removed"
+       if test -d list/requeue/2; then
+               atf_fail "list/requeue/2 should have been removed"
+       fi
+       atf_check -s exit:1 test -f mail-1.txt
+cat > list/requeue/3/mailfile <<EOF
+From: plop
+To: bla
+Subject: test
+
+body
+EOF
+       # no subscribers: delete the mailfile
+       atf_check $mlmmjmaintd -L list -F
+       atf_check -o file:expect1.txt sed -e "s/at .*/at/" list/mlmmj-maintd.lastrun.log
+       if test -f list/requeue/3/mailfile; then
+               atf_fail "list/requeue/3/mailfile should have been removed"
+       fi
+
+cat > list/requeue/3/mailfile <<EOF
+From: plop
+To: bla
+Subject: test
+
+body
+EOF
+       cat >> list/requeue/3/subscribers <<EOF
+user1@test1
+EOF
+       # now the mail should be sent
+       atf_check $mlmmjmaintd -L list -F
+       cat > expect1.txt <<EOF
+EHLO heloname\r
+MAIL FROM:<test+bounces-3-user1=test1@test>\r
+RCPT TO:<user1@test1>\r
+DATA\r
+From: plop\r
+To: bla\r
+Subject: test\r
+\r
+body\r
+\r
+.\r
+QUIT\r
+EOF
+       atf_check -o file:expect1.txt sed -e "/^Message-ID:/d; /^Date:/d; s/confsub-.*@mlmmjtest/confsub-@mlmmjtest/g" mail-1.txt
+       atf_check -s exit:1 test -f mail-2.txt
+       atf_check -s exit:1 test -f list/requeue/3/mailfile
+cat > list/archive/1 <<EOF
+From: plop
+To: bla
+Subject: test
+
+body
+EOF
+       # now with archive
+       cat > expect2.txt <<EOF
+EHLO heloname\r
+MAIL FROM:<test+bounces-1-user1=test1@test>\r
+RCPT TO:<user1@test1>\r
+DATA\r
+From: plop\r
+To: bla\r
+Subject: test\r
+\r
+body\r
+\r
+.\r
+MAIL FROM:<test+bounces-1-user2=test2@test>\r
+RCPT TO:<user2@test2>\r
+DATA\r
+From: plop\r
+To: bla\r
+Subject: test\r
+\r
+body\r
+\r
+.\r
+MAIL FROM:<test+bounces-1-user3=test3@test>\r
+RCPT TO:<user3@test3>\r
+DATA\r
+From: plop\r
+To: bla\r
+Subject: test\r
+\r
+body\r
+\r
+.\r
+QUIT\r
+EOF
+       atf_check $mlmmjmaintd -L list -F
+       atf_check -o file:expect2.txt sed -e "/^Message-ID:/d; /^Date:/d; s/confsub-.*@mlmmjtest/confsub-@mlmmjtest/g" mail-2.txt
+       atf_check -s exit:1 test -f mail-4.txt
+       atf_check -s exit:0 test -f list/archive/1
+}
index 90ffcea0c8952448d1a42d23ce164e6104b3f837..74f3085a6fa9fbcfb5d7a7c785f2c760e9460885 100755 (executable)
@@ -2,12 +2,6 @@
 
 . $(atf_get_srcdir)/test_env.sh
 
-kill_fakesmtp()
-{
-       pid=$(cat fakesmtp.pid)
-       kill -15 $pid
-}
-
 tests_init \
        add_basics \
        add_normal \
index 4681fea3c81e0a63f1c72bac9a36b42119ad11a9..f84ab10758b3e29dd552a53ab4ca53d642087eeb 100644 (file)
@@ -35,3 +35,10 @@ init_ml()
                mkdir $ml/$d
        done
 }
+
+kill_fakesmtp()
+{
+       pid=$(cat fakesmtp.pid)
+       kill -15 $pid
+}
+