From: Simon Schubert <2@0x2c.org> Date: Sat, 8 Jan 2011 14:30:12 +0000 (+0100) Subject: readmail: accept mail without newline at the end X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=807f777abf9b99a378e553cd152f8a4000154c7e;p=people%2Fms%2Fdma.git readmail: accept mail without newline at the end --- diff --git a/mail.c b/mail.c index 3c0ab1b..041ebe4 100644 --- a/mail.c +++ b/mail.c @@ -341,6 +341,7 @@ readmail(struct queue *queue, int nodot, int recp_from_header) int had_from = 0; int had_messagid = 0; int had_date = 0; + int had_last_line = 0; int nocopy = 0; parse_state.state = NONE; @@ -360,12 +361,20 @@ readmail(struct queue *queue, int nodot, int recp_from_header) return (-1); while (!feof(stdin)) { - if (fgets(line, sizeof(line), stdin) == NULL) + if (fgets(line, sizeof(line) - 1, stdin) == NULL) break; + if (had_last_line) + errlogx(1, "bad mail input format"); linelen = strlen(line); if (linelen == 0 || line[linelen - 1] != '\n') { - errno = EINVAL; /* XXX mark permanent errors */ - return (-1); + /* + * This line did not end with a newline character. + * If we fix it, it better be the last line of + * the file. + */ + line[linelen] = '\n'; + line[linelen + 1] = 0; + had_last_line = 1; } if (!had_headers) { /*