From: Baptiste Daroussin Date: Fri, 13 Jun 2025 13:32:57 +0000 (+0200) Subject: refactoring: isolate the code scanning the header X-Git-Tag: RELEASE_1.6.0~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d12a4376a97d125df1a241c5de7f21772e191a9e;p=thirdparty%2Fmlmmj.git refactoring: isolate the code scanning the header Isolate the code scanning the header of a mail into its own function for it to be reusable --- diff --git a/include/do_all_the_voodoo_here.h b/include/do_all_the_voodoo_here.h index 0111eb44..523c54d2 100644 --- a/include/do_all_the_voodoo_here.h +++ b/include/do_all_the_voodoo_here.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Mads Martin Joergensen - * Copyright (C) 2023 Baptiste Daroussin + * Copyright (C) 2023-2025 Baptiste Daroussin * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -30,3 +30,5 @@ void getinfo(const char *line, struct mailhdr *readhdrs); int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd, const strlist *delhdrs, struct mailhdr *readhdrs, strlist *allhdrs, const char *subjectprefix, int replyto); +void scan_headers(FILE *f, struct mailhdr *readhdrs, strlist *allhdrs, + strlist *allunfoldeds); diff --git a/src/do_all_the_voodoo_here.c b/src/do_all_the_voodoo_here.c index d6f6e12b..184ac5c9 100644 --- a/src/do_all_the_voodoo_here.c +++ b/src/do_all_the_voodoo_here.c @@ -1,6 +1,5 @@ /* Copyright (C) 2004 Mads Martin Joergensen - * - * $Id$ + * Copyright (C) 2025 Baptiste Daroussin * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -70,20 +69,13 @@ void getinfo(const char *line, struct mailhdr *readhdrs) } } -int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd, - const strlist *delhdrs, struct mailhdr *readhdrs, - strlist *allhdrs, const char *prefix, int replyto) +void +scan_headers(FILE *f, struct mailhdr *readhdrs, strlist *allhdrs, strlist *allunfoldeds) { - char *hdrline, *unfolded, *unqp; - strlist allunfoldeds = tll_init(); - char *posteraddr = NULL; - bool hdrsadded = false; - bool subject_present = false; - FILE *f = fdopen(dup(infd), "r"); + char *hdrline, *unfolded; /* scan all headers and populate readhdrs , allhdrs , allunfoldeds */ - - for(;;) { + for (;;) { /* hdrline contains the header in one line and unfolded contains the original data */ hdrline = gethdrline(f, &unfolded); @@ -96,15 +88,34 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd, if(readhdrs) getinfo(hdrline, readhdrs); - /* Snatch a copy of the header */ - tll_push_back(*allhdrs, xstrdup(hdrline)); + if (allhdrs != NULL) { + /* Snatch a copy of the header */ + tll_push_back(*allhdrs, xstrdup(hdrline)); + } - /* Snatch a copy of unfolded */ - tll_push_back(allunfoldeds, xstrdup(unfolded)); + if (allunfoldeds != NULL) { + /* Snatch a copy of unfolded */ + tll_push_back(*allunfoldeds, xstrdup(unfolded)); + } free(hdrline); free(unfolded); } +} + +int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd, + const strlist *delhdrs, struct mailhdr *readhdrs, + strlist *allhdrs, const char *prefix, int replyto) +{ + char *hdrline, *unfolded, *unqp; + strlist allunfoldeds = tll_init(); + char *posteraddr = NULL; + bool hdrsadded = false; + bool subject_present = false; + FILE *f = fdopen(dup(infd), "r"); + + scan_headers(f, readhdrs, allhdrs, &allunfoldeds); + /* if we have custom headers , extract posteraddr from current header */ if(hdrfd >= 0) { strlist fromemails = tll_init();