]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
listcontrol: simplify code handling omits in +release
authorBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 14 Apr 2023 10:02:26 +0000 (12:02 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 14 Apr 2023 10:02:26 +0000 (12:02 +0200)
Reuse the code used to read a line from a file in control
and only unlink the file if it actually existed

src/listcontrol.c

index 7049b2484e64afe1be200ad0b75c46411d80181d..cedceac316d22be4129c205135e2c4f81fcfc0b7 100644 (file)
 #include "send_mail.h"
 #include "log_error.h"
 #include "statctrl.h"
-#include "mygetline.h"
 #include "chomp.h"
 #include "log_oper.h"
 #include "ctrlvalues.h"
+#include "ctrlvalue.h"
 #include "subscriberfuncs.h"
 #include "utils.h"
 
@@ -153,7 +153,6 @@ int listcontrol(strlist *fromemails, struct ml *ml,
        char *omit = NULL;
        char *c, *archivefilename, *sendfilename, *tosend;
        bool nosubconfirm;
-       int tmpfd;
        text *txt;
        char *queuefilename;
        enum subtype ts = SUB_NONE;
@@ -456,20 +455,11 @@ int listcontrol(strlist *fromemails, struct ml *ml,
                }
 
                xasprintf(&omitfilename, "%s.omit", moderatefilename);
-               if(faccessat(ml->fd, omitfilename, F_OK, 0) == 0) {
-                       tmpfd = openat(ml->fd, omitfilename, O_RDONLY);
-                       if(tmpfd < 0) {
-                               log_error(LOG_ARGS, "Could not open %s",
-                                               omitfilename);
-                       } else {
-                               omit = mygetline(tmpfd);
-                               close(tmpfd);
-                               chomp(omit);
-                       }
+               errno = 0;
+               omit = ctrlvalue(ml->fd, omitfilename);
+               if (omit != NULL || errno != ENOENT)
                        unlinkat(ml->fd, omitfilename, 0);
-                       free(omitfilename);
-               }
-
+               free(omitfilename);
                free(moderatefilename);
 
                log_oper(ml->fd, OPLOGFNAME, "%s released %s",