]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-process: deduplicate some code
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 5 Jul 2023 07:15:09 +0000 (09:15 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 5 Jul 2023 07:15:09 +0000 (09:15 +0200)
include/utils.h
src/mlmmj-process.c
src/utils.c

index f2d6894265f0acf521d9a9724c1a6259e1c4cc5d..9430efa7fbc165f222bf002436bd618cc9182653 100644 (file)
@@ -29,6 +29,8 @@
 #include <time.h>
 #include <fcntl.h>
 
+#include "mlmmj.h"
+
 char *lowercase(const char *);
 intmax_t strtoim(const char *np, intmax_t minval, intmax_t maxval,
     const char **errpp);
@@ -37,3 +39,4 @@ void exec_or_die(const char *arg, ...);
 int exec_and_wait(const char *arg, ...);
 time_t strtotimet(const char *np, const char **errpp);
 bool lock(int fd, bool write);
+bool find_email(strlist *list, strlist *matches, const char *delim, char **recipextra);
index 633dc8c7fa11cb08a83988bec2da59a6556e378f..0fd6e3a0a3e631e9f20323a7fd496488d0892fc3 100644 (file)
@@ -538,39 +538,15 @@ int main(int argc, char **argv)
                        log_error(LOG_ARGS, "list address is not defined");
                        err(EXIT_FAILURE, "list address is not defined");
                }
-               tll_foreach(dtemails, it) {
-                       tll_foreach(*listaddrs, la) {
-                               if (addrmatch(la->item, it->item,
-                                   ml.delim,
-                                   recipextra != NULL ? NULL : &recipextra)) {
-                                       findaddress = 0;
-                                       break;
-                               }
-                       }
-               }
+               findaddress = !find_email(&dtemails, listaddrs, ml.delim,
+                   recipextra != NULL ? NULL : &recipextra);
        }
        if(addr_in_to_or_cc || findaddress) {
-               tll_foreach(toemails, it) {
-                       tll_foreach(*listaddrs, la) {
-                               if(addrmatch(la->item, it->item,
-                               ml.delim,
-                               recipextra != NULL ? NULL : &recipextra)) {
-                                       intocc = true;
-                                       break;
-                               }
-                       }
-               }
+               intocc = find_email(&toemails, listaddrs, ml.delim,
+                   recipextra != NULL ? NULL : &recipextra);
                if (!intocc)
-                       tll_foreach(ccemails, it) {
-                               tll_foreach(*listaddrs, la) {
-                                       if(addrmatch(la->item, it->item,
-                                               ml.delim,
-                                          recipextra != NULL ? NULL : &recipextra)) {
-                                               intocc = true;
-                                               break;
-                                       }
-                               }
-                       }
+                       intocc = find_email(&ccemails, listaddrs, ml.delim,
+                           recipextra != NULL ? NULL : &recipextra);
        }
        if (listaddrs)
                tll_free_and_free(*listaddrs, free);
index abf96c99a9b61993fd4bb2d96a634de6aa2e80ca..a602369904e9d28d75004135715e7fd80e5f4253 100644 (file)
@@ -295,3 +295,16 @@ addrmatch(const char *listaddr, const char *addr,
 
        return (true);
 }
+
+bool
+find_email(strlist *list, strlist *matches, const char *delim, char **recipextra)
+{
+       tll_foreach(*list, lit) {
+               tll_foreach(*matches, mit) {
+                       if (addrmatch(mit->item, lit->item, delim, recipextra))
+                               return true;
+               }
+       }
+       return false;
+}
+