]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
notify-sub: do not call mlmmj-send anymore
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 15 Feb 2023 12:45:48 +0000 (13:45 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 15 Feb 2023 12:51:06 +0000 (13:51 +0100)
include/subscriberfuncs.h
src/mlmmj-sub.c
src/mlmmj-unsub.c
src/subscriberfuncs.c
tests/mlmmj.c
tests/mlmmj_tests.c
tests/mlmmj_tests.h

index 0489430d0814ffbbd04a148d2dacb9f88b477617..d608b0b8295d167dc2db54c83c72cf518e7b6d86 100644 (file)
@@ -1,6 +1,6 @@
-/* Copyright (C) 2003 Mads Martin Joergensen <mmj at mmj.dk>
- *
- * $Id$
+/*
+ * Copyright (C) 2003 Mads Martin Joergensen <mmj at mmj.dk>
+ * Copyright (C) 2023 Baptiste Daroussin <bapt@FreeBSD.org>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -21,8 +21,7 @@
  * IN THE SOFTWARE.
  */
 
-#ifndef SUBSCRIBERFUNC_H
-#define SUBSCRIBERFUNC_H
+#pragma once
 
 #include <stdbool.h>
 
@@ -30,7 +29,5 @@ bool find_subscriber(int fd, const char *address);
 int is_subbed_in(int fd, const char *subddirname, const char *address);
 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,
+void notify_sub(struct ml *ml, const char *subaddr, enum subtype typesub,
                enum subreason reasonsub, bool sub);
-#endif /* SUBSCRIBERFUNC_H */
index 523d3df2d89e3c51d33b19f79fa87630b201bfbf..cbc0eb9186188c7d7d70c6bed8cda10a28090cce 100644 (file)
@@ -674,7 +674,7 @@ int main(int argc, char **argv)
 
        /* Notify list owner about subscription */
        if (notifysub)
-               notify_sub(&ml, address, mlmmjsend, typesub, reasonsub, true);
+               notify_sub(&ml, address, typesub, reasonsub, true);
 
        free(address);
        free(mlmmjsend);
index b407e1535dcb4a1134b20065f6c5744f99709018..94f80b0b0c1313bd17507cadc31e467e67ef7ecc 100644 (file)
@@ -372,7 +372,7 @@ int main(int argc, char **argv)
 
         /* Notify list owner about subscription */
         if (notifysub)
-                notify_sub(&ml, address, mlmmjsend, typesub, reasonsub, false);
+                notify_sub(&ml, address, typesub, reasonsub, false);
 
        free(address);
        free(mlmmjsend);
index e8c89c2cbe8cb4905111c55ad1e0c9e21a746b90..23b9fcef2181dce3aeee75f534b0e1819a6436d2 100644 (file)
@@ -34,6 +34,7 @@
 #include "utils.h"
 #include "prepstdreply.h"
 #include "xmalloc.h"
+#include "send_mail.h"
 
 char *subtype_strs[] = {
        "normal",
@@ -165,15 +166,16 @@ get_subcookie_content(int listfd, bool unsub, const char *param)
        return (NULL);
 }
 
-void notify_sub(struct ml *ml, const char *subaddr,
-               const char *mlmmjsend, enum subtype typesub,
+void notify_sub(struct ml *ml, const char *subaddr, enum subtype typesub,
                enum subreason reasonsub, bool sub)
 {
        char *fromaddr, *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");
 
@@ -205,7 +207,13 @@ void notify_sub(struct ml *ml, const char *subaddr,
        MY_ASSERT(queuefilename);
        close_text(txt);
 
-       exec_or_die(mlmmjsend, "-l", "1", "-L", ml->dir, "-T", tostr,
-           "-F", fromaddr, "-m", queuefilename, NULL);
+       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);
+       }
+       exit(EXIT_SUCCESS);
 }
 
index 6a5921d873ff9f579c6b1c7649b086a133bef80c..1d34cbcd5cd35362ba05c26f3982c7bb914b34c4 100644 (file)
@@ -1780,9 +1780,8 @@ ATF_TC_BODY(list_subs, tc)
 
 ATF_TC_BODY(notify_sub, tc)
 {
-       int fd;
-       char *dir, *content;
-       const char *path, *pattern;
+       char *dir;
+       const char *path;
        init_ml(true);
        struct ml ml;
        ml_init(&ml);
@@ -1793,22 +1792,19 @@ ATF_TC_BODY(notify_sub, tc)
            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) {
-               notify_sub(&ml, "test@plop", "/bin/echo", SUB_NORMAL,
-                   SUB_ADMIN, true);
+               notify_sub(&ml, "test@plop", SUB_NORMAL, SUB_ADMIN, true);
        }
-       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++;
+       atf_utils_wait(p2, 0, "save:mailout.txt", "");
+       atf_utils_wait(p, 0, "", "");
+       path = "mailout.txt";
        if (!atf_utils_grep_file(".*The address <test@plop> has been subscribed to the normal.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
@@ -1819,20 +1815,14 @@ ATF_TC_BODY(notify_sub, tc)
                atf_tc_fail("invalid file");
        }
 
+       p2 = single_mail_reception(smtppipe[1]);
+       atf_utils_readline(smtppipe[0]);
        p = atf_utils_fork();
        if (p == 0) {
-               notify_sub(&ml, "test@plop", "/bin/echo", SUB_DIGEST,
-                   SUB_ADMIN, true);
+               notify_sub(&ml, "test@plop", SUB_DIGEST, SUB_ADMIN, true);
        }
-       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++;
+       atf_utils_wait(p2, 0, "save:mailout.txt", "");
+       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*The address <test@plop> has been subscribed to the digest.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
@@ -1842,20 +1832,14 @@ ATF_TC_BODY(notify_sub, tc)
                atf_tc_fail("invalid file");
        }
 
+       p2 = single_mail_reception(smtppipe[1]);
+       atf_utils_readline(smtppipe[0]);
        p = atf_utils_fork();
        if (p == 0) {
-               notify_sub(&ml, "test@plop", "/bin/echo", SUB_NOMAIL,
-                   SUB_CONFIRM, true);
+               notify_sub(&ml, "test@plop", SUB_NOMAIL, SUB_CONFIRM, true);
        }
-       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++;
+       atf_utils_wait(p2, 0, "save:mailout.txt", "");
+       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*The address <test@plop> has been subscribed to the no-mail.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
@@ -1865,20 +1849,14 @@ ATF_TC_BODY(notify_sub, tc)
                atf_tc_fail("invalid file");
        }
 
+       p2 = single_mail_reception(smtppipe[1]);
+       atf_utils_readline(smtppipe[0]);
        p = atf_utils_fork();
        if (p == 0) {
-               notify_sub(&ml, "test@plop", "/bin/echo", SUB_BOTH,
-                   SUB_REQUEST, true);
+               notify_sub(&ml, "test@plop", SUB_BOTH, SUB_REQUEST, true);
        }
-       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++;
+       atf_utils_wait(p2, 0, "save:mailout.txt", "");
+       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*The address <test@plop> has been subscribed to the version.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
@@ -1888,21 +1866,14 @@ ATF_TC_BODY(notify_sub, tc)
                atf_tc_fail("invalid file");
        }
 
+       p2 = single_mail_reception(smtppipe[1]);
+       atf_utils_readline(smtppipe[0]);
        p = atf_utils_fork();
        if (p == 0) {
-               notify_sub(&ml, "test@plop", "/bin/echo", SUB_NORMAL,
-                   SUB_ADMIN, false);
+               notify_sub(&ml, "test@plop", 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++;
+       atf_utils_wait(p2, 0, "save:mailout.txt", "");
+       atf_utils_wait(p, 0, "", "");
        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");
@@ -1913,20 +1884,14 @@ ATF_TC_BODY(notify_sub, tc)
                atf_tc_fail("invalid file");
        }
 
+       p2 = single_mail_reception(smtppipe[1]);
+       atf_utils_readline(smtppipe[0]);
        p = atf_utils_fork();
        if (p == 0) {
-               notify_sub(&ml, "test@plop", "/bin/echo", SUB_DIGEST,
-                   SUB_ADMIN, false);
+               notify_sub(&ml, "test@plop", 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++;
+       atf_utils_wait(p2, 0, "save:mailout.txt", "");
+       atf_utils_wait(p, 0, "", "");
        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");
@@ -1936,43 +1901,31 @@ ATF_TC_BODY(notify_sub, tc)
                atf_tc_fail("invalid file");
        }
 
+       p2 = single_mail_reception(smtppipe[1]);
+       atf_utils_readline(smtppipe[0]);
        p = atf_utils_fork();
        if (p == 0) {
-               notify_sub(&ml, "test@plop", "/bin/echo", SUB_NOMAIL,
-                   SUB_CONFIRM, false);
+               notify_sub(&ml, "test@plop", 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++;
+       atf_utils_wait(p2, 0, "save:mailout.txt", "");
+       atf_utils_wait(p, 0, "", "");
        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_tc_fail("invalid file unsubscribe nomail confirm");
        }
        if (!atf_utils_grep_file(".*request to unsubscribe was confirmed.*", 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) {
-               notify_sub(&ml, "test@plop", "/bin/echo", SUB_BOTH,
-                   SUB_REQUEST, false);
+               notify_sub(&ml, "test@plop", 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++;
+       atf_utils_wait(p2, 0, "save:mailout.txt", "");
+       atf_utils_wait(p, 0, "", "");
        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");
@@ -2129,11 +2082,7 @@ ATF_TC_BODY(send_single_mail, tc)
        atf_utils_create_file("list/control/smtpport", "25678");
        int smtppipe[2];
        ATF_REQUIRE(socketpair(AF_UNIX, SOCK_STREAM, 0, smtppipe) >= 0);
-       pid_t p = atf_utils_fork();
-       if (p == 0) {
-               single_mail_reception(smtppipe[1]);
-               exit(0);
-       }
+       pid_t p = single_mail_reception(smtppipe[1]);
        close(smtppipe[1]);
        atf_utils_readline(smtppipe[0]);
        atf_utils_create_file("list/control/smtphelo", "heloname");
index 89130197347017795ba796ae1ab4c1bc30da7474..5bef57eb29491c52ec3ac1d1d4c132947c846553 100644 (file)
@@ -107,42 +107,47 @@ read_print_reply(int fd, const char **replies, size_t nreplies)
        }
 }
 
-void
+pid_t
 single_mail_reception(int fd)
 {
-       int s = fakesmtp(fd);
-       int c;
-       char *r;
-       struct sockaddr_in cl;
-       socklen_t clsize = 0;
-       c = accept(s, (struct sockaddr *) &cl, &clsize);
-       if (c == -1)
-               exit(5);
-       dprintf(c, "220 me fake smtp\n");
+       pid_t p = atf_utils_fork();
+       if (p == 0) {
+               int s = fakesmtp(fd);
+               int c;
+               char *r;
+               struct sockaddr_in cl;
+               socklen_t clsize = 0;
+               c = accept(s, (struct sockaddr *) &cl, &clsize);
+               if (c == -1)
+                       exit(5);
+               dprintf(c, "220 me fake smtp\n");
 
-       const char *replies[] = {
-               "250-hostname.net\n"
-               "250-PIPELINEING\n"
-               "250-SIZE 20480000\n"
-               "250-ETRN\n"
-               "250-STARTTLS\n"
-               "250-ENHANCEDSTATUSCODES\n"
-               "250-8BITMIME\n"
-               "250-DSN\n"
-               "250-SMTPUTF8\n"
-               "250 CHUNKING\n",
-               "250 2.1.0 OK\n",
-               "250 2.1.0 OK\n",
-               "350 2.1.0 OK\n",
-       };
-       read_print_reply(c, replies, NELEM(replies));
-       while ((r = atf_utils_readline(c)) != NULL) {
-               printf("%s\n", r);
-               if (strcmp(r, ".\r") == 0) {
-                       dprintf(c, "250 2.1.0 OK\n");
-                       break;
+               const char *replies[] = {
+                       "250-hostname.net\n"
+                       "250-PIPELINEING\n"
+                       "250-SIZE 20480000\n"
+                       "250-ETRN\n"
+                       "250-STARTTLS\n"
+                       "250-ENHANCEDSTATUSCODES\n"
+                       "250-8BITMIME\n"
+                       "250-DSN\n"
+                       "250-SMTPUTF8\n"
+                       "250 CHUNKING\n",
+                       "250 2.1.0 OK\n",
+                       "250 2.1.0 OK\n",
+                       "350 2.1.0 OK\n",
+               };
+               read_print_reply(c, replies, NELEM(replies));
+               while ((r = atf_utils_readline(c)) != NULL) {
+                       printf("%s\n", r);
+                       if (strcmp(r, ".\r") == 0) {
+                               dprintf(c, "250 2.1.0 OK\n");
+                               break;
+                       }
                }
+               const char *rep = "221 2.0.0 bye\n";
+               read_print_reply(c, &rep, 1);
+               exit(0);
        }
-       const char *rep = "221 2.0.0 bye\n";
-       read_print_reply(c, &rep, 1);
+       return (p);
 }
index f6431d7e3ad40f5080dbab5a3b624671f23bb045..ced30cc4e9d53d7e1a46bc004557b8ee7ca0a976 100644 (file)
@@ -32,4 +32,4 @@
 void init_ml(bool complete);
 int fakesmtp(int pipe);
 void read_print_reply(int fd, const char **replies, size_t nreplies);
-void single_mail_reception(int fd);
+pid_t single_mail_reception(int fd);