free(modfilename);
}
-void confirm_sub(struct ml *ml, const char *subaddr,
- const char *mlmmjsend, enum subtype typesub,
- enum subreason reasonsub)
-{
- text *txt;
- char *queuefilename, *fromaddr, *listtext;
-
- gen_addr(fromaddr, ml, "bounces-help");
-
- switch(typesub) {
- default:
- case SUB_NORMAL:
- listtext = xstrdup("sub-ok");
- break;
- case SUB_DIGEST:
- listtext = xstrdup("sub-ok-digest");
- break;
- case SUB_NOMAIL:
- listtext = xstrdup("sub-ok-nomail");
- break;
- case SUB_BOTH:
- /* No legacy list text as feature didn't exist. */
- listtext = xstrdup("sub-ok");
- break;
- }
-
- txt = open_text(ml->fd, "finish", "sub",
- subreason_strs[reasonsub], subtype_strs[typesub],
- listtext);
- free(listtext);
- MY_ASSERT(txt);
- register_default_unformatted(txt, ml);
- register_unformatted(txt, "subaddr", subaddr);
- queuefilename = prepstdreply(txt, ml, "$helpaddr$", subaddr, NULL);
- MY_ASSERT(queuefilename);
- close_text(txt);
-
- exec_or_die(mlmmjsend, "-l", "1", "-L", ml->dir, "-T", subaddr, "-F",
- fromaddr, "-m", queuefilename, NULL);
-}
-
static void print_help(const char *prg)
{
printf("Usage: %s -L /path/to/list {-a john@doe.org | -m str}\n"
if(childpid < 0) {
log_error(LOG_ARGS, "Could not fork; owner not notified");
- confirm_sub(&ml, address, mlmmjsend, typesub, reasonsub);
+ confirm_sub(&ml, address, typesub, reasonsub, true);
}
if(childpid > 0) {
/* child confirms subscription */
if(childpid == 0)
- confirm_sub(&ml, address, mlmmjsend, typesub, reasonsub);
+ confirm_sub(&ml, address, typesub, reasonsub, true);
}
notifysub = !quiet && reasonsub != SUB_SWITCH &&
#include "prepstdreply.h"
#include "utils.h"
-void confirm_unsub(struct ml *ml, const char *subaddr, const char *mlmmjsend,
- enum subtype typesub, enum subreason reasonsub)
-{
- text *txt;
- char *queuefilename, *fromaddr, *listtext;
-
- gen_addr(fromaddr, ml, "bounces-help");
-
- switch(typesub) {
- default:
- case SUB_NORMAL:
- listtext = xstrdup("unsub-ok");
- break;
- case SUB_DIGEST:
- listtext = xstrdup("unsub-ok-digest");
- break;
- case SUB_NOMAIL:
- listtext = xstrdup("unsub-ok-nomail");
- break;
- }
-
- txt = open_text(ml->fd, "finish", "unsub",
- subreason_strs[reasonsub], subtype_strs[typesub],
- listtext);
- free(listtext);
- MY_ASSERT(txt);
- register_default_unformatted(txt, ml);
- register_unformatted(txt, "subaddr", subaddr);
- queuefilename = prepstdreply(txt, ml, "$helpaddr$", subaddr, NULL);
- MY_ASSERT(queuefilename);
- close_text(txt);
-
- exec_or_die(mlmmjsend, "-l", "1", "-L", ml->dir, "-T", subaddr, "-F",
- fromaddr, "-m", queuefilename, NULL);
-}
-
static void print_help(const char *prg)
{
printf("Usage: %s -L /path/to/list -a john@doe.org\n"
if(childpid < 0) {
log_error(LOG_ARGS, "Could not fork");
- confirm_unsub(&ml, address, mlmmjsend, typesub, reasonsub);
+ confirm_sub(&ml, address, typesub, reasonsub, false);
}
if(childpid > 0) {
/* child confirms subscription */
if(childpid == 0)
- confirm_unsub(&ml, address, mlmmjsend, typesub, reasonsub);
+ confirm_sub(&ml, address, typesub, reasonsub, false);
}
notifysub = !quiet && statctrl(ml.ctrlfd, "notifysub");
exit(EXIT_SUCCESS);
}
+void
+confirm_sub(struct ml *ml, const char *subaddr, enum subtype typesub,
+ enum subreason reasonsub, bool sub)
+{
+ text *txt;
+ char *queuefilename, *fromaddr;
+ const char *listtext;
+ struct mail mail;
+
+ memset(&mail, 0, sizeof(mail));
+ gen_addr(fromaddr, ml, "bounces-help");
+
+ switch(typesub) {
+ default:
+ case SUB_BOTH: /* FALLTHROUGH */
+ case SUB_NORMAL:
+ listtext = sub ? "sub-ok" : "unsub-ok";
+ break;
+ case SUB_DIGEST:
+ listtext = sub ? "sub-ok-digest" : "unsub-ok-digest";
+ break;
+ case SUB_NOMAIL:
+ listtext = sub ? "sub-ok-nomail" : "unsub-ok-nomail";
+ break;
+ }
+
+ txt = open_text(ml->fd, "finish", sub ? "sub" : "unsub",
+ subreason_strs[reasonsub], subtype_strs[typesub],
+ listtext);
+ MY_ASSERT(txt);
+ register_default_unformatted(txt, ml);
+ register_unformatted(txt, "subaddr", subaddr);
+ queuefilename = prepstdreply(txt, ml, "$helpaddr$", subaddr, NULL);
+ MY_ASSERT(queuefilename);
+ close_text(txt);
+
+ mail.to = subaddr;
+ mail.from = fromaddr;
+ mail.fp = fopen(queuefilename, "r");
+ if (!send_single_mail(&mail, ml, false)) {
+ save_queue(queuefilename, &mail);
+ exit(EXIT_FAILURE);
+ }
+ exit(EXIT_SUCCESS);
+}
+
ATF_TC_WITHOUT_HEAD(send_single_mail);
ATF_TC_WITHOUT_HEAD(generate_subscription);
ATF_TC_WITHOUT_HEAD(generate_subconfirm);
+ATF_TC_WITHOUT_HEAD(confirm_sub);
ATF_TC_BODY(random_int, tc)
{
atf_utils_cat_file(path, "");
atf_tc_fail("invalid file");
}
- return;
+}
+
+ATF_TC_BODY(confirm_sub, tc)
+{
+ char *dir;
+ const char *path;
+ init_ml(true);
+ struct ml ml;
+ ml_init(&ml);
+ ml.dir = "list";
+ ml_open(&ml, false);
+ rmdir("list/text");
+ xasprintf(&dir, "%s/../listtexts/en",
+ atf_tc_get_config_var(tc, "srcdir"));
+
+ symlink(dir, "list/text");
+ atf_utils_create_file("list/control/smtpport", "25678");
+ atf_utils_create_file("list/control/smtphelo", "heloname");
+ int smtppipe[2];
+ ATF_REQUIRE(socketpair(AF_UNIX, SOCK_STREAM, 0, smtppipe) >= 0);
+ pid_t p2 = single_mail_reception(smtppipe[1]);
+ atf_utils_readline(smtppipe[0]);
+ pid_t p = atf_utils_fork();
+ if (p == 0) {
+ confirm_sub(&ml, "test@plop", SUB_NORMAL, SUB_ADMIN, true);
+ }
+ atf_utils_wait(p2, 0, "save:mailout.txt", "");
+ atf_utils_wait(p, 0, "", "");
+ path = "mailout.txt";
+ if (!atf_utils_grep_file(".*An administrator has subscribed you to the normal version of the list.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+ if (!atf_utils_grep_file(".*The email address you are subscribed with is <test@plop>.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+
+ p2 = single_mail_reception(smtppipe[1]);
+ atf_utils_readline(smtppipe[0]);
+ p = atf_utils_fork();
+ if (p == 0) {
+ confirm_sub(&ml, "test@plop", SUB_DIGEST, SUB_ADMIN, true);
+ }
+ atf_utils_wait(p2, 0, "save:mailout.txt", "");
+ atf_utils_wait(p, 0, "", "");
+ if (!atf_utils_grep_file(".*An administrator has subscribed you to the digest version of the list.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+ if (!atf_utils_grep_file(".*The email address you are subscribed with is <test@plop>.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+
+ p2 = single_mail_reception(smtppipe[1]);
+ atf_utils_readline(smtppipe[0]);
+ p = atf_utils_fork();
+ if (p == 0) {
+ confirm_sub(&ml, "test@plop", SUB_NOMAIL, SUB_CONFIRM, true);
+ }
+ atf_utils_wait(p2, 0, "save:mailout.txt", "");
+ atf_utils_wait(p, 0, "", "");
+ if (!atf_utils_grep_file(".*Thank you for confirming your subscription. You have now been added to the.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+ if (!atf_utils_grep_file(".*no-mail version of the list..*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+
+ p2 = single_mail_reception(smtppipe[1]);
+ atf_utils_readline(smtppipe[0]);
+ p = atf_utils_fork();
+ if (p == 0) {
+ confirm_sub(&ml, "test@plop", SUB_BOTH, SUB_REQUEST, true);
+ }
+ atf_utils_wait(p2, 0, "save:mailout.txt", "");
+ atf_utils_wait(p, 0, "", "");
+ if (!atf_utils_grep_file(".*Thank you for your request to join us. You have now been added to the.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+ if (!atf_utils_grep_file(".*The email address you are subscribed with is <test@plop>.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+
+ p2 = single_mail_reception(smtppipe[1]);
+ atf_utils_readline(smtppipe[0]);
+ p = atf_utils_fork();
+ if (p == 0) {
+ confirm_sub(&ml, "test@plop", SUB_NORMAL, SUB_ADMIN, false);
+ }
+ atf_utils_wait(p2, 0, "save:mailout.txt", "");
+ atf_utils_wait(p, 0, "", "");
+ if (!atf_utils_grep_file(".*An administrator has removed you from the list.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+
+ p2 = single_mail_reception(smtppipe[1]);
+ atf_utils_readline(smtppipe[0]);
+ p = atf_utils_fork();
+ if (p == 0) {
+ confirm_sub(&ml, "test@plop", SUB_DIGEST, SUB_ADMIN, false);
+ }
+ atf_utils_wait(p2, 0, "save:mailout.txt", "");
+ atf_utils_wait(p, 0, "", "");
+ if (!atf_utils_grep_file(".*An administrator has removed you from the list.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
+
+ p2 = single_mail_reception(smtppipe[1]);
+ atf_utils_readline(smtppipe[0]);
+ p = atf_utils_fork();
+ if (p == 0) {
+ confirm_sub(&ml, "test@plop", SUB_NOMAIL, SUB_CONFIRM, false);
+ }
+ atf_utils_wait(p2, 0, "save:mailout.txt", "");
+ atf_utils_wait(p, 0, "", "");
+ if (!atf_utils_grep_file(".*Thank you for confirming your unsubscribe. You have now been removed from.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file unsubscribe nomail confirm");
+ }
+
+ p2 = single_mail_reception(smtppipe[1]);
+ atf_utils_readline(smtppipe[0]);
+ p = atf_utils_fork();
+ if (p == 0) {
+ confirm_sub(&ml, "test@plop", SUB_BOTH, SUB_REQUEST, false);
+ }
+ atf_utils_wait(p2, 0, "save:mailout.txt", "");
+ atf_utils_wait(p, 0, "", "");
+ if (!atf_utils_grep_file(".*You have now been removed from the list.*", path)) {
+ atf_utils_cat_file(path, "");
+ atf_tc_fail("invalid file");
+ }
}
ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, send_single_mail);
ATF_TP_ADD_TC(tp, generate_subscription);
ATF_TP_ADD_TC(tp, generate_subconfirm);
+ ATF_TP_ADD_TC(tp, confirm_sub);
return (atf_no_error());
}