]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-maintd: improve error handling of bouncers unsubscribtion
authorBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 28 Oct 2022 13:29:43 +0000 (15:29 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 28 Oct 2022 13:29:43 +0000 (15:29 +0200)
Now report an error if something went wrong, and keep the bounce
file around to make sure that maintd get another chance and
unsubscribing bouncers. (In the hope that an administrator will see
the logs and fix what needs to be fixed)

ChangeLog
src/mlmmj-maintd.c
tests/mlmmj-maintd.sh

index fb6a02a48afa978ff90a23a7cbff5189f59d4521..fb8504b5c907ec6362b28dbd033bf87d7095b394 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,8 @@
  o Reduce subscription confirmation address length to fit RFC 5321
  o Use arc4random is available
  o Reduce memory manipulation
+ o When unsubscribing bouncers, keep the bounce file if something went
+   wrong and report in syslog what went wrong
 1.3.0
  o Czech translation (Jiří Šolc)
  o Don't use address extensions from non-list addresses
index b616888a16edfa6b26f019589ff1eec765225b5f..31bd665a438d66190a76a557541cb4ae580a1ad5 100644 (file)
@@ -487,7 +487,7 @@ probe_bouncers(int dfd, const char *mlmmjbounce, const char *listdir, int logfd)
 }
 
 static bool
-unsub_bouncers(int dfd, const char *mlmmjunsub, const char *listdir, int logfd)
+unsub_bouncers(int dfd, int logfd)
 {
        DIR *bouncedir;
        char *probefile, *address, *a, *firstbounce;
@@ -566,8 +566,12 @@ unsub_bouncers(int dfd, const char *mlmmjunsub, const char *listdir, int logfd)
                }
                *a = '@';
 
-               exec_and_wait(mlmmjunsub, "-L", listdir, "-b", "-a", address,
-                   NULL);
+               if (!do_unsubscribe(dfd, address, SUB_ALL)) {
+                       log(" - Some errors during unsubscription of %s\n",
+                           address);
+                       ret = false;
+                       continue;
+               }
                unlinkat(bfd, dp->d_name, 0);
                xasprintf(&a, "%s.lastmsg",  dp->d_name);
                unlinkat(bfd, a, 0);
@@ -675,7 +679,7 @@ out:
 }
 
 void do_maintenance(int listfd, const char *listdir, const char *mlmmjsend,
-                   const char *mlmmjbounce, const char *mlmmjunsub)
+                   const char *mlmmjbounce)
 {
        char *random, *logname;
        char timenow[64];
@@ -757,7 +761,7 @@ void do_maintenance(int listfd, const char *listdir, const char *mlmmjsend,
                   "traces, see %s", MAINTD_LOGFILE);
 
        log("unsub_bouncers\n");
-       if (!unsub_bouncers(listfd, mlmmjunsub, listdir, logfd))
+       if (!unsub_bouncers(listfd, logfd))
                log_err("An error occured while unsubscribing bouncing emails, "
                    "see %s", MAINTD_LOGFILE);
 
@@ -842,8 +846,7 @@ int main(int argc, char **argv)
                if(listdir) {
                        log_set_namef("%s(%s)", argv[0], listdir);
                        int fd = open(listdir, O_DIRECTORY);
-                       do_maintenance(fd, listdir, mlmmjsend, mlmmjbounce,
-                                       mlmmjunsub);
+                       do_maintenance(fd, listdir, mlmmjsend, mlmmjbounce);
                        goto mainsleep;
                }
 
@@ -873,8 +876,7 @@ int main(int argc, char **argv)
                        char *l;
                        xasprintf(&l, "%s/%s", dirlists, dp->d_name);
                        log_set_namef("%s(%s)", argv[0], l);
-                       do_maintenance(fd, l, mlmmjsend, mlmmjbounce,
-                                       mlmmjunsub);
+                       do_maintenance(fd, l, mlmmjsend, mlmmjbounce);
                        free(l);
                        close(fd);
                }
index f97a9d8b04a19c9d9d80185fd6545a071a542520..ba29d9b1c2ab81334f73cc3098efcdc4901b6aa8 100755 (executable)
@@ -450,4 +450,27 @@ run_digests
        atf_check -s exit:1 test -f list/subscribers.d/p
        atf_check -s exit:1 test -f list/digesters.d/p
        atf_check -s exit:1 test -f list/nomailsubs.d/p
+
+       echo "a:1234 # plop" > list/bounce/plop=meh
+       echo "plop@meh" > list/digesters.d/p
+       rm -rf list/nomailsubs.d
+       atf_check -s exit:0 -e match:"An error occured while unsubscribing bouncing emails, see mlmmj-maintd.lastrun.log" $mlmmjmaintd -L list -F
+       atf_check -s exit:0 test -f list/bounce/plop=meh
+       atf_check -s exit:1 test -f list/digesters.d/p
+       output="Starting maintenance run at
+
+clean_moderation
+clean_discarded
+clean_subconf
+clean_unsubconf
+resend_queue
+resend_requeue
+clean_nolongerbouncing
+unsub_bouncers
+ - Some errors during unsubscription of plop@meh
+probe_bouncers
+run_digests
+ - No readable index file: no digest
+"
+       atf_check -o "inline:$output" sed -e "s/at .*/at/" list/mlmmj-maintd.lastrun.log
 }