/* Unix-style filter: reads stdin or files named on command line, writes stdout. Each file, or stdin, is a single RFC 822 message, unmodified (except that newlines are local text convention, not network style). EOF is taken as end of message. Output is input converted to dotmail format. This is intended for things like maildir or MH message files, one message per file. For example: */ // cd ~/Maildir // files_to_dotmail cur/* new/* >~/INBOX.dotmail /* Do not concatenate multiple messages on stdin, or in any one input file. Input must not contain mbox-style "From " line before message. Feeding this an mbox file would be a mistake. */ #include #include #define TRUE 1 #define FALSE 0 static void doit(FILE *f) { int bol = TRUE; /* beginning of line */ int c; while ((c = getc(f)) != EOF) { if (c == '.') if (bol) putchar('.'); /* dot-stuff the message line */ putchar(c); bol = (c == '\n'); } if ( !bol) /* invalid input file, no '\n' at end */ putchar('\n'); /* fix it */ puts("."); /* write end-of-message marker */ } int main(int argc, char *argv[], char *envp[]) { FILE *f; int i; if (argc > 1) for (i = 1; i < argc; i++) if ((f = fopen(argv[i], "r")) != NULL) doit(f); else { perror(argv[i]); break; } else doit(stdin); return errno; }