home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / newsgate / signoff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-18  |  3.3 KB  |  115 lines

  1. /*
  2. **  SIGNOFF
  3. **  Quickie hack to see of a mail message is a "please drop me" request.
  4. **  Exit's with status 0 if it is a regular message, or 1 if it appears to
  5. **  be a one of this administrative requests that annoy everyone when
  6. **  they're sent to the whole list.  Optional first argument is the name
  7. **  of the input file, or stdin is read if none is given.
  8. **
  9. **  Original program written by Russ Nelson, <nelson@clutx.clarkson.edu>.
  10. **  Severely hacked on by Rich $alz, <rsalz@bbn.com>.  This program is
  11. **  basically incorporated into mail2news; it's pulled out here for
  12. **  demonstration.
  13. **
  14. **  For example, here is a script that could be used as a wrapper around
  15. **  the mail2news program:
  16. **    #! /bin/sh
  17. **    cat >/tmp/signoff$$
  18. **    if /usr/lib/news/signoff </tmp/signoff$$ ; then
  19. **        /usr/ucb/Mail -s "Sign on/off request" usenet </tmp/signoff$$
  20. **    else
  21. **        /usr/lib/news/mail2news.real </tmp/signoff$$
  22. **    fi
  23. **    exec rm /tmp/signoff$$
  24. **
  25. **  Russ ran the following test for a month and got only one real message
  26. **  (a gnu.gcc bug report) treated as a subscription request.  He doesn't
  27. **  know how many subs made it out to the net, tho:  that would entail
  28. **  reading ALL netnews articles -- yuck!
  29. **
  30. **  Put the following line in your news sys file:
  31. **    allmail:all::/usr/lib/news/ts
  32. **  here is the "ts" script:
  33. **    #! /bin/sh
  34. **    cat >/tmp/ts.$$
  35. **    /usr/lib/news/signoff </tmp/ts.$$ || mail usenet </tmp/ts.$$
  36. **    exec rm /tmp/ts.$$
  37. **
  38. **  Perhaps a better way to test is to make the test less conservative,
  39. **  and see what "real" articles get caught, and make adjustments then?
  40. **  Comments solicited.
  41. */
  42. #include <stdio.h>
  43. #include <ctype.h>
  44.  
  45. #define EQ(a, b)        (strcmp((a), (b)) == 0)
  46.  
  47.  
  48. main(ac, av)
  49.     int            ac;
  50.     char        *av[];
  51. {
  52.     register FILE    *F;
  53.     register char    *p;
  54.     register int    c;
  55.     register int    drop_or_add;
  56.     register int    from_or_to;
  57.     register int    mail_word;
  58.     register int    count;
  59.     char        word[128];
  60.  
  61.     /* Get input. */
  62.     if (ac < 2)
  63.     F = stdin;
  64.     else if ((F = fopen(av[1], "r")) == NULL) {
  65.     (void)fprintf(stderr, "%s: cannot open %s\n", av[0], av[1]);
  66.     exit(1);
  67.     }
  68.  
  69.     /* Skip headers by waiting for the first blank line. */
  70.     while (fgets(word, sizeof word, F) && *word != '\n')
  71.         ;
  72.  
  73.     /* Clear counts. */
  74.     drop_or_add = 0;
  75.     from_or_to = 0;
  76.     mail_word = 0;
  77.     count = 0;
  78.  
  79.     /* Read input a word at a time. */
  80.     for (p = word; (c = getc(F)) != EOF; ) {
  81.     if (!isalpha(c)) {
  82.         *p = '\0';
  83.         if (p > word)
  84.         count++;
  85.         p = word;
  86.  
  87.         if (EQ(word, "remove") || EQ(word, "drop") || EQ(word, "off")
  88.          || EQ(word, "subscribe") || EQ(word, "get") || EQ(word, "add"))
  89.         drop_or_add++;
  90.         else if (EQ(word, "from") || EQ(word, "to"))
  91.         from_or_to++;
  92.         else if (EQ(word, "mail") || EQ(word, "mailing")
  93.           || EQ(word, "list") || EQ(word, "dl"))
  94.         mail_word++;
  95.     }
  96.     else if (p < &word[sizeof word - 1])
  97.         *p++ = isupper(c) ? tolower(c) : c;
  98.     }
  99.  
  100.     (void)fclose(F);
  101.  
  102.     /* Use fancy-shmancy AI techniques to determine what the message is. */
  103.     c = count < 25 && drop_or_add && from_or_to && mail_word;
  104.  
  105. #if    defined(DEBUG)
  106.     printf("%s: %d words, %d drop, %d mail --> %s\n",
  107.        av[1] ? av[1] : "<stdin>",
  108.        count, drop_or_add, mail_word,
  109.        c ? "yes" : "no");
  110. #endif    /* defined(DEBUG) */
  111.  
  112.     /* Exit appropriately. */
  113.     exit(c ? 0 : 1);
  114. }
  115.