X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Frcvstore.c;h=83c5150ff51a606824666259e69f9278bd59f947;hp=9c842701f14feb06a9e2ae8cabca8f4b6389b4ce;hb=31750e8a12eafcd1b8fa81cb12b988e680254f24;hpb=cf1205b5cbea2f0cd6ea710ec16c637df85b647c diff --git a/uip/rcvstore.c b/uip/rcvstore.c index 9c84270..83c5150 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -49,6 +50,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) @@ -138,7 +140,7 @@ main(int argc, char **argv) if (folder) adios(EX_USAGE, NULL, "only one folder at a time!"); else - folder = getcpy(expandfol(cp)); + folder = mh_xstrdup(expandfol(cp)); } else { adios(EX_USAGE, NULL, "usage: %s [+folder] [switches]", invo_name); @@ -178,6 +180,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 +234,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 */