]> git.ipfire.org Git - people/ms/dma.git/blobdiff - local.c
local: use space instead of tab in "From " separator
[people/ms/dma.git] / local.c
diff --git a/local.c b/local.c
index fd816ddfd86963427befcb3dfa593af2d20f8fba..94e217928983743c846c357e6e9a78c86de7aee2 100644 (file)
--- a/local.c
+++ b/local.c
@@ -1,8 +1,9 @@
 /*
+ * Copyright (c) 2008-2014, Simon Schubert <2@0x2c.org>.
  * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
  *
  * This code is derived from software contributed to The DragonFly Project
- * by Simon 'corecode' Schubert <corecode@fs.ei.tum.de>.
+ * by Simon Schubert <2@0x2c.org>.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -40,6 +41,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <paths.h>
+#include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <syslog.h>
@@ -80,7 +82,7 @@ create_mbox(const char *name)
 
                execl(LIBEXEC_PATH "/dma-mbox-create", "dma-mbox-create", name, NULL);
                syslog(LOG_ERR, "cannot execute "LIBEXEC_PATH"/dma-mbox-create: %m");
-               exit(1);
+               exit(EX_SOFTWARE);
 
        default:
                /* parent */
@@ -194,7 +196,7 @@ retry:
                goto out;
        }
 
-       error = snprintf(line, sizeof(line), "%sFrom %s\t%s", newline, sender, ctime(&now));
+       error = snprintf(line, sizeof(line), "%sFrom %s %s", newline, sender, ctime(&now));
        if (error < 0 || (size_t)error >= sizeof(line)) {
                syslog(LOG_NOTICE, "local delivery deferred: can not write header: %m");
                goto out;
@@ -213,7 +215,17 @@ retry:
                        goto chop;
                }
 
-               if (hadnl && strncmp(line, "From ", 5) == 0) {
+               /*
+                * mboxro processing:
+                * - escape lines that start with "From " with a > sign.
+                * - be reversable by escaping lines that contain an arbitrary
+                *   number of > signs, followed by "From ", i.e. />*From / in regexp.
+                * - strict mbox processing only requires escaping after empty lines,
+                *   yet most MUAs seem to relax this requirement and will treat any
+                *   line starting with "From " as the beginning of a new mail.
+                */
+               if ((!MBOX_STRICT || hadnl) &&
+                   strncmp(&line[strspn(line, ">")], "From ", 5) == 0) {
                        const char *gt = ">";
 
                        if (write(mbox, gt, 1) != 1)