]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
send_help: test, use send_mail and generalize its usage
authorBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 16 Feb 2023 14:16:56 +0000 (15:16 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 16 Feb 2023 14:16:56 +0000 (15:16 +0100)
include/send_help.h
include/send_list.h
src/listcontrol.c
src/mlmmj-process.c
src/mlmmj-sub.c
src/send_help.c
src/send_list.c
src/send_mail.c
src/subscriberfuncs.c
tests/mlmmj.c

index d8ce9b90479828173a0a8a63e581e5e4ca042eef..deea3d80b8fe03f0a649bad36aba3b9a6c3220eb 100644 (file)
@@ -23,5 +23,4 @@
 
 #pragma once
 
-void send_help(struct ml *ml, const char *queuefilename,
-               const char *emailaddr, const char *mlmmjsend);
+void send_help(struct ml *ml, const char *queuefilename, const char *emailaddr);
index e79bf10c81fcb619b73f8d2aae8d329f3ad62a37..6051ea5fd36a3df8094e8c790ecb871c45d9d2af 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "mlmmj.h"
 
-void send_list(struct ml *ml, const char *emailaddr, const char *mlmmjsend);
+void send_list(struct ml *ml, const char *emailaddr);
 struct subs_list_state;
 struct subs_list_state *init_subs_list(int fd, const char *dirname);
 void rewind_subs_list(void *state);
index 1d72a8c0ed4abd467b1d2ba7771da1ea60edbc57..198e8b157bc46b7a125b38fa2b3081a2cf838039 100644 (file)
@@ -213,8 +213,7 @@ int listcontrol(strlist *fromemails, struct ml *ml,
                                        tll_front(*fromemails), NULL);
                        MY_ASSERT(queuefilename);
                        close_text(txt);
-                       send_help(ml, queuefilename,
-                           tll_front(*fromemails), mlmmjsend);
+                       send_help(ml, queuefilename, tll_front(*fromemails));
                        return -1;
                }
                log_oper(ml->fd, OPLOGFNAME, "mlmmj-sub: request for digest"
@@ -249,8 +248,7 @@ int listcontrol(strlist *fromemails, struct ml *ml,
                                        tll_front(*fromemails), NULL);
                        MY_ASSERT(queuefilename);
                        close_text(txt);
-                       send_help(ml, queuefilename,
-                                       tll_front(*fromemails), mlmmjsend);
+                       send_help(ml, queuefilename, tll_front(*fromemails));
                        return -1;
                }
                log_oper(ml->fd, OPLOGFNAME, "mlmmj-sub: request for nomail"
@@ -285,8 +283,7 @@ int listcontrol(strlist *fromemails, struct ml *ml,
                                        tll_front(*fromemails), NULL);
                        MY_ASSERT(queuefilename);
                        close_text(txt);
-                       send_help(ml, queuefilename,
-                                       tll_front(*fromemails), mlmmjsend);
+                       send_help(ml, queuefilename, tll_front(*fromemails));
                        return -1;
                }
                log_oper(ml->fd, OPLOGFNAME, "mlmmj-sub: request for both"
@@ -603,8 +600,7 @@ permit:
                                "$listowner$", tll_front(*fromemails), NULL);
                MY_ASSERT(queuefilename);
                close_text(txt);
-               send_help(ml, queuefilename,
-                               tll_front(*fromemails), mlmmjsend);
+               send_help(ml, queuefilename, tll_front(*fromemails));
                break;
 
        /* listname+faq@domain.tld */
@@ -626,8 +622,7 @@ permit:
                                "$listowner$", tll_front(*fromemails), NULL);
                MY_ASSERT(queuefilename);
                close_text(txt);
-               send_help(ml, queuefilename,
-                               tll_front(*fromemails), mlmmjsend);
+               send_help(ml, queuefilename, tll_front(*fromemails));
                break;
 
        /* listname+get-INDEX@domain.tld */
@@ -697,7 +692,7 @@ permit:
                                " Ignoring mail");
                        return -1;
                } else {
-                       send_list(ml, owner, mlmmjsend);
+                       send_list(ml, owner);
                }
                if (owners != NULL)
                        tll_free_and_free(*owners, free);
index 8d0e803e397945d22cd09ba609fbafde0eea0512..d72ab7ead5d3c812b504acf1fe11264059d2b36e 100644 (file)
@@ -53,6 +53,7 @@
 #include "mlmmj-process.h"
 #include "utils.h"
 #include "xstring.h"
+#include "send_help.h"
 
 enum action {
        ALLOW,
@@ -367,7 +368,6 @@ int main(int argc, char **argv)
        char *randomstr = NULL, *mqueuename, *omitfilename;
        char *mlmmjsend, *mlmmjsub, *mlmmjunsub;
        char *bindir, *subjectprefix, *discardname;
-       char *fromaddr;
        text *txt;
        char *queuefilename, *recipextra = NULL, *owner = NULL;
        char *maxmailsizestr;
@@ -698,7 +698,6 @@ int main(int argc, char **argv)
                                exit(EXIT_SUCCESS);
                        }
 
-                       gen_addr(fromaddr, &ml, "bounces-help");
                        txt = open_text(ml.fd, "deny", "post",
                                        "maxmailsize", NULL, "maxmailsize");
                        MY_ASSERT(txt);
@@ -715,9 +714,7 @@ int main(int argc, char **argv)
                        unlink(mailfile);
                        free(donemailname);
                        free(maxmailsizestr);
-                       exec_or_die(mlmmjsend, "-l", "1", "-L", ml.dir, "-T",
-                           posteraddr, "-F", fromaddr, "-m", queuefilename,
-                           NULL);
+                       send_help(&ml, queuefilename, posteraddr);
                }
        }
 
@@ -755,7 +752,6 @@ int main(int argc, char **argv)
                        free(donemailname);
                        exit(EXIT_SUCCESS);
                }
-               gen_addr(fromaddr, &ml, "bounces-help");
                txt = open_text(ml.fd, "deny", "post",
                                "tocc", NULL, "notintocc");
                MY_ASSERT(txt);
@@ -769,8 +765,7 @@ int main(int argc, char **argv)
                close_text(txt);
                unlink(donemailname);
                free(donemailname);
-               exec_or_die(mlmmjsend, "-l", "1", "-L", ml.dir, "-T",
-                   posteraddr, "-F", fromaddr, "-m", queuefilename, NULL);
+               send_help(&ml, queuefilename, posteraddr);
        }
 
        access_rules = ctrlvalues(ml.ctrlfd, "access");
@@ -793,7 +788,6 @@ int main(int argc, char **argv)
                                free(donemailname);
                                exit(EXIT_SUCCESS);
                        }
-                       gen_addr(fromaddr, &ml, "bounces-help");
                        txt = open_text(ml.fd, "deny", "post",
                                        "access", NULL, "access");
                        MY_ASSERT(txt);
@@ -808,9 +802,7 @@ int main(int argc, char **argv)
                        unlink(donemailname);
                        free(donemailname);
                        free(randomstr);
-                       exec_or_die(mlmmjsend, "-l", "1", "-L", ml.dir, "-T",
-                           posteraddr, "-F", fromaddr, "-m", queuefilename,
-                           NULL);
+                       send_help(&ml, queuefilename, posteraddr);
                } else if (accret == MODERATE) {
                        moderated = 1;
                        modreason = ACCESS;
@@ -891,7 +883,6 @@ int main(int argc, char **argv)
                                free(donemailname);
                                exit(EXIT_SUCCESS);
                            }
-                           gen_addr(fromaddr, &ml, "bounces-help");
                            if (subonlypost) {
                                txt = open_text(ml.fd, "deny", "post",
                                        "subonlypost", NULL, "subonlypost");
@@ -910,9 +901,7 @@ int main(int argc, char **argv)
                            close_text(txt);
                            unlink(donemailname);
                            free(donemailname);
-                               exec_or_die(mlmmjsend, "-L", ml.dir, "-l", "1",
-                                   "-T", testaddr, "-F", fromaddr, "-m",
-                                   queuefilename, NULL);
+                           send_help(&ml, queuefilename, testaddr);
                        }
                }
        }
index 5c8bd9140687f7d3f4f61f45809de447d5671fb9..c7943c18d89cf6e842a280a71f87389a817692d9 100644 (file)
@@ -48,6 +48,7 @@
 #include "ctrlvalues.h"
 #include "chomp.h"
 #include "utils.h"
+#include "send_help.h"
 
 static void moderate_sub(struct ml *ml, const char *subaddr,
                const char *mlmmjsend, enum subtype typesub,
@@ -186,8 +187,6 @@ static void moderate_sub(struct ml *ml, const char *subaddr,
        
        /* send mail to requester that the list is submod'ed */
 
-       gen_addr(from, ml, "bounces-help");
-
        txt = open_text(ml->fd,
                        "wait", "sub",
                        subreason_strs[reasonsub], subtype_strs[typesub],
@@ -203,14 +202,7 @@ static void moderate_sub(struct ml *ml, const char *subaddr,
        close_text(txt);
 
        finish_memory_lines(mls);
-       execl(mlmmjsend, mlmmjsend,
-                               "-l", "1",
-                               "-L", ml->dir,
-                               "-T", subaddr,
-                               "-F", from,
-                               "-m", queuefilename, (char *)NULL);
-       log_error(LOG_ARGS, "execl() of '%s' failed", mlmmjsend);
-       exit(EXIT_FAILURE);
+       send_help(ml, queuefilename, subaddr);
 }
 
 void getaddrandtype(const char *listdir, const char *modstr,
index 9e34ab9cc49215d7f3a63f9f9535c48615fe8833..c115c6f9f2328745de3e6b91878d6c93366559b6 100644 (file)
 #include "send_help.h"
 #include "utils.h"
 #include "xmalloc.h"
+#include "send_mail.h"
 
-void send_help(struct ml *ml, const char *queuefilename,
-               const char *emailaddr, const char *mlmmjsend)
+void
+send_help(struct ml *ml, const char *queuefilename, const char *emailaddr)
 {
        char *fromaddr;
+       struct mail mail;
 
+       memset(&mail, 0, sizeof(mail));
        gen_addr(fromaddr, ml, "bounces-help");
 
-       exec_or_die(mlmmjsend, "-l", "1", "-L", ml->dir, "-T", emailaddr,
-           "-F", fromaddr, "-m", queuefilename, NULL);
+       mail.to = emailaddr;
+       mail.from = fromaddr;
+       mail.fp = fopen(queuefilename, "r");
+       if (!send_single_mail(&mail, ml, false))
+               save_queue(queuefilename, &mail);
+       exit(EXIT_SUCCESS);
 }
index 3f741e4f47b06ab63930bdc8f958085c40a034b7..6b39f0eabc65a2e92d36d143a2cc52b6dca64808 100644 (file)
@@ -39,6 +39,7 @@
 #include "wrappers.h"
 #include "prepstdreply.h"
 #include "utils.h"
+#include "send_help.h"
 
 
 struct subs_list_state {
@@ -137,15 +138,13 @@ void print_subs(int fd, struct subs_list_state *s)
 }
 
 
-void send_list(struct ml *ml, const char *emailaddr, const char *mlmmjsend)
+void send_list(struct ml *ml, const char *emailaddr)
 {
        text *txt;
        struct subs_list_state *normalsls, *digestsls, *nomailsls;
-       char *queuefilename, *fromaddr;
+       char *queuefilename;
        int fd;
 
-       gen_addr(fromaddr, ml, "bounces-help");
-
        normalsls = init_subs_list(ml->fd, "subscribers.d");
        digestsls = init_subs_list(ml->fd, "digesters.d");
        nomailsls = init_subs_list(ml->fd, "nomailsubs.d");
@@ -187,6 +186,5 @@ void send_list(struct ml *ml, const char *emailaddr, const char *mlmmjsend)
        finish_subs_list(digestsls);
        finish_subs_list(nomailsls);
 
-       exec_or_die(mlmmjsend, "-l", "1", "-L", ml->dir, "-T", emailaddr, "-F",
-           fromaddr, "-m", queuefilename, NULL);
+       send_help(ml, queuefilename, emailaddr);
 }
index 577f0c6817d1caff366841aeaac10a565842f8ca..bbe80d2097ad1e0be93bfe1bfe41a298a8423182 100644 (file)
@@ -402,7 +402,7 @@ send_single_mail(struct mail *mail, struct ml *ml, bool bounce)
        sockfd = newsmtp(ml);
        if (sockfd == -1)
                return (false);
-       if (send_mail(sockfd, mail, ml->fd, ml->ctrlfd, bounce) != 0) {
+       if (send_mail(sockfd, mail, ml->fd, ml->ctrlfd, bounce)) {
                endsmtp(&sockfd);
                return (false);
        }
index 0c546ab8fccf2c4262a50cace7b94376c90feefc..d5ea8da8386001b24187162acb6a8c8b3544a712 100644 (file)
@@ -38,6 +38,7 @@
 #include "xmalloc.h"
 #include "send_mail.h"
 #include "strgen.h"
+#include "send_help.h"
 
 char *subtype_strs[] = {
        "normal",
@@ -173,14 +174,11 @@ void
 notify_sub(struct ml *ml, const char *subaddr, enum subtype typesub,
     enum subreason reasonsub, bool sub)
 {
-       char *fromaddr, *tostr;
+       char *tostr;
        text *txt;
        char *queuefilename = NULL;
        const char *listtext = NULL;
-       struct mail mail;
 
-       memset(&mail, 0, sizeof(mail));
-       gen_addr(fromaddr, ml, "bounces-help");
        gen_addr(tostr, ml, "owner");
 
        switch(typesub) {
@@ -211,13 +209,7 @@ notify_sub(struct ml *ml, const char *subaddr, enum subtype typesub,
        MY_ASSERT(queuefilename);
        close_text(txt);
 
-       mail.to = tostr;
-       mail.from = fromaddr;
-       mail.fp = fopen(queuefilename, "r");
-       if (!send_single_mail(&mail, ml, false)) {
-               save_queue(queuefilename, &mail);
-               exit(EXIT_FAILURE);
-       }
+       send_help(ml, queuefilename, tostr);
        exit(EXIT_SUCCESS);
 }
 
@@ -226,12 +218,8 @@ generate_subscription(struct ml *ml, const char *subaddr,
     enum subtype typesub, bool sub)
 {
        text *txt;
-       char *queuefilename, *fromaddr;
-       struct mail mail;
+       char *queuefilename;
 
-       memset(&mail, 0, sizeof(mail));
-
-       gen_addr(fromaddr, ml, "bounces-help");
        txt = open_text(ml->fd, "deny", sub ? "sub" : "unsub",
            sub ? "subbed" : "unsubbed", subtype_strs[typesub],
            sub ? "sub-subscribed" : "unsub-notsubscribed");
@@ -242,14 +230,7 @@ generate_subscription(struct ml *ml, const char *subaddr,
        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);
+       send_help(ml, queuefilename, subaddr);
 }
 
 void
@@ -327,10 +308,8 @@ generate_subconfirm(struct ml *ml, const char *subaddr, enum subtype typesub,
        mail.to = subaddr;
        mail.from = fromaddr;
        mail.fp = fopen(queuefilename, "r");
-       if (!send_single_mail(&mail, ml, false)) {
+       if (!send_single_mail(&mail, ml, false))
                save_queue(queuefilename, &mail);
-               exit(EXIT_FAILURE);
-       }
        exit(EXIT_SUCCESS);
 }
 
@@ -339,12 +318,8 @@ confirm_sub(struct ml *ml, const char *subaddr, enum subtype typesub,
     enum subreason reasonsub, bool sub)
 {
        text *txt;
-       char *queuefilename, *fromaddr;
+       char *queuefilename;
        const char *listtext;
-       struct mail mail;
-
-       memset(&mail, 0, sizeof(mail));
-       gen_addr(fromaddr, ml, "bounces-help");
 
        switch(typesub) {
                default:
@@ -370,13 +345,5 @@ confirm_sub(struct ml *ml, const char *subaddr, enum subtype typesub,
        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);
+       send_help(ml, queuefilename, subaddr);
 }
-
index d44a77149e9e86a839235018f4f2acb474dd13cf..5ac410bf7906819cf10ff51086cbef65135850d9 100644 (file)
@@ -64,6 +64,7 @@
 #include "mlmmj-process.h"
 #include "prepstdreply.h"
 #include "mlmmj_tests.h"
+#include "send_help.h"
 
 ATF_TC_WITHOUT_HEAD(random_int);
 ATF_TC_WITHOUT_HEAD(chomp);
@@ -143,6 +144,7 @@ ATF_TC_WITHOUT_HEAD(generate_subscription);
 ATF_TC_WITHOUT_HEAD(generate_subconfirm);
 ATF_TC_WITHOUT_HEAD(confirm_sub);
 ATF_TC_WITHOUT_HEAD(listcontrol);
+ATF_TC_WITHOUT_HEAD(send_help);
 
 ATF_TC_BODY(random_int, tc)
 {
@@ -2486,6 +2488,48 @@ ATF_TC_BODY(listcontrol, tc)
        ATF_REQUIRE_EQ(listcontrol(&fromemails, &ml, "subscribe", NULL, NULL, NULL, "meh"), -1);
 }
 
+ATF_TC_BODY(send_help, tc)
+{
+       char *dir;
+       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");
+       atf_utils_create_file("mail", "headers\n\nbody\n");
+       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) {
+               send_help(&ml, "mail", "test@plop");
+       }
+       atf_utils_wait(p2, 0, "save:mailout.txt", "");
+       atf_utils_wait(p, 0, "", "");
+       const char *output= "EHLO heloname\r\n"
+               "MAIL FROM:<test+bounces-help@test>\r\n"
+               "RCPT TO:<test@plop>\r\n"
+               "DATA\r\n"
+               "headers\r\n"
+               "\r\n"
+               "body\r\n"
+               "\r\n"
+               ".\r\n"
+               "QUIT\r\n";
+       if (!atf_utils_compare_file("mailout.txt", output)) {
+               atf_utils_cat_file("mailout.txt", "");
+               atf_tc_fail("invalid file");
+       }
+}
+
 ATF_TP_ADD_TCS(tp)
 {
        ATF_TP_ADD_TC(tp, random_int);
@@ -2566,6 +2610,7 @@ ATF_TP_ADD_TCS(tp)
        ATF_TP_ADD_TC(tp, generate_subconfirm);
        ATF_TP_ADD_TC(tp, confirm_sub);
        ATF_TP_ADD_TC(tp, listcontrol);
+       ATF_TP_ADD_TC(tp, send_help);
 
        return (atf_no_error());
 }