]> diplodocus.org Git - mdeliver/commitdiff
(deliver): Check for and strip 'From ' line that some broken mailers
authorepg <>
Sun, 25 Aug 2002 06:50:37 +0000 (06:50 +0000)
committerepg <>
Sun, 25 Aug 2002 06:50:37 +0000 (06:50 +0000)
(such as Postfix) add as the first line of input.

mdeliver.c

index 99eaec1..03f5c99 100644 (file)
@@ -119,6 +119,33 @@ deliver(char *maildir, char *newfn)
     /* From this point, we have a tmp file, so if someting fails we
      * must try to unlink it before bombing. */
 
+    {
+        r = read(STDIN_FILENO, buf, 5);
+        if (r != 5) {
+            unlink(fn);
+            err(EX_TEMPFAIL, "Failed read from stdin");
+        }
+
+        if (strncmp(buf, "From ", 5)) {
+            while ((r = read(STDIN_FILENO, buf, 1)) > 0
+                   || (r == -1 && errno == EINTR)) {
+                if (buf[0] == '\n') {
+                    break;
+                }
+            }
+
+            if (r == -1) {
+                unlink(fn);
+                err(EX_TEMPFAIL, "Failed read from stdin");
+            }
+        } else {
+            if (full_write(fd, buf, r) != r) {
+                unlink(fn);
+                err(EX_TEMPFAIL, "Failed write(%s)", fn);
+            }
+        }
+    }
+
     while ((r = read(STDIN_FILENO, buf, BUFSIZ)) > 0
            || (r == -1 && errno == EINTR)) {
         if (full_write(fd, buf, r) != r) {