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)
/* 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);
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;
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. */
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);
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);
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);
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);
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);
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)