From 76e6c4793248607e2e6bf06adbae839b13bf5da2 Mon Sep 17 00:00:00 2001 From: epg <> Date: Sun, 25 Aug 2002 06:50:37 +0000 Subject: [PATCH] (deliver): Check for and strip 'From ' line that some broken mailers (such as Postfix) add as the first line of input. --- mdeliver.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mdeliver.c b/mdeliver.c index 99eaec1..03f5c99 100644 --- a/mdeliver.c +++ b/mdeliver.c @@ -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) { -- 2.56.0