]> git.ipfire.org Git - thirdparty/fcron.git/commitdiff
Move format_displayname() and make_mailbox_addr() into their own file.
authorThibault Godouet <yo8192@users.noreply.github.com>
Sat, 24 Aug 2024 21:25:45 +0000 (22:25 +0100)
committerThibault Godouet <yo8192@users.noreply.github.com>
Sat, 24 Aug 2024 21:25:45 +0000 (22:25 +0100)
Makefile.in
fcronconf.c
job.c
mail.c [new file with mode: 0644]
mail.h
test/Makefile.in

index cfcfd9564145b42edf5625d39f206dc11066704a..4c046dc4e22e5723a21c233af06cca38cb86d304 100644 (file)
@@ -76,11 +76,11 @@ CFLAGS        += $(OPTIM) $(OPTION) $(DEFS) $(CPPFLAGS) $(LDFLAGS)
 ifeq ($(FCRONDYN), 1)
        LIBOBJS   := $(LIBOBJS)
 endif
-OBJSD         := fcron.o cl.o subs.o mem.o save.o temp_file.o log.o database.o job.o conf.o u_list.o exe_list.o lavg_list.o env_list.o fcronconf.o filesubs.o select.o fcrondyn_svr.o suspend.o $(LIBOBJS)
-OBJSTAB       := fcrontab.o cl.o subs.o mem.o save.o temp_file.o  log.o fileconf.o allow.o read_string.o u_list.o env_list.o fcronconf.o filesubs.o
-OBJSDYN       := fcrondyn.o subs.o mem.o log.o allow.o read_string.o fcronconf.o filesubs.o
-OBJCONV       := convert-fcrontab.o cl.o subs.o mem.o save.o log.o u_list.o env_list.o fcronconf.o filesubs.o
-OBJSIG        := fcronsighup.o subs.o mem.o log.o allow.o fcronconf.o filesubs.o
+OBJSD         := fcron.o cl.o subs.o mem.o save.o temp_file.o log.o database.o job.o conf.o u_list.o exe_list.o lavg_list.o env_list.o fcronconf.o mail.o filesubs.o select.o fcrondyn_svr.o suspend.o $(LIBOBJS)
+OBJSTAB       := fcrontab.o cl.o subs.o mem.o save.o temp_file.o log.o fileconf.o allow.o read_string.o u_list.o env_list.o fcronconf.o mail.o filesubs.o
+OBJSDYN       := fcrondyn.o subs.o mem.o log.o allow.o read_string.o fcronconf.o mail.o filesubs.o
+OBJCONV       := convert-fcrontab.o cl.o subs.o mem.o save.o log.o u_list.o env_list.o fcronconf.o mail.o filesubs.o
+OBJSIG        := fcronsighup.o subs.o mem.o log.o allow.o fcronconf.o mail.o filesubs.o
 HEADERSALL    := config.h $(SRCDIR)/global.h $(SRCDIR)/cl.h $(SRCDIR)/log.h $(SRCDIR)/subs.h $(SRCDIR)/mem.h $(SRCDIR)/save.h $(SRCDIR)/option.h $(SRCDIR)/dyncom.h $(SRCDIR)/mail.h
 
 # this is a regular expression :
index b5280e2489efdf982ea69c38fbe4d9990d1ace72..d743ea64d8c95a7cfa69ce7f9fe003de6bfd8608 100644 (file)
@@ -47,63 +47,6 @@ char *sendmail = NULL;
 char *editor = NULL;
 char *displayname = NULL;
 
-char
-*format_displayname(char *displayname_conf)
-    /* Format the input string `conf_value` according to RFC5322 sec. 3.2.3.
-     * <https://datatracker.ietf.org/doc/html/rfc5322#section-3.2.3>.
-     * Returns: either the formatted displayname (possibly unchanged or empty)
-     * as a new dynamically allocated string (must be properly freed by the
-     * caller) or NULL on errors like buffer overflow. */
-{
-    bool need_quotes = false;
-    char c = '\0';
-    char *ipos = NULL;  /* Input position */
-    char *output = NULL, *quoted_output = NULL;
-
-    const uint buf_len = MAIL_FROM_VALUE_LEN_MAX;
-    uint cwritten = 0;  /* how many chars we have written */
-
-    if (strlen(displayname_conf) == 0) return strdup2("");
-
-    output = (char *)alloc_safe(buf_len * sizeof(char), "output buffer");
-
-    /* walk the conf_value and rebuild it in buf1 */
-    for (ipos = displayname_conf; *ipos; ipos++) {
-        c = *ipos;
-        if (strchr(SPECIAL_MBOX_CHARS, c)) {
-            /* insert escape */
-            if (c == DQUOTE) {
-                output[cwritten] = BSLASH;
-                cwritten++;
-            }
-            need_quotes = true;
-        }
-        if (cwritten >= buf_len) {
-            error("Formatted 'displayname' exceeds %u chars", buf_len);
-            Free_safe(output);
-            return NULL;
-        }
-        output[cwritten] = c;
-        cwritten++;
-    }
-
-    if (need_quotes) {
-        quoted_output = (char *)alloc_safe(buf_len * sizeof(char), "quoted output buffer");
-        int needed_len = snprintf(quoted_output, buf_len, "\"%s\"", output);
-        if (needed_len >= buf_len){
-            error("Formatted 'displayname' too long: length:%u > max:%u chars", needed_len, buf_len);
-            Free_safe(output);
-            Free_safe(quoted_output);
-            return NULL;
-        }
-        Free_safe(output);
-
-        return quoted_output;
-    }
-
-    return output;
-}
-
 void
 init_conf(void)
 /* initialises config with compiled in constants */
diff --git a/job.c b/job.c
index 5191255a07aec1b1b2f0442b011831143d920956..f956fb4e05d3664c5adc09bcb8d3beced51555eb 100644 (file)
--- a/job.c
+++ b/job.c
@@ -278,43 +278,6 @@ sig_dfl(void)
     signal(SIGPIPE, SIG_DFL);
 }
 
-char *
-make_mailbox_addr(char *displayname_conf, char *mail_from, char *hostname)
-    /* Produce a "mailbox" header as per RFC5322 sec. 3.2.3
-     * <https://datatracker.ietf.org/doc/html/rfc5322#section-3.2.3>.
-     * Returns: either the formatted mailbox header as a new dynamically
-     * allocated string (must be properly freed by the caller) or NULL on
-     * errors like buffer overflow. */
-{
-    char *buf = NULL;
-    uint written = 0;
-    bool need_anglebrackets = false;
-
-    const uint buf_len = MAIL_FROM_VALUE_LEN_MAX+1;
-
-    buf = (char *)alloc_safe(buf_len * sizeof(char), "mailbox addr buffer");
-
-    if (displayname_conf[0] != '\0') {
-        /* displayname_conf isn't an empty string */
-        need_anglebrackets = true;
-    }
-
-    /* no @ here, it's handled upstream */
-    if (need_anglebrackets)
-        written = snprintf(buf, buf_len, "%s %c%s%s%c",
-                           displayname_conf, '<', mail_from, hostname, '>');
-    else
-        written = snprintf(buf, buf_len, "%s%s", mail_from, hostname);
-
-    if (written >= buf_len) {
-        error("Mailbox addr exceeds %u chars", buf_len);
-        Free_safe(buf);
-        return NULL;
-    }
-
-    return buf;
-}
-
 FILE *
 create_mail(cl_t * line, char *subject, char *content_type, char *encoding,
             char **env)
diff --git a/mail.c b/mail.c
new file mode 100644 (file)
index 0000000..e42a5ca
--- /dev/null
+++ b/mail.c
@@ -0,0 +1,120 @@
+/*
+ * FCRON - periodic command scheduler
+ *
+ *  Copyright 2000-2021 Thibault Godouet <fcron@free.fr>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  The GNU General Public License can also be found in the file
+ *  `LICENSE' that comes with the fcron source distribution.
+ */
+
+
+#include "fcron.h"
+#include "mail.h"
+
+char
+*format_displayname(char *displayname_conf)
+    /* Format the input string `conf_value` according to RFC5322 sec. 3.2.3.
+     * <https://datatracker.ietf.org/doc/html/rfc5322#section-3.2.3>.
+     * Returns: either the formatted displayname (possibly unchanged or empty)
+     * as a new dynamically allocated string (must be properly freed by the
+     * caller) or NULL on errors like buffer overflow. */
+{
+    bool need_quotes = false;
+    char c = '\0';
+    char *ipos = NULL;  /* Input position */
+    char *output = NULL, *quoted_output = NULL;
+
+    const uint buf_len = MAIL_FROM_VALUE_LEN_MAX;
+    uint cwritten = 0;  /* how many chars we have written */
+
+    if (strlen(displayname_conf) == 0) return strdup2("");
+
+    output = (char *)alloc_safe(buf_len * sizeof(char), "output buffer");
+
+    /* walk the conf_value and rebuild it in buf1 */
+    for (ipos = displayname_conf; *ipos; ipos++) {
+        c = *ipos;
+        if (strchr(SPECIAL_MBOX_CHARS, c)) {
+            /* insert escape */
+            if (c == DQUOTE) {
+                output[cwritten] = BSLASH;
+                cwritten++;
+            }
+            need_quotes = true;
+        }
+        if (cwritten >= buf_len) {
+            error("Formatted 'displayname' exceeds %u chars", buf_len);
+            Free_safe(output);
+            return NULL;
+        }
+        output[cwritten] = c;
+        cwritten++;
+    }
+
+    if (need_quotes) {
+        quoted_output = (char *)alloc_safe(buf_len * sizeof(char), "quoted output buffer");
+        int needed_len = snprintf(quoted_output, buf_len, "\"%s\"", output);
+        if (needed_len >= buf_len){
+            error("Formatted 'displayname' too long: length:%u > max:%u chars", needed_len, buf_len);
+            Free_safe(output);
+            Free_safe(quoted_output);
+            return NULL;
+        }
+        Free_safe(output);
+
+        return quoted_output;
+    }
+
+    return output;
+}
+
+char *
+make_mailbox_addr(char *displayname_conf, char *mail_from, char *hostname)
+    /* Produce a "mailbox" header as per RFC5322 sec. 3.2.3
+     * <https://datatracker.ietf.org/doc/html/rfc5322#section-3.2.3>.
+     * Returns: either the formatted mailbox header as a new dynamically
+     * allocated string (must be properly freed by the caller) or NULL on
+     * errors like buffer overflow. */
+{
+    char *buf = NULL;
+    uint written = 0;
+    bool need_anglebrackets = false;
+
+    const uint buf_len = MAIL_FROM_VALUE_LEN_MAX+1;
+
+    buf = (char *)alloc_safe(buf_len * sizeof(char), "mailbox addr buffer");
+
+    if (displayname_conf[0] != '\0') {
+        /* displayname_conf isn't an empty string */
+        need_anglebrackets = true;
+    }
+
+    /* no @ here, it's handled upstream */
+    if (need_anglebrackets)
+        written = snprintf(buf, buf_len, "%s %c%s%s%c",
+                           displayname_conf, '<', mail_from, hostname, '>');
+    else
+        written = snprintf(buf, buf_len, "%s%s", mail_from, hostname);
+
+    if (written >= buf_len) {
+        error("Mailbox addr exceeds %u chars", buf_len);
+        Free_safe(buf);
+        return NULL;
+    }
+
+    return buf;
+}
diff --git a/mail.h b/mail.h
index 86a82c5b668d45a2a097ea2ac5aba026235235ba..ff16064b760b1cab406d372ae39df0367ffb7b22 100644 (file)
--- a/mail.h
+++ b/mail.h
@@ -29,4 +29,7 @@
 #define FROM_HEADER_KEY "From: "
 #define MAIL_FROM_VALUE_LEN_MAX (MAIL_LINE_LEN_MAX - sizeof(FROM_HEADER_KEY))
 
+extern char *format_displayname(char *displayname_conf);
+extern char *make_mailbox_addr(char *displayname_conf, char *mail_from, char *hostname);
+
 #endif                          /* __MAIL_H__ */
index 74a18cf95734b421f38f3d62c2165d51d8bca9f1..38c54765f8e804fd4deb4c283a59de15bc405f07 100644 (file)
@@ -4,7 +4,7 @@ LIBS   := @LIBS@
 SRCST  := mailbox_addr.c
 OBJST  := $(patsubst %.c,%.o,$(SRCST))
 EXEST  := $(patsubst %.c,%,$(SRCST))
-OBJSD  := $(addprefix $(SRCDIR)/,log.o job.o mem.o filesubs.o subs.o fcronconf.o temp_file.o env_list.o u_list.o)
+OBJSD  := $(addprefix $(SRCDIR)/,log.o job.o mem.o filesubs.o subs.o fcronconf.o mail.o temp_file.o env_list.o u_list.o)
 
 CFLAGS += -I$(SRCDIR)
 CFLAGS += @CFLAGS@