From: Baptiste Daroussin Date: Wed, 8 Mar 2023 10:08:56 +0000 (+0100) Subject: mlmmj-maintd: fix and test resend_requeue X-Git-Tag: RELEASE_1_4_0b1~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=532c13ec1e2a0e4ca2499d487fdb0a1754c8b83f;p=thirdparty%2Fmlmmj.git mlmmj-maintd: fix and test resend_requeue 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 --- diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index a0338bba..31e89f24 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -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); diff --git a/tests/mlmmj-maintd.sh b/tests/mlmmj-maintd.sh index 30ce4c34..e0deb63f 100755 --- a/tests/mlmmj-maintd.sh +++ b/tests/mlmmj-maintd.sh @@ -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 <> expect1.txt <> list/requeue/1/subscribers < list/requeue/3/mailfile < list/requeue/3/mailfile <> list/requeue/3/subscribers < expect1.txt < +RCPT TO: +DATA +From: plop +To: bla +Subject: test + +body + +. +QUIT +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 < expect2.txt < +RCPT TO: +DATA +From: plop +To: bla +Subject: test + +body + +. +MAIL FROM: +RCPT TO: +DATA +From: plop +To: bla +Subject: test + +body + +. +MAIL FROM: +RCPT TO: +DATA +From: plop +To: bla +Subject: test + +body + +. +QUIT +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 +} diff --git a/tests/mlmmj-sub.sh b/tests/mlmmj-sub.sh index 90ffcea0..74f3085a 100755 --- a/tests/mlmmj-sub.sh +++ b/tests/mlmmj-sub.sh @@ -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 \ diff --git a/tests/test_env.sh.in b/tests/test_env.sh.in index 4681fea3..f84ab107 100644 --- a/tests/test_env.sh.in +++ b/tests/test_env.sh.in @@ -35,3 +35,10 @@ init_ml() mkdir $ml/$d done } + +kill_fakesmtp() +{ + pid=$(cat fakesmtp.pid) + kill -15 $pid +} +