]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
confunsub: factorize code
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 12 Apr 2023 10:09:19 +0000 (12:09 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 12 Apr 2023 10:09:19 +0000 (12:09 +0200)
src/listcontrol.c

index 93651a27f77864444dc3c934997b6cd15787cb18..f321ba67cd1a9a069667d3384aac2ea7aa90b029 100644 (file)
@@ -379,53 +379,33 @@ int listcontrol(strlist *fromemails, struct ml *ml,
 
        /* listname+unsubconf-digest-COOKIE@domain.tld */
        case CTRL_CONFUNSUB_DIGEST:
-               tmpstr = get_subcookie_content(ml->fd, true, param);
-               if (tmpstr == NULL) {
-                       /* invalid COOKIE */
-                       errno = 0;
-                       log_error(LOG_ARGS, "An unsubconf-digest request was"
-                               " sent with a mismatching cookie."
-                               " Ignoring mail");
-                       return -1;
-               }
-               log_oper(ml->fd, OPLOGFNAME, "mlmmj-unsub: %s confirmed"
-                       " unsubscribe from digest", tmpstr);
-               exec_or_die(mlmmjunsub, "-L", ml->dir, "-a", tmpstr, "-d",
-                   "-R", "-c", NULL);
-               break;
-
+               subtype = "-d";
+               subtypename = "-digest";
+               __attribute__ ((fallthrough));
        /* listname+unsubconf-nomail-COOKIE@domain.tld */
        case CTRL_CONFUNSUB_NOMAIL:
-               tmpstr = get_subcookie_content(ml->fd, true, param);
-               if (tmpstr == NULL) {
-                       /* invalid COOKIE */
-                       errno = 0;
-                       log_error(LOG_ARGS, "An unsubconf-nomail request was"
-                               " sent with a mismatching cookie."
-                               " Ignoring mail");
-                       return -1;
+               if (subtype == NULL) {
+                       subtype = "-n";
+                       subtypename = "-nomail";
                }
-               log_oper(ml->fd, OPLOGFNAME, "mlmmj-unsub: %s confirmed"
-                       " unsubscribe from nomail", tmpstr);
-               exec_or_die(mlmmjunsub, "-L", ml->dir, "-a", tmpstr, "-n",
-                   "-R", "-c", NULL);
-               break;
-
+               __attribute__ ((fallthrough));
        /* listname+unsubconf-COOKIE@domain.tld */
        case CTRL_CONFUNSUB:
+               if (subtype == NULL) {
+                       subtype = "";
+                       subtypename = "";
+               }
                tmpstr = get_subcookie_content(ml->fd, true, param);
                if (tmpstr == NULL) {
                        /* invalid COOKIE */
                        errno = 0;
-                       log_error(LOG_ARGS, "An unsubconf request was"
+                       log_error(LOG_ARGS, "An unsubconf%s request was"
                                " sent with a mismatching cookie."
-                               " Ignoring mail");
+                               " Ignoring mail", subtypename);
                        return -1;
                }
-               log_oper(ml->fd, OPLOGFNAME, "mlmmj-unsub: %s confirmed"
-                       " unsubscribe from regular list", tmpstr);
                exec_or_die(mlmmjunsub, "-L", ml->dir, "-a", tmpstr, "-R", "-c",
-                   NULL);
+                   subtype, NULL);
                break;
 
        /* listname+bounces-INDEX-user=example.tld@domain.tld */