Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!tut.cis.ohio-state.edu!rls!randy From: randy@rls.UUCP (Randall L. Smith) Newsgroups: comp.mail.headers Subject: Re: Header stripper Summary: AW, SHOOT! *&^@&^* Message-ID: <10714@rls.UUCP> Date: 8 Apr 91 19:47:36 GMT References: <1991Apr2.063227.25582@engin.umich.edu> <10712@rls.UUCP> Organization: The Internet Lines: 161 In article <10712@rls.UUCP>, randy@rls.UUCP (Randall L. Smith) writes: > In article <1991Apr2.063227.25582@engin.umich.edu>, mjo@irie.ais.org (Mike O'Connor) writes: >> I am looking for a program/script that strips extraneous mail header >> stuff from my mbox... I generally don't need to see the 20 or so >> machines that my mail goes through to get to me. Does anyone have any >> suggestions? I will post to comp.mail.headers if I receive a large >> body of mail on the subject. > > I dunno, is this what you're looking for? > [....] > * Easily achieved because the first line of a mail or news > * header must begin with "Path:" and the last line of the > * header must be a blank line. Rats!! I test *after* I post. Sorry folks. Heres the *corrected* version. The last version only trims news headers. This one does both mail and news. /* * header.c * * Author: Randall L. Smith * Bangpath: ...!tut!rls!randy * Internet: rls!randy@tut.cis.ohio-state.edu * * Donated to the public domain March 1, 1991. Do whatever you * like with it, even make money, as if you could. :-) * * Simply strips headers off news & mail text files. (destructively) * * Easily achieved because the first line of a mail or news * header must begin with "From " or "Path:", respectively and * the last line of the header must be a blank line. * * BUGS: Has potential to destroy files ending in .t * */ #include #ifndef NULL #define NULL (void* ) 0 #endif #ifndef BUFSIZE #define BUFSIZE 512 #endif /* making room to append .t to temp file name. if you have longer file names, then change FILNAMLEN to max_file_name_length - 2 */ #ifndef FILENAME #define FILENAME 12 #endif FILE *fil_desc, *temp_chan; int main(argc, argv) int argc; char *argv[]; { int file_count = 0, first_blank_line, ch, verbose = 0; /* * large BUFSIZE is for news posters that don't know what is for.... */ char fil_name[FILENAME], inp_str[BUFSIZE], temp_file[FILENAME+2]; while ((ch = getopt(argc, argv, "hv")) != EOF) { switch (ch) { case 'v': verbose = -1; file_count++; break; case 'h': fprintf(stdout, "Usage: %s [ filenames to have mail or news headers stripped ]\n", argv[0]); exit(0); } } while (file_count < argc) while (++file_count < argc) { (void) strcpy(fil_name, argv[file_count]); if ( strlen(fil_name) > FILENAME ) { (void) fprintf(stderr, "File name %s too long.\n", fil_name); break; } first_blank_line = 0; fil_desc = fopen(fil_name, "r"); if (ferror(fil_desc) != 0 || fil_desc == 0) { (void) fprintf(stderr, "Error opening %s\n", fil_name); break; } /* * Make sure there's a header to strip... * The wierd main while loop is due to this break statement. * The other option was a goto, ... not. :-| */ (void) fgets(inp_str, BUFSIZE, fil_desc); if (strncmp(inp_str, "Path:", 5) != 0 && strncmp(inp_str, "From ", 5) != 0) { (void) fclose(fil_desc); if (verbose) fprintf(stdout, "No header to strip from %s\n", fil_name); break; } /* * Waddle through the file until the first blank line past * the Path: or From header line. Once we find it, open a * work file to copy the rest of the files contents. */ while (feof(fil_desc) == 0 && first_blank_line == 0) { (void) fgets(inp_str, BUFSIZE, fil_desc); if (strlen(inp_str) <= 1 && first_blank_line == 0) { first_blank_line = -1; strcpy(temp_file, fil_name); strcat(temp_file, ".t"); temp_chan = fopen(temp_file, "w"); if (ferror(temp_chan) != 0 || temp_chan == 0) { (void) fprintf(stderr, "Error opening %s\n", temp_file); break; } if (verbose) fprintf(stdout, "Stripping header from %s\n", fil_name); } } /* * Copy the rest of the original file into the temp file. */ while (feof(fil_desc) == 0) { (void) fgets(inp_str, BUFSIZE, fil_desc); (void) fputs(inp_str, temp_chan); } /* * Close original and temp files, then delete original * and rename temp to original. Go back and do it again. */ (void) fclose(temp_chan); (void) fclose(fil_desc); (void) unlink(fil_name); (void) link(temp_file, fil_name); (void) unlink(temp_file); } exit(0); } Cheers! - randy Usenet: randy@rls.uucp Bangpath: ...!osu-cis!rls!randy Internet: rls!randy@tut.cis.ohio-state.edu %CC-I-ANACRONISM, The operator is an obsolete form and may not be portable.