From: Baptiste Daroussin Date: Fri, 10 Feb 2023 17:03:07 +0000 (+0100) Subject: notify-sub: use the same function from subscribtion and unsubscribtion X-Git-Tag: RELEASE_1_4_0b1~175 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db82526dce6c8da8e2f1165a1053104e8d798fa7;p=thirdparty%2Fmlmmj.git notify-sub: use the same function from subscribtion and unsubscribtion --- diff --git a/include/subscriberfuncs.h b/include/subscriberfuncs.h index 07cececd..0489430d 100644 --- a/include/subscriberfuncs.h +++ b/include/subscriberfuncs.h @@ -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 */ diff --git a/src/mlmmj-sub.c b/src/mlmmj-sub.c index daf855d4..27256422 100644 --- a/src/mlmmj-sub.c +++ b/src/mlmmj-sub.c @@ -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); diff --git a/src/mlmmj-unsub.c b/src/mlmmj-unsub.c index f208888b..79b3bc02 100644 --- a/src/mlmmj-unsub.c +++ b/src/mlmmj-unsub.c @@ -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); diff --git a/src/subscriberfuncs.c b/src/subscriberfuncs.c index a13dc1e9..987b21b6 100644 --- a/src/subscriberfuncs.c +++ b/src/subscriberfuncs.c @@ -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); diff --git a/tests/mlmmj.c b/tests/mlmmj.c index 1ceb54f9..cddf16c6 100644 --- a/tests/mlmmj.c +++ b/tests/mlmmj.c @@ -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 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 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 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 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)