🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.mail.headers
Article #182

Re: Header stripper

#182
From: Randall L. Smith
Date: Mon, 08 Apr 1991 18:15
139 lines
4392 bytes
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?

/*
 *    header.c
 *
 *    Author:  Randall L. Smith
 *    Bangpath: ...<backbone>!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 "Path:" and the last line of the
 *    header must be a blank line.
 *
 *    BUGS:  None known.
 *
 */

#include <stdio.h>

#ifndef NULL
#define NULL  (void* ) 0
#endif

#ifndef BUFSIZE
#define BUFSIZE 512
#endif

#ifndef FILENAME
#define FILENAME 256
#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 <cr> is for....
     */
    char fil_name[FILENAME], inp_str[BUFSIZE], temp_file[FILENAME];

    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]);
	    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) {
		(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: 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: ...<backbone>!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.
Technical Details
Message-ID: <10712@rls.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!rls!randy
References: <1991Apr2.063227.25582@engin.umich.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!rls!randy
From: randy@rls.UUCP (Randall L. Smith)
Newsgroups: comp.mail.headers
Subject: Re: Header stripper
Message-ID: <10712@rls.UUCP>
Date: 8 Apr 91 18:15:40 GMT
References: <1991Apr2.063227.25582@engin.umich.edu>
Organization: The Internet
Lines: 121