static char *tmpfilenam = NULL;
void unlink_done();
+static void fix_mbox(int out, char *ofile);
int
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);
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
*/