From: Baptiste Daroussin Date: Mon, 18 Dec 2023 09:02:07 +0000 (+0100) Subject: digest: trim the last element of lastdigest if needed X-Git-Tag: RELEASE_1_4_2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9256cd67ce51a2b030f4e50e5a15a3b46d8e9012;p=thirdparty%2Fmlmmj.git digest: trim the last element of lastdigest if needed Add regression tests about it --- diff --git a/src/mlmmj.c b/src/mlmmj.c index 1ce9b5fa..6c6c41a0 100644 --- a/src/mlmmj.c +++ b/src/mlmmj.c @@ -85,6 +85,9 @@ parse_lastdigest(char *line, long *lastindex, time_t *lasttime, return true; } walk = walk + strlen(walk) + 1; + size_t l = strlen(walk) -1; + if (walk[l] == '\n') + walk[l] = '\0'; *lastissue = strtoim(walk, LONG_MIN, LONG_MAX, errstr); if (*errstr != NULL) { *errstr = "Invalid value for lastissue"; diff --git a/tests/mlmmj-maintd.sh b/tests/mlmmj-maintd.sh index eac7b8e3..ec7bd261 100755 --- a/tests/mlmmj-maintd.sh +++ b/tests/mlmmj-maintd.sh @@ -12,6 +12,7 @@ tests_init \ digests_2 \ digests_3 \ digests_4 \ + digests_5 \ unsub_bouncers_0 \ unsub_bouncers_1 \ unsub_bouncers_2 \ @@ -485,6 +486,32 @@ run_digests atf_check -o "inline:$output" sed -e "s/at .*/at/" lists/ml/mlmmj-maintd.lastrun.log } +digests_5_body() +{ + test $(id -u) = 0 && atf_skip "Can only be run as non-root" + mkdir lists + init_ml lists/ml + echo test@mlmmjtest > lists/ml/control/listaddress + + echo "0" > lists/ml/index + echo "3774:1702743593:141" > lists/ml/lastdigest + atf_check -s exit:0 $mlmmjmaintd -L lists/ml -F + output="Starting maintenance run at + +clean_moderation +clean_discarded +clean_subconf +clean_unsubconf +resend_queue +resend_requeue +clean_nolongerbouncing +unsub_bouncers +probe_bouncers +run_digests +" + atf_check -o "inline:$output" sed -e "s/at .*/at/" lists/ml/mlmmj-maintd.lastrun.log +} + unsub_bouncers_0_body() { init_ml list diff --git a/tests/mlmmj.c b/tests/mlmmj.c index e68f7643..b403c8dd 100644 --- a/tests/mlmmj.c +++ b/tests/mlmmj.c @@ -771,6 +771,14 @@ ATF_TC_BODY(parse_lastdigest, tc) ATF_REQUIRE_EQ(lasttime, 1702743593); ATF_REQUIRE_EQ(lastissue, 141); free(line); + + line = xstrdup("3774:1702743593:141\n"); + ATF_REQUIRE(parse_lastdigest(line, &lastindex, &lasttime, &lastissue, + &errstr)); + ATF_REQUIRE_EQ(lastindex, 3774); + ATF_REQUIRE_EQ(lasttime, 1702743593); + ATF_REQUIRE_EQ(lastissue, 141); + free(line); } ATF_TC_BODY(extract_bouncetime, tc)