Article View: comp.mail.headers
Article #178Re: Header stripper
From: Lyndon Nerenberg
Date: Wed, 03 Apr 1991 17:09
Date: Wed, 03 Apr 1991 17:09
114 lines
3938 bytes
3938 bytes
paul@uxc.cso.uiuc.edu (Paul Pomes - UofIllinois CSO) writes:
>mjo@irie.ais.org (Mike O'Connor) writes:
>>Sorry... poor choice of words in my initial post. I not only don't
>>want to SEE the headers, but I also don't want to KEEP the headers. I
>>use elm, and find that I am making large folders that are half
>>headers! I would like some automagic way of stripping those headers.
>Some time back I wrote the thdr filter to do just that for mail messages
>inbound to notesfiles. It uses the regexp package (every program should
>be a learning experience). Now for the incantation:
Regexp? Ick! here's something I hacked together a while back that should
do what he asked for. Also available via anonymous ftp from
aupair.cs.athabascau.ca:mail/striphdrs.c.
/*
* Clean up headers in mail destined for a mailing list. I usually invoke
* this from the smail alias file as follows:
*
* foo: "|/usr/local/smail/striphdrs|/usr/local/bin/smail -oi -q -f foo-request foo-redist"
*
* Written January 1991 (or there abouts) by Lyndon Nerenberg.
* This program is in the public domain.
*
* --lyndon@cs.athabascau.ca
*/
#ifndef lint
static char RCSid[] = "$Id: striphdrs.c,v 1.6 91/04/03 10:05:09 lyndon Rel $";
#endif /* ! lint */
#include <stdio.h>
#include <strings.h>
#include <malloc.h>
/*
* Define MAILLIST if you want a "Precedence: bulk" header to be automatically
* included in every message (useful for mailing list traffic).
*/
#define MAILLIST
#ifdef sun
extern void exit();
#endif /* sun */
#define INBUFSIZE 4096 /* Size of input buffer. Lines longer than */
/* this will be truncated. */
#define TRUE 1
#define FALSE 0
static char *hdr_del[] = { /* NULL terminated list of hdrs to delete */
"Return-Path:",
"Received:",
"Errors-To:",
"Sender:",
"Precedence:",
NULL };
main(argc, argv)
int argc; char *argv[];
{
char *inbuf; /* Input buffer */
char **c; /* Temporary pointer */
int in_headers = TRUE; /* Set to 0 when last header encountered */
int deleting = FALSE; /* Set to 1 if actively deleting header */
inbuf = (char *) malloc((unsigned) INBUFSIZE);
if (inbuf == NULL) {
(void) fprintf(stderr, "%s: malloc(INBUFSIZE) failed!\n", argv[0]);
exit(1);
}
while ((fgets(inbuf, INBUFSIZE, stdin)) != NULL) {
if (in_headers) {
if (*inbuf == '\n') {
in_headers = FALSE; /* Header/body seperator found */
#ifdef MAILLIST
(void) fputs("Precedence: bulk\n\n", stdout);
#else /* ! MAILLIST */
(void) fputs("\n\n", stdout);
#endif /* ! MAILLIST */
continue;
}
if (deleting && ((*inbuf == ' ') || (*inbuf == '\t')))
continue; /* Skip any continuation lines */
else
deleting = FALSE;
/* See if this is a bogus header */
for (c = hdr_del; *c != NULL; c++)
if (strncasecmp(inbuf, *c, strlen(*c)) == 0)
deleting = TRUE;
if (!deleting)
(void) fputs(inbuf, stdout);
}
else
(void) fputs(inbuf, stdout);
}
exit(0);
/*NOTREACHED*/
}
--
Lyndon Nerenberg VE6BBM / Computing Services / Athabasca University
atha!cs.athabascau.ca!lyndon || lyndon@cs.athabascau.ca
Packet: ve6bbm@ve6bbm.ab.can.noam
The only thing open about OSF is their mouth. --Chuck Musciano
Technical Details
Message-ID:
<1592@aupair.cs.athabascau.ca>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!lll-winken!aunro!aupair.cs.athabascau.ca!lyndonReferences:
<1991Apr2.063227.25582@engin.umich.edu> <1991Apr2.123656.24499@mp.cs.niu.edu> <1991Apr2.154149.3899@engin.umich.edu> <1991Apr2.201030.7924@ux1.cso.uiuc.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!sol.ctr.columbia.edu!lll-winken!aunro!aupair.cs.athabascau.ca!lyndon From: lyndon@cs.athabascau.ca (Lyndon Nerenberg) Newsgroups: comp.mail.headers Subject: Re: Header stripper Message-ID: <1592@aupair.cs.athabascau.ca> Date: 3 Apr 91 17:09:55 GMT References: <1991Apr2.063227.25582@engin.umich.edu> <1991Apr2.123656.24499@mp.cs.niu.edu> <1991Apr2.154149.3899@engin.umich.edu> <1991Apr2.201030.7924@ux1.cso.uiuc.edu> Organization: Athabasca University Lines: 114