home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / contrib / striphdrs / striphdrs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-22  |  3.0 KB  |  136 lines

  1. /* @(#)contrib/striphdrs/striphdrs.c    1.2 5/23/92 01:01:55 */
  2.  
  3. /*
  4.  * Clean up headers in mail destined for a mailing list. I usually invoke
  5.  * this from the smail alias file as follows:
  6.  *
  7.  * foo:    "|/usr/local/smail/striphdrs|/usr/local/bin/smail -oi -q -f foo-request foo-redist"
  8.  *
  9.  * Written January 1991 (or there abouts) by Lyndon Nerenberg.
  10.  * This program is in the public domain.
  11.  *
  12.  * --lyndon@ampr.ab.ca
  13.  */
  14.  
  15. #ifndef lint
  16. static char RCSid[] = "$Id: striphdrs.c,v 1.7 1992/05/22 21:55:31 lyndon Exp $";
  17. #endif /* ! lint */
  18.  
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #ifdef SYSV
  22. #include <string.h>
  23. #else /* ! SYSV */
  24. #include <strings.h>
  25. #endif /* ! SYSV */
  26. #ifndef NO_MALLOC_H
  27. #include <malloc.h>
  28. #endif /* NO_MALLOC_H */
  29.  
  30. /*
  31.  * Define MAILLIST if you're using this to filter messages destined for
  32.  * a mailing list exploder. This ensures messages have a "Precedence: bulk"
  33.  * header, and strips out any Return-Receipt-To: header - something you
  34.  * don't want leaking out to the entire mailing list.
  35.  */
  36.  
  37. #if !defined(MAILLIST) && !defined(NO_MAILLIST)
  38. #define MAILLIST
  39. #endif    /* ! MAILLIST && ! NO_MAILLIST */
  40.  
  41. #ifdef sun
  42. extern void exit();
  43. #endif /* sun */
  44.  
  45. #define INBUFSIZE 4096        /* Size of input buffer. Lines longer than */
  46.                 /* this will be truncated. */
  47. #define    TRUE    1
  48. #define FALSE    0
  49.  
  50. static int strncasecmp();
  51.  
  52. static char *hdr_del[] = {    /* NULL terminated list of hdrs to delete */
  53.   "Return-Path:",
  54.   "Received:",
  55.   "Errors-To:",
  56. #ifdef MAILLIST
  57.   "Return-Receipt-To:",
  58. #endif /* MAILLIST */
  59.   "Sender:",
  60.   "Precedence:",
  61.   NULL };
  62.  
  63. main(argc, argv)
  64.   int argc; char *argv[];
  65. {
  66.   
  67.   register char *inbuf;        /* Input buffer */
  68.   register char **c;        /* Temporary pointer */
  69.   int  in_headers = TRUE;    /* Set to 0 when last header encountered */
  70.   int  deleting = FALSE;    /* Set to 1 if actively deleting header */
  71.   
  72.   inbuf = (char *) malloc((unsigned) INBUFSIZE);
  73.   if (inbuf == NULL) {
  74.     (void) fprintf(stderr, "%s: malloc(INBUFSIZE) failed!\n", argv[0]);
  75.     exit(1);
  76.   }
  77.   
  78.   while ((fgets(inbuf, INBUFSIZE, stdin)) != NULL) {
  79.     
  80.     if (in_headers) {
  81.       
  82.       if (*inbuf == '\n') {
  83.     in_headers = FALSE;    /* Header/body seperator found */
  84. #ifdef MAILLIST
  85.     (void) fputs("Precedence: bulk\n\n", stdout);
  86. #else /* ! MAILLIST */
  87.     (void) fputs("\n\n", stdout);
  88. #endif /* ! MAILLIST */
  89.     continue;
  90.       }
  91.  
  92.       if (deleting && ((*inbuf == ' ') || (*inbuf == '\t')))
  93.     continue;        /* Skip any continuation lines */
  94.       else
  95.     deleting = FALSE;
  96.       
  97.       /* See if this is a bogus header */
  98.       for (c = hdr_del; *c != NULL; c++)
  99.     if (strncasecmp(inbuf, *c, strlen(*c)) == 0)
  100.       deleting = TRUE;
  101.  
  102.       if (!deleting)
  103.     (void) fputs(inbuf, stdout);
  104.     }
  105.     else
  106.       (void) fputs(inbuf, stdout);
  107.   }
  108.   exit(0);
  109. /*NOTREACHED*/
  110. }
  111.  
  112. static int
  113. strncasecmp(s1, s2, n)
  114.     char *s1;
  115.     char *s2;
  116.     int n;
  117. {
  118.     int c1, c2;
  119.     int cnt = n;
  120.  
  121.     while (*s1 && *s2 && cnt > 0) {
  122.     if (isupper(c1 = *s1++)) {
  123.         c1 = tolower(c1);
  124.     }
  125.     if (isupper(c2 = *s2++)) {
  126.         c2 = tolower(c2);
  127.     }
  128.     if (c1 != c2) {
  129.         return c1-c2;
  130.     }
  131.     cnt--;
  132.     }
  133.  
  134.     return cnt ? (int)((*s1)-(*s2)) : 0;
  135. }
  136.