#include "ctrlvalue.h"
#include "ctrlvalues.h"
#include "utils.h"
-#include "do_all_the_voodoo_here.h"
#include "log_error.h"
#include "wrappers.h"
parse_content_type(allhdrs,&mime_type,boundary);
if(mime_type) {
/* check if this part should be stripped */
- if(delmime && findit(mime_type, delmime))
+ if(delmime && line_startwithany(mime_type, delmime, true))
result = MIME_STRIP;
/* check if the mail should be denied */
- if(denymime && findit(mime_type, denymime))
+ if(denymime && line_startwithany(mime_type, denymime, true))
*deny = 1;
free(mime_type);
}
/*
- * Copyright (C) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
+ * Copyright (C) 2025 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
bool lock(int fd, bool write);
bool find_email(strlist *list, strlist *matches, const char *delim, char **recipextra);
char *readlf(int fd, bool oneline);
+bool line_startwithany(const char *el, const strlist *list, bool ignore_case);
#include "log_error.h"
#include "wrappers.h"
#include "find_email_adr.h"
+#include "utils.h"
-bool
-findit(const char *line, const strlist *headers)
-{
- size_t len;
-
- tll_foreach(*headers, it) {
- len = strlen(it->item);
- if(strncasecmp(line, it->item, len) == 0)
- return true;
- }
-
- return false;
-}
/* read line and populate a struct to save a list important header see mlmmj-process.c:254 and mlmmj.h:97 */
void getinfo(const char *line, struct mailhdr *readhdrs)
}
/* Should it be stripped? */
- if(!delhdrs || !findit(hdrline, delhdrs))
+ if(!delhdrs || !line_startwithany(hdrline, delhdrs, true))
dprintf(outfd, "%s", unfolded);
/* Should Reply-To be added? */
/*
- * Copyright (C) 2021-2022 Baptiste Daroussin <bapt@FreeBSD.org>
+ * Copyright (C) 2021-2025 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
}
return (buf);
}
+
+typedef int (*cmp_fn_t)(const char *, const char *, size_t);
+
+bool
+line_startwithany(const char *el, const strlist *list, bool ignore_case)
+{
+ size_t len;
+ cmp_fn_t cmp = ignore_case ? strncasecmp : strncmp;
+
+ tll_foreach(*list, it) {
+ len = strlen(it->item);
+ if (cmp(el, it->item, len) == 0)
+ return (true);
+ }
+
+ return (false);
+}
ATF_TC_WITHOUT_HEAD(find_in_list);
ATF_TC_WITHOUT_HEAD(do_access);
ATF_TC_WITHOUT_HEAD(unistr_header_to_utf8);
+ATF_TC_WITHOUT_HEAD(line_startwithany);
ATF_TC_BODY(random_int, tc)
{
ATF_REQUIRE_STREQ(out, "useless but why not");
}
+ATF_TC_BODY(line_startwithany, tc)
+{
+ strlist l = tll_init();
+ tll_push_back(l, "bla");
+ ATF_REQUIRE(!line_startwithany("BLA", &l, false));
+ ATF_REQUIRE(line_startwithany("BLA", &l, true));
+ ATF_REQUIRE(!line_startwithany("BLOP", &l, false));
+ ATF_REQUIRE(!line_startwithany("BLOP", &l, true));
+ tll_push_back(l, "BLOP");
+ ATF_REQUIRE(line_startwithany("BLOP", &l, false));
+ ATF_REQUIRE(line_startwithany("BLOP", &l, true));
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, random_int);
ATF_TP_ADD_TC(tp, find_in_list);
ATF_TP_ADD_TC(tp, do_access);
ATF_TP_ADD_TC(tp, unistr_header_to_utf8);
+ ATF_TP_ADD_TC(tp, line_startwithany);
return (atf_no_error());
}