From: Philipp Takacs Date: Sun, 31 Jan 2016 18:47:23 +0000 (+0100) Subject: simple mbox support for rcvstore X-Git-Tag: mmh-0.3~39^2 X-Git-Url: http://git.marmaro.de/?p=mmh;a=commitdiff_plain;h=4cc601f996579386ce4f4937b9b72b7b3d891107 simple mbox support for rcvstore Some MTA(opensmtpd) add a ``From '' line ad the head of mails befor handling the mail to a .forwoad MDA. m_getfld2 don't support such mails, so rcvstore should handle this mbox-like mails. --- diff --git a/uip/rcvstore.c b/uip/rcvstore.c index 9c84270..5c7f9d8 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -49,6 +49,7 @@ static struct swit switches[] = { static char *tmpfilenam = NULL; void unlink_done(); +static void fix_mbox(int out, char *ofile); int main(int argc, char **argv) @@ -178,6 +179,9 @@ main(int argc, char **argv) } chmod(tmpfilenam, m_gmprot()); + /* check if incoming mail is in mbox-format */ + fix_mbox(fd, tmpfilenam); + /* copy the message from stdin into temp file */ cpydata(fileno(stdin), fd, "standard input", tmpfilenam); @@ -229,6 +233,35 @@ main(int argc, char **argv) return EX_OK; } +static void +fix_mbox(int out, char *outfile) +{ + char mbox[5]; + int ret; + + if ((ret = read(fileno(stdin), mbox, sizeof(mbox))) != sizeof(mbox)) { + if (ret == -1) { + adios(EX_IOERR, "standard input", "error reading"); + } + return; + } + + if (strncmp(mbox, "From ", sizeof(mbox))==0) { + do { + if ((ret = read(fileno(stdin), mbox, 1)) != 1) { + if (ret == -1) { + adios(EX_IOERR, "standard input", "error reading"); + } + return; + } + } while (*mbox != '\n'); + } else { + if (write(out, mbox, sizeof(mbox)) != sizeof(mbox)) { + adios(EX_IOERR, outfile, "error writing"); + } + } +} + /* ** Clean up and exit */