/* * cleanmail.c -- strip crap from net mail */ #include static char *byebyelines[] = { "Via:", "Status:", "Received:", "Arpa-Address:", "Article-I.D.:", "Article-ID:", "In-Reply-To:", "In-reply-to:", "Relay-Version:", "Posting-Version:", "Newsgroups:", "Date-Received:", "Organization:", "Lines:", "Return-Path:", "Message-Id:", "Message-ID:", "Reply-To:", " id ", "Sender:", 0 }; char linebuff[133]; main(argc, argv) int argc; char **argv; { register char c; register int i, j, found; FILE *infile, *outfile; char *tempname = "ClmXXXXXX"; char backname[15]; if (argc < 2) { fprintf(stderr, "Usage: cleanmail file1 file2 .... \n"); exit(-1); } for (i = 1; --argc > 0; i++) { if ((infile = fopen(argv[i], "r")) == NULL) { perror (argv[i]); continue; } if ((outfile = fopen(mktemp(tempname), "w")) == NULL) { perror(tempname); exit(-1); } printf("cleaning %s\n", argv[i]); strcpy(backname, argv[i]); link(argv[i], strcat(backname, ".bak")); unlink(argv[i]); while (fgets(linebuff, sizeof linebuff, infile) != NULL) { found = 0; for (j = 0; byebyelines[j] != NULL; j++) { if (linebuff[0] == byebyelines[j][0]) { if (strncmp(byebyelines[j], linebuff, strlen(byebyelines[j])) == 0) { ++found; break; } } } if (!found) fputs(linebuff, outfile); } fclose(outfile); fclose(infile); link(tempname, argv[i]); unlink(tempname); } }