]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Replace custom struct email_contianer with generic strlist
authorBaptiste Daroussin <bapt@FreeBSD.org>
Tue, 3 Jan 2023 11:13:10 +0000 (12:13 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Tue, 3 Jan 2023 11:13:10 +0000 (12:13 +0100)
include/find_email_adr.h
include/listcontrol.h
include/mlmmj.h
src/find_email_adr.c
src/listcontrol.c
src/mlmmj-process.c
src/mlmmj.c
tests/mlmmj.c

index 92180889ef5fc318cda24485e55aa0b075b0d5ca..e5da89b3583a5918d86605cc400091b30270eed7 100644 (file)
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002, 2003 Mads Martin Joergensen <mmj at mmj.dk>
- *
- * $Id$
+/*
+ * Copyright (C) 2002, 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
 
 #include <stddef.h>
 
-struct email_container {
-       int emailcount;
-       char **emaillist;
-};
-
-struct email_container *find_email_adr(const char *str,
-               struct email_container *retval);
+strlist *find_email_adr(const char *str, strlist *retval);
 
 #endif /* FIND_EMAIL_ADR_H */
index 78316d95a049b8c0af537207a8217667cf10c0e1..bc45a27247182406b956946683a9c9d94b953fae 100644 (file)
@@ -24,9 +24,9 @@
 #ifndef LISTCONTROL_H
 #define LISTCONTROL_H
 
-#include "find_email_adr.h"
+#include "mlmmj.h"
 
-int listcontrol(struct email_container *fromemails, const char *listdir,
+int listcontrol(strlist *fromemails, const char *listdir,
                const char *controlstr, const char *mlmmjsub,
                const char *mlmmjunsub, const char *mlmmjsend,
                const char *mailname, int listfd, int ctrlfd);
index b8a7d82feca79418f02abe39b067eda377406a2b..5371f73db763bb4b6638470150da0883892587af 100644 (file)
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002, 2003, 2004 Mads Martin Joergensen <mmj at mmj.dk>
- *
- * $Id$
+/*
+ * Copyright (C) 2002, 2003, 2004 Mads Martin Joergensen <mmj at mmj.dk>
+ * Copyright (C) 2022-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
@@ -27,6 +27,7 @@
 #include "config.h"
 #include <stdbool.h>
 #include <time.h>
+#include <tllist.h>
 
 #define RELAYHOST "127.0.0.1"
 #define READ_BUFSIZE 2048
@@ -58,6 +59,8 @@
 #define OPLOGFNAME "mlmmj.operation.log" /* logfile to log operations */
 #define OPLOGSIZE 524288
 
+typedef tll(char *) strlist;
+
 typedef enum bounce {
        BOUNCE_OK,
        BOUNCE_FAIL,
index 11d90bc76e934124e4761c1b517bcc6e58f45611..083009886bae9d16a9aee9f50b6aa18ddd656015 100644 (file)
@@ -44,6 +44,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 
+#include "mlmmj.h"
 #include "find_email_adr.h"
 #include "xmalloc.h"
 
@@ -181,8 +182,8 @@ static char *skin(char *name)
 }
 
 
-struct email_container *find_email_adr(const char *str,
-               struct email_container *retstruct)
+strlist *
+find_email_adr(const char *str, strlist *retstruct)
 {
        char *c1 = NULL, *c2 = NULL;
        char *p;
@@ -230,12 +231,8 @@ oncemore:
                }
 
                adr = skin(cur);
-               if (adr) {
-                       retstruct->emailcount++;
-                       retstruct->emaillist = (char **)xrealloc(retstruct->emaillist,
-                                         sizeof(char *) * retstruct->emailcount);
-                       retstruct->emaillist[retstruct->emailcount-1] = adr;
-               }
+               if (adr)
+                       tll_push_back(*retstruct, adr);
        }
 
        free(s);
index 0d5ffd7ac4b40af430c2c473853614d462b969b4..8b40341abbf1e8ae56a262808becb1ccbf53ee96 100644 (file)
@@ -112,7 +112,7 @@ static struct ctrl_command ctrl_commands[] = {
 };
 
 
-int listcontrol(struct email_container *fromemails, const char *listdir,
+int listcontrol(strlist *fromemails, const char *listdir,
                const char *controlstr, const char *mlmmjsub,
                const char *mlmmjunsub, const char *mlmmjsend,
                const char *mailname, int listfd, int ctrlfd)
@@ -145,8 +145,8 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
        
 #if 0
        log_error(LOG_ARGS, "controlstr = [%s]\n", controlstr);
-       log_error(LOG_ARGS, "fromemails->emaillist[0] = [%s]\n",
-                       fromemails->emaillist[0]);
+       log_error(LOG_ARGS, "tll_front(*fromemails) = [%s]\n",
+                       tll_front(*fromemails));
 #endif
        for (ctrl=0; ctrl<CTRL_END; ctrl++) {
                cmdlen = strlen(ctrl_commands[ctrl].command);
@@ -192,10 +192,10 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
        }
        
        /* Only allow mails with bad From: header to be bounce mails */
-       if(fromemails->emailcount != 1 && ctrl != CTRL_BOUNCES) {
+       if(tll_length(*fromemails) != 1 && ctrl != CTRL_BOUNCES) {
                errno = 0;
                log_error(LOG_ARGS, "Ignoring mail with invalid From: "
-                               "which was not a bounce: %d", fromemails->emailcount);
+                               "which was not a bounce: %d", tll_length(*fromemails));
                return -1;
        }
 
@@ -213,7 +213,7 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                                " sent to a closed list. Ignoring mail");
                        return -1;
                }
-               if (!strchr(fromemails->emaillist[0], '@')) {
+               if (!strchr(tll_front(*fromemails), '@')) {
                        /* Not a valid From: address */
                        errno = 0;
                        log_error(LOG_ARGS, "A subscribe-digest request was"
@@ -229,21 +229,21 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                                        "digest", "sub-deny-digest");
                        MY_ASSERT(txt);
                        register_unformatted(txt, "subaddr",
-                                       fromemails->emaillist[0]);
+                                       tll_front(*fromemails));
                        queuefilename = prepstdreply(txt, listdir,
                                        "$listowner$",
-                                       fromemails->emaillist[0], NULL, listfd, ctrlfd);
+                                       tll_front(*fromemails), NULL, listfd, ctrlfd);
                        MY_ASSERT(queuefilename);
                        close_text(txt);
                        send_help(listdir, queuefilename,
-                                       fromemails->emaillist[0], mlmmjsend, ctrlfd);
+                                       tll_front(*fromemails), mlmmjsend, ctrlfd);
                        return -1;
                }
                log_oper(listdir, OPLOGFNAME, "mlmmj-sub: request for digest"
                                        " subscription from %s",
-                                       fromemails->emaillist[0]);
+                                       tll_front(*fromemails));
                exec_or_die(mlmmjsub, "-L", listdir, "-a",
-                   fromemails->emaillist[0], "-d", "-r", "-c",
+                   tll_front(*fromemails), "-d", "-r", "-c",
                    (nosubconfirm ? NULL : "-C"), NULL);
                break;
 
@@ -255,7 +255,7 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                                " sent to a closed list. Ignoring mail");
                        return -1;
                }
-               if (!strchr(fromemails->emaillist[0], '@')) {
+               if (!strchr(tll_front(*fromemails), '@')) {
                        /* Not a valid From: address */
                        errno = 0;
                        log_error(LOG_ARGS, "A subscribe-nomail request was"
@@ -271,21 +271,21 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                                        "nomail", "sub-deny-nomail");
                        MY_ASSERT(txt);
                        register_unformatted(txt, "subaddr",
-                                       fromemails->emaillist[0]);
+                                       tll_front(*fromemails));
                        queuefilename = prepstdreply(txt, listdir,
                                        "$listowner$",
-                                       fromemails->emaillist[0], NULL, listfd, ctrlfd);
+                                       tll_front(*fromemails), NULL, listfd, ctrlfd);
                        MY_ASSERT(queuefilename);
                        close_text(txt);
                        send_help(listdir, queuefilename,
-                                       fromemails->emaillist[0], mlmmjsend, ctrlfd);
+                                       tll_front(*fromemails), mlmmjsend, ctrlfd);
                        return -1;
                }
                log_oper(listdir, OPLOGFNAME, "mlmmj-sub: request for nomail"
                                        " subscription from %s",
-                                       fromemails->emaillist[0]);
+                                       tll_front(*fromemails));
                exec_or_die(mlmmjsub, "-L", listdir, "-a",
-                   fromemails->emaillist[0], "-n", "-r", "-c",
+                   tll_front(*fromemails), "-n", "-r", "-c",
                    (nosubconfirm ? NULL : "-C"), NULL);
                break;
 
@@ -297,7 +297,7 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                                " sent to a closed list. Ignoring mail");
                        return -1;
                }
-               if (!strchr(fromemails->emaillist[0], '@')) {
+               if (!strchr(tll_front(*fromemails), '@')) {
                        /* Not a valid From: address */
                        errno = 0;
                        log_error(LOG_ARGS, "A subscribe-both request was"
@@ -313,21 +313,21 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                                        "both", "sub-deny-digest");
                        MY_ASSERT(txt);
                        register_unformatted(txt, "subaddr",
-                                       fromemails->emaillist[0]);
+                                       tll_front(*fromemails));
                        queuefilename = prepstdreply(txt, listdir,
                                        "$listowner$",
-                                       fromemails->emaillist[0], NULL, listfd, ctrlfd);
+                                       tll_front(*fromemails), NULL, listfd, ctrlfd);
                        MY_ASSERT(queuefilename);
                        close_text(txt);
                        send_help(listdir, queuefilename,
-                                       fromemails->emaillist[0], mlmmjsend, ctrlfd);
+                                       tll_front(*fromemails), mlmmjsend, ctrlfd);
                        return -1;
                }
                log_oper(listdir, OPLOGFNAME, "mlmmj-sub: request for both"
                                        " subscription from %s",
-                                       fromemails->emaillist[0]);
+                                       tll_front(*fromemails));
                exec_or_die(mlmmjsub, "-L", listdir, "-a",
-                   fromemails->emaillist[0], "-b", "-r", "-c",
+                   tll_front(*fromemails), "-b", "-r", "-c",
                    (nosubconfirm ? NULL : "-C"), NULL);
                break;
 
@@ -339,7 +339,7 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                                " sent to a closed list. Ignoring mail");
                        return -1;
                }
-               if (!strchr(fromemails->emaillist[0], '@')) {
+               if (!strchr(tll_front(*fromemails), '@')) {
                        /* Not a valid From: address */
                        errno = 0;
                        log_error(LOG_ARGS, "A subscribe request was"
@@ -349,9 +349,9 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                }
                log_oper(listdir, OPLOGFNAME, "mlmmj-sub: request for regular"
                                        " subscription from %s",
-                                       fromemails->emaillist[0]);
+                                       tll_front(*fromemails));
                exec_or_die(mlmmjsub, "-L", listdir, "-a",
-                   fromemails->emaillist[0], "-r", "-c",
+                   tll_front(*fromemails), "-r", "-c",
                    (nosubconfirm ? NULL : "-C"), NULL);
                break;
 
@@ -427,7 +427,7 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                                " sent to a closed list. Ignoring mail");
                        return -1;
                }
-               if (!strchr(fromemails->emaillist[0], '@')) {
+               if (!strchr(tll_front(*fromemails), '@')) {
                        /* Not a valid From: address */
                        errno = 0;
                        log_error(LOG_ARGS, "An unsubscribe request was"
@@ -437,9 +437,9 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                }
                log_oper(listdir, OPLOGFNAME, "mlmmj-unsub: %s requests"
                                        " unsubscribe",
-                                       fromemails->emaillist[0]);
+                                       tll_front(*fromemails));
                exec_or_die(mlmmjunsub, "-L", listdir, "-a",
-                   fromemails->emaillist[0], "-r",
+                   tll_front(*fromemails), "-r",
                    (nosubconfirm ? "-c" : "-C"), NULL);
                break;
 
@@ -603,7 +603,7 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                free(moderatefilename);
 
                log_oper(listdir, OPLOGFNAME, "%s released %s",
-                               fromemails->emaillist[0], param);
+                               tll_front(*fromemails), param);
 
                if (omit != NULL)
                        exec_or_die(mlmmjsend, "-L", listdir, "-o", omit,
@@ -624,7 +624,7 @@ int listcontrol(struct email_container *fromemails, const char *listdir,
                        return -1;
                }
                log_oper(listdir, OPLOGFNAME, "%s rejected %s",
-                       fromemails->emaillist[0], param);
+                       tll_front(*fromemails), param);
                free(param);
                if (unlink(moderatefilename) != 0) {
                        log_error(LOG_ARGS, "Could not unlink %s",
@@ -650,7 +650,7 @@ permit:
                        return -1;
                }
                log_oper(listdir, OPLOGFNAME, "%s permitted %s",
-                       fromemails->emaillist[0], param);
+                       tll_front(*fromemails), param);
                exec_or_die(mlmmjsub, "-L", listdir, "-m", param, "-c", NULL);
                break;
 
@@ -668,7 +668,7 @@ permit:
                        return -1;
                }
                log_oper(listdir, OPLOGFNAME, "%s obstructed %s",
-                       fromemails->emaillist[0], param);
+                       tll_front(*fromemails), param);
                free(param);
                if (unlink(gatekeepfilename) != 0) {
                        log_error(LOG_ARGS, "Could not unlink %s",
@@ -681,7 +681,7 @@ permit:
 
        /* listname+help@domain.tld */
        case CTRL_HELP:
-               if(!strchr(fromemails->emaillist[0], '@')) {
+               if(!strchr(tll_front(*fromemails), '@')) {
                        /* Not a valid From: address */
                        errno = 0;
                        log_error(LOG_ARGS, "A help request was"
@@ -690,20 +690,20 @@ permit:
                        return -1;
                }
                log_oper(listdir, OPLOGFNAME, "%s requested help",
-                               fromemails->emaillist[0]);
+                               tll_front(*fromemails));
                txt = open_text(listdir, "help", NULL, NULL, NULL, "listhelp");
                MY_ASSERT(txt);
                queuefilename = prepstdreply(txt, listdir,
-                               "$listowner$", fromemails->emaillist[0], NULL, listfd, ctrlfd);
+                               "$listowner$", tll_front(*fromemails), NULL, listfd, ctrlfd);
                MY_ASSERT(queuefilename);
                close_text(txt);
                send_help(listdir, queuefilename,
-                               fromemails->emaillist[0], mlmmjsend, ctrlfd);
+                               tll_front(*fromemails), mlmmjsend, ctrlfd);
                break;
 
        /* listname+faq@domain.tld */
         case CTRL_FAQ:
-               if(!strchr(fromemails->emaillist[0], '@')) {
+               if(!strchr(tll_front(*fromemails), '@')) {
                        /* Not a valid From: address */
                        errno = 0;
                        log_error(LOG_ARGS, "A faq request was"
@@ -712,15 +712,15 @@ permit:
                        return -1;
                }
                log_oper(listdir, OPLOGFNAME, "%s requested faq",
-                               fromemails->emaillist[0]);
+                               tll_front(*fromemails));
                txt = open_text(listdir, "faq", NULL, NULL, NULL, "listfaq");
                MY_ASSERT(txt);
                queuefilename = prepstdreply(txt, listdir,
-                               "$listowner$", fromemails->emaillist[0], NULL, listfd, ctrlfd);
+                               "$listowner$", tll_front(*fromemails), NULL, listfd, ctrlfd);
                MY_ASSERT(queuefilename);
                close_text(txt);
                send_help(listdir, queuefilename,
-                               fromemails->emaillist[0], mlmmjsend, ctrlfd);
+                               tll_front(*fromemails), mlmmjsend, ctrlfd);
                break;
 
        /* listname+get-INDEX@domain.tld */
@@ -734,7 +734,7 @@ permit:
                }
                subonlyget = statctrl(ctrlfd, "subonlyget");
                if(subonlyget) {
-                       if(is_subbed(listfd, fromemails->emaillist[0], 0) ==
+                       if(is_subbed(listfd, tll_front(*fromemails), 0) ==
                                        SUB_NONE) {
                                errno = 0;
                                log_error(LOG_ARGS, "A get request was sent"
@@ -760,8 +760,8 @@ permit:
                        exit(EXIT_FAILURE);
                }
                log_oper(listdir, OPLOGFNAME, "%s got archive/%s",
-                               fromemails->emaillist[0], archivefilename);
-               exec_or_die(mlmmjsend, "-T", fromemails->emaillist[0], "-L",
+                               tll_front(*fromemails), archivefilename);
+               exec_or_die(mlmmjsend, "-T", tll_front(*fromemails), "-L",
                    listdir, "-l", "6", "-m", archivefilename, "-a", "-D",
                    NULL);
                break;
@@ -774,11 +774,11 @@ permit:
                owners = ctrlvalues(listdir, "owner");
                if (owners != NULL) {
                        for(i = 0; i < owners->count; i++) {
-                               if(strcasecmp(fromemails->emaillist[0],
+                               if(strcasecmp(tll_front(*fromemails),
                                                        owners->strs[i]) == 0) {
                                        log_oper(listdir, OPLOGFNAME,
                                                        "%s requested sub list",
-                                       fromemails->emaillist[0]);
+                                       tll_front(*fromemails));
                                        owner_idx = i;
                                        break;
                                }
index da61320ef10e058525837dd07478f16b145ec98d..8bd871feb0b62e13156e5ff9ccc5608ffdf25a63 100644 (file)
@@ -438,13 +438,13 @@ int main(int argc, char **argv)
        char *envstr, *efrom;
        struct stat st;
        uid_t uid;
-       struct email_container fromemails = { 0, NULL };
-       struct email_container originalfromemails = { 0, NULL };
-       struct email_container toemails = { 0, NULL };
-       struct email_container ccemails = { 0, NULL };
-       struct email_container rpemails = { 0, NULL };
-       struct email_container dtemails = { 0, NULL };
-       struct email_container *testfrom = NULL;
+       strlist fromemails = tll_init();
+       strlist originalfromemails = tll_init();
+       strlist toemails = tll_init();
+       strlist ccemails = tll_init();
+       strlist rpemails = tll_init();
+       strlist dtemails = tll_init();
+       strlist *testfrom = NULL;
        struct strlist *access_rules = NULL;
        struct strlist *list_rules = NULL;
        struct strlist *delheaders = NULL;
@@ -633,9 +633,9 @@ int main(int argc, char **argv)
        }
        if(addrtocc || findaddress) {
                listaddrs = ctrlvalues(listdir, "listaddress");
-               for(i = 0; i < dtemails.emailcount; i++) {
+               tll_foreach(dtemails, it) {
                        for(j = 0; j < listaddrs->count; j++) {
-                               if(addrmatch(listaddrs->strs[j], dtemails.emaillist[i],
+                               if(addrmatch(listaddrs->strs[j], it->item,
                                                listdelim, &recipextra)) {
                                        findaddress = 0;
                                        free(listdelim);
@@ -646,24 +646,25 @@ int main(int argc, char **argv)
                }
        }
        if(addrtocc || findaddress) {
-               for(i = 0; i < toemails.emailcount; i++) {
+               tll_foreach(toemails, it) {
                        for(j = 0; j < listaddrs->count; j++) {
-                               if(addrmatch(listaddrs->strs[j], toemails.emaillist[i],
+                               if(addrmatch(listaddrs->strs[j], it->item,
                                                listdelim, &recipextra)) {
                                        intocc = 1;
                                        break;
                                }
                        }
                }
-               if (!intocc) for(i = 0; i < ccemails.emailcount; i++) {
-                       for(j = 0; j < listaddrs->count; j++) {
-                               if(addrmatch(listaddrs->strs[j], ccemails.emaillist[i],
+               if (!intocc)
+                       tll_foreach(ccemails, it) {
+                               for(j = 0; j < listaddrs->count; j++) {
+                                       if(addrmatch(listaddrs->strs[j], it->item,
                                                listdelim, &recipextra)) {
-                                       intocc = 1;
-                                       break;
+                                               intocc = 1;
+                                               break;
+                                       }
                                }
                        }
-               }
        }
        if (listdelim) {
                free(listdelim);
@@ -687,19 +688,19 @@ int main(int argc, char **argv)
        }
 
        /* discard malformed mail with invalid From: unless it's a bounce */
-       if(fromemails.emailcount != 1 &&
+       if(tll_length(fromemails) != 1 &&
                        (recipextra == NULL ||
                        strncmp(recipextra, "bounces", 7) != 0)) {
-               for(i = 0; i < fromemails.emailcount; i++)
-                       printf("fromemails.emaillist[%d] = %s\n",
-                                       i, fromemails.emaillist[i]);
+               tll_foreach(fromemails, it)
+                       printf("fromemails.emaillist[] = %s\n",
+                                       it->item);
                discardname = concatstr(3, listdir,
                                "/queue/discarded/", randomstr);
                log_error(LOG_ARGS, "Discarding %s due to invalid From:",
                                mailfile);
-               for(i = 0; i < fromemails.emailcount; i++)
-                       log_error(LOG_ARGS, "fromemails.emaillist[%d] = %s\n",
-                                       i, fromemails.emaillist[i]);
+               tll_foreach(fromemails, it)
+                       log_error(LOG_ARGS, "fromemails.emaillist[] = %s\n",
+                                       it->item);
                rename(mailfile, discardname);
                unlink(donemailname);
                free(donemailname);
@@ -711,8 +712,8 @@ int main(int argc, char **argv)
        /* The only time posteraddr will remain unset is when the mail is a
         * bounce, so the mail will be processed by listcontrol() and the
         * program will terminate before posteraddr is used. */
-       if (fromemails.emailcount > 0)
-                       posteraddr = fromemails.emaillist[0];
+       if (tll_length(fromemails) > 0)
+                       posteraddr = tll_front(fromemails);
 
        /* Return-Path: addresses */
        for(i = 0; i < readhdrs[3].valuecount; i++) {
@@ -723,9 +724,9 @@ int main(int argc, char **argv)
        if((envstr = getenv("SENDER")) != NULL) {
                /* qmail, postfix, exim */
                efrom = xstrdup(envstr);
-       } else if(rpemails.emailcount >= 1) {
+       } else if(tll_length(rpemails) >= 1) {
                /* the (first) Return-Path: header */
-               efrom = xstrdup(rpemails.emaillist[0]);
+               efrom = xstrdup(tll_front(rpemails));
        } else {
                efrom = xstrdup("");
        }
@@ -782,7 +783,7 @@ int main(int argc, char **argv)
                log_error(LOG_ARGS, "listcontrol(from, %s, %s, %s, %s, %s, %s, %s)\n", listdir, toemails.emaillist[0], mlmmjsub, mlmmjunsub, mlmmjsend, mlmmjbounce, donemailname);
 #endif
                unlink(mailfile);
-               if (originalfromemails.emailcount > 0)
+               if (tll_length(originalfromemails) > 0)
                        testfrom = &originalfromemails;
                else
                        testfrom = &fromemails;
@@ -999,8 +1000,8 @@ int main(int argc, char **argv)
                /* Don't send a mail about denial to the list, but silently
                 * discard and exit. */
                char *testaddr = posteraddr;
-               if (originalfromemails.emailcount > 0)
-                       testaddr = originalfromemails.emaillist[0];
+               if (tll_length(originalfromemails) > 0)
+                       testaddr = tll_front(originalfromemails);
                if (strcasecmp(listaddr, testaddr) == 0) {
                        log_error(LOG_ARGS, "Discarding %s because"
                                        " there are sender restrictions but"
index 38cb87646615e9809dd676fcb3d598dda2ea0259..63c4cb8d9712b50fbe5f161e9f96236647cf9983 100644 (file)
@@ -389,11 +389,11 @@ save_lastbouncedmsg(int listfd, const char *address, const char *mailname)
 
 char *dsnparseaddr(const char *mailname)
 {
-       int fd, i;
+       int fd;
        char *line, *hdr, *walk, *addr = NULL, *boundary = NULL;
        bool quoted = false;
        bool indsn = false;
-       struct email_container emails = { 0, NULL };
+       strlist emails = tll_init();
 
        fd = open(mailname, O_RDONLY);
        if(fd < 0) {
@@ -452,11 +452,9 @@ char *dsnparseaddr(const char *mailname)
                                        break;
                                }
                                find_email_adr(walk+1, &emails);
-                               if(emails.emailcount > 0) {
-                                       addr = xstrdup(emails.emaillist[0]);
-                                       for(i = 0; i < emails.emailcount; i++)
-                                               free(emails.emaillist[i]);
-                                       free(emails.emaillist);
+                               if(tll_length(emails) > 0) {
+                                       addr = xstrdup(tll_front(emails));
+                                       tll_free_and_free(emails, free);
                                }
                                free(line);
                                break;
index 5823ef7e64b530ae51e8649fa95a870980d102af..10f9c71c4984eaeb234c6206b2f7ff298551450a 100644 (file)
@@ -355,92 +355,92 @@ ATF_TC_BODY(exec_and_wait, tc)
 
 ATF_TC_BODY(find_email_adr, tc)
 {
-       struct email_container c = {0, NULL};
-       struct email_container c1 = {0, NULL};
-       struct email_container c2 = {0, NULL};
-       struct email_container c3 = {0, NULL};
-       struct email_container c4 = {0, NULL};
-       struct email_container c5 = {0, NULL};
-       struct email_container c6 = {0, NULL};
-       struct email_container c7 = {0, NULL};
+       strlist c  = tll_init();
+       strlist c1 = tll_init();
+       strlist c2 = tll_init();
+       strlist c3 = tll_init();
+       strlist c4 = tll_init();
+       strlist c5 = tll_init();
+       strlist c6 = tll_init();
+       strlist c7 = tll_init();
        find_email_adr("test@foo.bar", &c);
-       ATF_REQUIRE_EQ(c.emailcount, 1);
+       ATF_REQUIRE_EQ(tll_length(c), 1);
        find_email_adr("test@foo.bar, meh@bar", &c1);
-       ATF_REQUIRE_EQ(c1.emailcount, 2);
+       ATF_REQUIRE_EQ(tll_length(c1), 2);
        find_email_adr("test@foo.bar, meh@bar, nope", &c2);
-       ATF_REQUIRE_EQ(c2.emailcount, 3);
+       ATF_REQUIRE_EQ(tll_length(c2), 3);
        find_email_adr("name <test@foo.com>", &c3);
-       ATF_REQUIRE_EQ(c3.emailcount, 1);
-       ATF_REQUIRE_STREQ(c3.emaillist[0], "test@foo.com");
+       ATF_REQUIRE_EQ(tll_length(c3), 1);
+       ATF_REQUIRE_STREQ(tll_front(c3), "test@foo.com");
        find_email_adr("(name <test@foo.com>) test@foo.com", &c4);
-       ATF_REQUIRE_EQ(c4.emailcount, 1);
-       ATF_REQUIRE_STREQ(c4.emaillist[0], " test@foo.com");
+       ATF_REQUIRE_EQ(tll_length(c4), 1);
+       ATF_REQUIRE_STREQ(tll_front(c4), " test@foo.com");
        find_email_adr("\"name <test@foo.com>\" test@foo.com", &c5);
-       ATF_REQUIRE_EQ(c5.emailcount, 1);
-       ATF_REQUIRE_STREQ(c5.emaillist[0], "name <test@foo.com> test@foo.com");
+       ATF_REQUIRE_EQ(tll_length(c5), 1);
+       ATF_REQUIRE_STREQ(tll_front(c5), "name <test@foo.com> test@foo.com");
        find_email_adr("\"name <test@foo.com> test@foo.com", &c6);
-       ATF_REQUIRE_EQ(c6.emailcount, 1);
-       ATF_REQUIRE_STREQ(c6.emaillist[0], "name <test@foo.com> test@foo.com");
+       ATF_REQUIRE_EQ(tll_length(c6), 1);
+       ATF_REQUIRE_STREQ(tll_front(c6), "name <test@foo.com> test@foo.com");
        find_email_adr("\"name <test@foo.com>\\ test@foo.com", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 1);
-       ATF_REQUIRE_STREQ(c7.emaillist[0], "name <test@foo.com> test@foo.com");
+       ATF_REQUIRE_EQ(tll_length(c7), 1);
+       ATF_REQUIRE_STREQ(tll_front(c7), "name <test@foo.com> test@foo.com");
        find_email_adr("\"name <test@foo.com> test@foo.com\\", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 2);
-       ATF_REQUIRE_STREQ(c7.emaillist[1], "name <test@foo.com> test@foo.com");
+       ATF_REQUIRE_EQ(tll_length(c7), 2);
+       ATF_REQUIRE_STREQ(tll_back(c7), "name <test@foo.com> test@foo.com");
        find_email_adr("test at foo.com", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 3);
-       ATF_REQUIRE_STREQ(c7.emaillist[2], "test@foo.com");
+       ATF_REQUIRE_EQ(tll_length(c7), 3);
+       ATF_REQUIRE_STREQ(tll_back(c7), "test@foo.com");
        find_email_adr("test atfoo.com", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 4);
-       ATF_REQUIRE_STREQ(c7.emaillist[3], "test atfoo.com");
+       ATF_REQUIRE_EQ(tll_length(c7), 4);
+       ATF_REQUIRE_STREQ(tll_back(c7), "test atfoo.com");
        find_email_adr("test a t foo.com", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 5);
-       ATF_REQUIRE_STREQ(c7.emaillist[4], "test a t foo.com");
+       ATF_REQUIRE_EQ(tll_length(c7), 5);
+       ATF_REQUIRE_STREQ(tll_back(c7), "test a t foo.com");
        find_email_adr("test@foo.com, \"meh\"", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 7);
-       ATF_REQUIRE_STREQ(c7.emaillist[6], "\"meh\"");
+       ATF_REQUIRE_EQ(tll_length(c7), 7);
+       ATF_REQUIRE_STREQ(tll_back(c7), "\"meh\"");
        find_email_adr("test@foo.com, \"meh\\\"", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 9);
-       ATF_REQUIRE_STREQ(c7.emaillist[8], "meh ");
+       ATF_REQUIRE_EQ(tll_length(c7), 9);
+       ATF_REQUIRE_STREQ(tll_back(c7), "meh ");
        find_email_adr("", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 9);
+       ATF_REQUIRE_EQ(tll_length(c7), 9);
        find_email_adr("\"meh\" , ", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 10);
-       ATF_REQUIRE_STREQ(c7.emaillist[9], "meh");
+       ATF_REQUIRE_EQ(tll_length(c7), 10);
+       ATF_REQUIRE_STREQ(tll_back(c7), "meh");
        find_email_adr("\"meh , ", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 11);
-       ATF_REQUIRE_STREQ(c7.emaillist[10], "meh   ");
+       ATF_REQUIRE_EQ(tll_length(c7), 11);
+       ATF_REQUIRE_STREQ(tll_back(c7), "meh   ");
        find_email_adr("\t,", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 11);
+       ATF_REQUIRE_EQ(tll_length(c7), 11);
        find_email_adr("\r,", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 11);
+       ATF_REQUIRE_EQ(tll_length(c7), 11);
        find_email_adr("\n,", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 11);
+       ATF_REQUIRE_EQ(tll_length(c7), 11);
        find_email_adr(", m", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 12);
+       ATF_REQUIRE_EQ(tll_length(c7), 12);
        find_email_adr(", \"m", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 13);
+       ATF_REQUIRE_EQ(tll_length(c7), 13);
        find_email_adr("bob @ foo.net", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 14);
-       ATF_REQUIRE_STREQ(c7.emaillist[13], "bob@foo.net");
+       ATF_REQUIRE_EQ(tll_length(c7), 14);
+       ATF_REQUIRE_STREQ(tll_back(c7), "bob@foo.net");
        find_email_adr("bob @foo.net", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 15);
-       ATF_REQUIRE_STREQ(c7.emaillist[14], "bob @foo.net");
+       ATF_REQUIRE_EQ(tll_length(c7), 15);
+       ATF_REQUIRE_STREQ(tll_back(c7), "bob @foo.net");
        find_email_adr("bob @foo.net>", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 16);
-       ATF_REQUIRE_STREQ(c7.emaillist[15], "bob @foo.net>");
+       ATF_REQUIRE_EQ(tll_length(c7), 16);
+       ATF_REQUIRE_STREQ(tll_back(c7), "bob @foo.net>");
        find_email_adr("<bob @foo.net> garbage,", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 17);
-       ATF_REQUIRE_STREQ(c7.emaillist[16], "bob @foo.net");
+       ATF_REQUIRE_EQ(tll_length(c7), 17);
+       ATF_REQUIRE_STREQ(tll_back(c7), "bob @foo.net");
        find_email_adr("<bob @foo.net> garbage (more garbage) ,", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 18);
-       ATF_REQUIRE_STREQ(c7.emaillist[17], "bob @foo.net");
+       ATF_REQUIRE_EQ(tll_length(c7), 18);
+       ATF_REQUIRE_STREQ(tll_back(c7), "bob @foo.net");
        find_email_adr("<bob @foo.net> garbage \"more garbage\" ,", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 19);
-       ATF_REQUIRE_STREQ(c7.emaillist[18], "bob @foo.net");
+       ATF_REQUIRE_EQ(tll_length(c7), 19);
+       ATF_REQUIRE_STREQ(tll_back(c7), "bob @foo.net");
        find_email_adr("<bob @foo.net> garbage \"more garbage \\ ,", &c7);
-       ATF_REQUIRE_EQ(c7.emailcount, 20);
-       ATF_REQUIRE_STREQ(c7.emaillist[19], "bob @foo.net");
+       ATF_REQUIRE_EQ(tll_length(c7), 20);
+       ATF_REQUIRE_STREQ(tll_back(c7), "bob @foo.net");
 }
 
 ATF_TC_BODY(strtoim, tc)