]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
notify-sub: use the same function from subscribtion and unsubscribtion
authorBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 10 Feb 2023 17:03:07 +0000 (18:03 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 10 Feb 2023 17:03:07 +0000 (18:03 +0100)
include/subscriberfuncs.h
src/mlmmj-sub.c
src/mlmmj-unsub.c
src/subscriberfuncs.c
tests/mlmmj.c

index 07cececd7ad8a585a8eaa2daa866c635dab3dae8..0489430d0814ffbbd04a148d2dacb9f88b477617 100644 (file)
@@ -32,5 +32,5 @@ enum subtype is_subbed(int listfd, const char *address, bool both);
 char *get_subcookie_content(int listfd, bool unsub, const char *param);
 void notify_sub(struct ml *ml, const char *subaddr,
                const char *mlmmjsend, enum subtype typesub,
-               enum subreason reasonsub);
+               enum subreason reasonsub, bool sub);
 #endif /* SUBSCRIBERFUNC_H */
index daf855d4821ede3603b4f462d29b5e8374c1bf04..272564226de60c76b9b58edf146e488db651ce18 100644 (file)
@@ -682,7 +682,7 @@ int main(int argc, char **argv)
 
        /* Notify list owner about subscription */
        if (notifysub)
-               notify_sub(&ml, address, mlmmjsend, typesub, reasonsub);
+               notify_sub(&ml, address, mlmmjsend, typesub, reasonsub, true);
 
        free(address);
        free(mlmmjsend);
index f208888b8e315d87f08a329003ac15dae2dc8ecb..79b3bc02410cb414e42d2a9540dbe77baedc5334 100644 (file)
@@ -86,47 +86,6 @@ void confirm_unsub(struct ml *ml, const char *subaddr, const char *mlmmjsend,
            fromaddr, "-m", queuefilename, NULL);
 }
 
-void notify_unsub(struct ml *ml, const char *subaddr, const char *mlmmjsend,
-                 enum subtype typesub, enum subreason reasonsub)
-{
-        char *fromaddr, *tostr;
-       text *txt;
-        char *queuefilename = NULL, *listtext;
-
-       gen_addr(fromaddr, ml, "bounces-help");
-       gen_addr(tostr, ml, "owner");
-
-       switch(typesub) {
-               default:
-               case SUB_NORMAL:
-                       listtext = xstrdup("notifyunsub");
-                       break;
-               case SUB_DIGEST:
-                       listtext = xstrdup("notifyunsub-digest");
-                       break;
-               case SUB_NOMAIL:
-                       listtext = xstrdup("notifyunsub-nomail");
-                       break;
-       }
-       
-       txt = open_text(ml->fd, "notify", "unsub",
-                       subreason_strs[reasonsub], subtype_strs[typesub],
-                       listtext);
-       free(listtext);
-       MY_ASSERT(txt);
-       register_default_unformatted(txt, ml->delim, ml->addr);
-       register_unformatted(txt, "subaddr", subaddr);
-       register_unformatted(txt, "oldsub", subaddr); /* DEPRECATED */
-       queuefilename = prepstdreply(txt, ml->dir,
-                       "$listowner$", "$listowner$", NULL, ml->fd, ml->ctrlfd);
-       MY_ASSERT(queuefilename);
-       close_text(txt);
-
-       exec_or_die(mlmmjsend, "-l", "1", "-L", ml->dir, "-T", tostr, "-F",
-           fromaddr, "-m", queuefilename, NULL);
-}
-
-
 void generate_unsubconfirm(struct ml *ml, const char *subaddr,
                           const char *mlmmjsend,
                           enum subtype typesub, enum subreason reasonsub)
@@ -420,7 +379,7 @@ int main(int argc, char **argv)
 
         /* Notify list owner about subscription */
         if (notifysub)
-                notify_unsub(&ml, address, mlmmjsend, typesub, reasonsub);
+                notify_sub(&ml, address, mlmmjsend, typesub, reasonsub, false);
 
        free(address);
        free(mlmmjsend);
index a13dc1e99a795050677cba1bec1441afeacbc377..987b21b630774ee5c3b573961cd1db9ed1990994 100644 (file)
@@ -167,7 +167,7 @@ get_subcookie_content(int listfd, bool unsub, const char *param)
 
 void notify_sub(struct ml *ml, const char *subaddr,
                const char *mlmmjsend, enum subtype typesub,
-               enum subreason reasonsub)
+               enum subreason reasonsub, bool sub)
 {
        char *fromaddr, *tostr;
        text *txt;
@@ -180,13 +180,13 @@ void notify_sub(struct ml *ml, const char *subaddr,
        switch(typesub) {
                default:
                case SUB_NORMAL:
-                       listtext = "notifysub";
+                       listtext = sub ? "notifysub" : "notifyunsub";
                        break;
                case SUB_DIGEST:
-                       listtext = "notifysub-digest";
+                       listtext = sub ? "notifysub-digest": "notifyunsub-digest";
                        break;
                case SUB_NOMAIL:
-                       listtext = "notifysub-nomail";
+                       listtext = sub ? "notifysub-nomail": "notifyunsub-nomail";
                        break;
                case SUB_BOTH:
                        /* No legacy list text as feature didn't exist. */
@@ -194,13 +194,13 @@ void notify_sub(struct ml *ml, const char *subaddr,
                        break;
        }
 
-       txt = open_text(ml->fd, "notify", "sub",
+       txt = open_text(ml->fd, "notify", sub? "sub":"unsub",
                        subreason_strs[reasonsub], subtype_strs[typesub],
                        listtext);
        MY_ASSERT(txt);
        register_default_unformatted(txt, ml->delim, ml->addr);
        register_unformatted(txt, "subaddr", subaddr);
-       register_unformatted(txt, "newsub", subaddr); /* DEPRECATED */
+       register_unformatted(txt, sub ? "newsub" : "oldsub", subaddr); /* DEPRECATED */
        queuefilename = prepstdreply(txt, ml->dir,
                        "$listowner$", "$listowner$", NULL, ml->fd, ml->ctrlfd);
        MY_ASSERT(queuefilename);
index 1ceb54f9b45a1b45680dca00180026788970ca9d..cddf16c6e5b58ae9e0c368ae5863cb2dfbb9fca4 100644 (file)
@@ -2415,7 +2415,7 @@ ATF_TC_BODY(notify_sub, tc)
        pid_t p = atf_utils_fork();
        if (p == 0) {
                notify_sub(&ml, "test@plop", "/bin/echo", SUB_NORMAL,
-                   SUB_ADMIN);
+                   SUB_ADMIN, true);
        }
        atf_utils_wait(p, 0, "save:plop.txt", "");
        fd = open("plop.txt", O_RDONLY);
@@ -2440,7 +2440,7 @@ ATF_TC_BODY(notify_sub, tc)
        p = atf_utils_fork();
        if (p == 0) {
                notify_sub(&ml, "test@plop", "/bin/echo", SUB_DIGEST,
-                   SUB_ADMIN);
+                   SUB_ADMIN, true);
        }
        atf_utils_wait(p, 0, "save:plop.txt", "");
        fd = open("plop.txt", O_RDONLY);
@@ -2463,7 +2463,7 @@ ATF_TC_BODY(notify_sub, tc)
        p = atf_utils_fork();
        if (p == 0) {
                notify_sub(&ml, "test@plop", "/bin/echo", SUB_NOMAIL,
-                   SUB_CONFIRM);
+                   SUB_CONFIRM, true);
        }
        atf_utils_wait(p, 0, "save:plop.txt", "");
        fd = open("plop.txt", O_RDONLY);
@@ -2486,7 +2486,7 @@ ATF_TC_BODY(notify_sub, tc)
        p = atf_utils_fork();
        if (p == 0) {
                notify_sub(&ml, "test@plop", "/bin/echo", SUB_BOTH,
-                   SUB_REQUEST);
+                   SUB_REQUEST, true);
        }
        atf_utils_wait(p, 0, "save:plop.txt", "");
        fd = open("plop.txt", O_RDONLY);
@@ -2505,6 +2505,100 @@ ATF_TC_BODY(notify_sub, tc)
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
        }
+
+       p = atf_utils_fork();
+       if (p == 0) {
+               notify_sub(&ml, "test@plop", "/bin/echo", SUB_NORMAL,
+                   SUB_ADMIN, false);
+       }
+       atf_utils_wait(p, 0, "save:plop.txt", "");
+       fd = open("plop.txt", O_RDONLY);
+       content = atf_utils_readline(fd);
+       close(fd);
+       pattern = "-l 1 -L list -T test+owner@test -F test+bounces-help@test -m list/queue/";
+       if (strncmp(content, pattern, strlen(pattern)) != 0)
+               atf_tc_fail("Invalid command: '%s'", content);
+       path = strrchr(content, ' ');
+       ATF_REQUIRE(path != NULL);
+       path++;
+       if (!atf_utils_grep_file(".*The address <test@plop> has been unsubscribed from the list.*", path)) {
+               atf_utils_cat_file(path, "");
+               atf_tc_fail("invalid file");
+       }
+       atf_utils_cat_file(path, "");
+       if (!atf_utils_grep_file(".*administrator commanded it.*", path)) {
+               atf_utils_cat_file(path, "");
+               atf_tc_fail("invalid file");
+       }
+
+       p = atf_utils_fork();
+       if (p == 0) {
+               notify_sub(&ml, "test@plop", "/bin/echo", SUB_DIGEST,
+                   SUB_ADMIN, false);
+       }
+       atf_utils_wait(p, 0, "save:plop.txt", "");
+       fd = open("plop.txt", O_RDONLY);
+       content = atf_utils_readline(fd);
+       close(fd);
+       pattern = "-l 1 -L list -T test+owner@test -F test+bounces-help@test -m list/queue/";
+       if (strncmp(content, pattern, strlen(pattern)) != 0)
+               atf_tc_fail("Invalid command: '%s'", content);
+       path = strrchr(content, ' ');
+       path++;
+       if (!atf_utils_grep_file(".*The address <test@plop> has been unsubscribed from the list.*", path)) {
+               atf_utils_cat_file(path, "");
+               atf_tc_fail("invalid file");
+       }
+       if (!atf_utils_grep_file(".*administrator commanded it.*", path)) {
+               atf_utils_cat_file(path, "");
+               atf_tc_fail("invalid file");
+       }
+
+       p = atf_utils_fork();
+       if (p == 0) {
+               notify_sub(&ml, "test@plop", "/bin/echo", SUB_NOMAIL,
+                   SUB_CONFIRM, false);
+       }
+       atf_utils_wait(p, 0, "save:plop.txt", "");
+       fd = open("plop.txt", O_RDONLY);
+       content = atf_utils_readline(fd);
+       close(fd);
+       pattern = "-l 1 -L list -T test+owner@test -F test+bounces-help@test -m list/queue/";
+       if (strncmp(content, pattern, strlen(pattern)) != 0)
+               atf_tc_fail("Invalid command: '%s'", content);
+       path = strrchr(content, ' ');
+       path++;
+       if (!atf_utils_grep_file(".*The address <test@plop> has been unsubscribed from the list.*", path)) {
+               atf_utils_cat_file(path, "");
+               atf_tc_fail("invalid file");
+       }
+       if (!atf_utils_grep_file(".*request to unsubscribe was confirmed.*", path)) {
+               atf_utils_cat_file(path, "");
+               atf_tc_fail("invalid file");
+       }
+
+       p = atf_utils_fork();
+       if (p == 0) {
+               notify_sub(&ml, "test@plop", "/bin/echo", SUB_BOTH,
+                   SUB_REQUEST, false);
+       }
+       atf_utils_wait(p, 0, "save:plop.txt", "");
+       fd = open("plop.txt", O_RDONLY);
+       content = atf_utils_readline(fd);
+       close(fd);
+       pattern = "-l 1 -L list -T test+owner@test -F test+bounces-help@test -m list/queue/";
+       if (strncmp(content, pattern, strlen(pattern)) != 0)
+               atf_tc_fail("Invalid command: '%s'", content);
+       path = strrchr(content, ' ');
+       path++;
+       if (!atf_utils_grep_file(".*The address <test@plop> has been unsubscribed from the list.*", path)) {
+               atf_utils_cat_file(path, "");
+               atf_tc_fail("invalid file");
+       }
+       if (!atf_utils_grep_file(".*request to unsubscribe was received.*", path)) {
+               atf_utils_cat_file(path, "");
+               atf_tc_fail("invalid file");
+       }
 }
 
 ATF_TP_ADD_TCS(tp)