#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	autoreply/INSTALL
#	autoreply/Makefile
#	autoreply/autoreply.c
# This archive created: Sun Nov  8 13:03:45 1992
# By:	Christophe Wolfhugel ()
export PATH; PATH=/bin:$PATH
echo shar: extracting "'autoreply/INSTALL'" '(564 characters)'
if test -f 'autoreply/INSTALL'
then
	echo shar: will not over-write existing file "'autoreply/INSTALL'"
else
sed 's/^X//' << \SHAR_EOF > 'autoreply/INSTALL'
XInstallation is easy:
X
X- Configure Makefile
X- Edit the #define's in autoreply.c
X- do "make"
X- do "make install" with appropriate priviledge.
X
XEdit and configure your newsfeeds (INN) or sys (C-News) file according
Xto your requirements.
X
XHere is what I use in my newsfeeds file:
X
Xautoreply\
X	:!*,rocad.test,resif.test,vmsnet.test,sub.test\
X	:Tp:/usr/local/news/bin/local/autoreply
X
XIf you add extensions to this small package I'd like to here about them,
Xplease send a context diff and include the original Revision number.
X
X
XChristophe.Wolfhugel@grasp.insa-lyon.fr
SHAR_EOF
fi # end of overwriting check
echo shar: extracting "'autoreply/Makefile'" '(1418 characters)'
if test -f 'autoreply/Makefile'
then
	echo shar: will not over-write existing file "'autoreply/Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'autoreply/Makefile'
X# $Id: Makefile,v 1.1 92/11/08 13:02:08 wolf Exp $
X#-------------------------------------------------------------------------
X#  Autoreply v3.00 - Automatic reply to messages posted in newsgroups
X#
X#  Copyright (C) 1992, Christophe Wolfhugel - Herve Schauer Consultants
X#                      Email: Christophe.Wolfhugel@hsc-sec.fr
X#
X#  Copyright (C) 1991, Vincent Archer  (archer@frmug.gna.tfd.com)  for
X#                      the original program.
X#
X#  This program is free software; you can redistribute it and/or modify
X#  it under the terms of the GNU General Public License as published by
X#  the Free Software Foundation; either version 1, or (at your option)
X#  any later version.
X#
X#  This program is distributed in the hope that it will be useful,
X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X#  GNU General Public License for more details.
X#
X#  You should have received a copy of the GNU General Public License
X#  along with this program; if not, write to the Free Software
X#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X#
X#----------------------------------------------------------------------
X
XINSTALL	=	/usr/ucb/install
XDESTDIR	=	/usr/lib/newsbin/local
X
Xall: autoreply
X
Xautoreply: autoreply.c
X	cc -O -o autoreply autoreply.c
X
Xinstall: autoreply
X	$(INSTALL) -g news -m 111 -o news -s autoreply $(DESTDIR)
SHAR_EOF
fi # end of overwriting check
echo shar: extracting "'autoreply/autoreply.c'" '(10192 characters)'
if test -f 'autoreply/autoreply.c'
then
	echo shar: will not over-write existing file "'autoreply/autoreply.c'"
else
sed 's/^X//' << \SHAR_EOF > 'autoreply/autoreply.c'
X#ifndef lint
Xchar rcsid[]="@(#)$Id: autoreply.c,v 1.1 92/11/08 13:02:16 wolf Exp $";
X#endif
X/*-------------------------------------------------------------------------
X *  Autoreply v3.10 - Automatic reply to messages posted in newsgroups
X *
X #  Copyright (C) 1992, Christophe Wolfhugel - Herve Schauer Consultants
X #                      Email: Christophe.Wolfhugel@hsc-sec.fr
X *
X *  Copyright (C) 1991, Vincent Archer  (archer@frmug.gna.tfd.com)  for
X *                      the original program.
X *
X *  This program is free software; you can redistribute it and/or modify
X *  it under the terms of the GNU General Public License as published by
X *  the Free Software Foundation; either version 1, or (at your option)
X *  any later version.
X *
X *  This program is distributed in the hope that it will be useful,
X *  but WITHOUT ANY WARRANTY; without even the implied warranty of
X *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X *  GNU General Public License for more details.
X *
X *  You should have received a copy of the GNU General Public License
X *  along with this program; if not, write to the Free Software
X *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X *----------------------------------------------------------------------*/
X
X/*
X * $Revision: 1.1 $
X */
X
X#include <sys/types.h>
X#include <ctype.h>
X#include <dirent.h>
X#include <errno.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <time.h>
X
Xchar temporary[80];
Xchar lockname[80];
Xchar found_file[80];
X
X/* 
X * This is for INN, if you use C-News, the "getdate" needs to be used 
X * just grab the good arguments in the man page. It is used to convert
X * a litteral (article posted) date to a numeric one (seconds since
X * the epoch).
X * If undefined no propagation delays will be computed, it is generally
X * wise to have a reliable clock in order to indicate the delays (we
X * have our systems synchronized with NTP here).
X */
X
X#define  GETDATE	"/usr/local/news/bin/convdate -n"
X
X/*
X * The mail transport agent. Recipients are given on the command line,
X * one some older sites it's /usr/lib/sendmail.
X */
X
X#define  SENDMAIL	"/usr/sbin/sendmail"
X
X/*
X * What appears in the "Path" for the articles at your site, check inn.conf
X * or /usr/lib/news/whoami for C-News folks.
X */
X
X#define  NEWSNAME	"univ-lyon1.fr"
X
X/* 
X * The "From:" to be put in auto replies. If you undefine this then
X * the MTA will add one. If undefined no contact address will be
X * specified at the end of the message.
X */
X
X#define  EMAIL		"newsmaster@univ-lyon1.fr"
X
X/*
X * User getting a blind carbon-copy of all replies, if undefined no
X * Bcc will be generated.
X */
X
X#define  CC		"wolf@grasp1.univ-lyon1.fr"
X
X/*
X * Organization name to put on the mail message (generally 
X * the same as the news server).
X */
X
X#define  ORGANIZATION	"INSA Informatique, Lyon, France"
X
X/*--- End of configuration section ---*/
X
XFILE *reply,*h1;
Xchar line[1024],buf[1024],fl[5][256];
Xchar when[40],user[512];
X
Xint noreply=0;
X
Xtypedef struct {
X                 char *token;
X                 char *value;
X               } HEADER;
X
Xtypedef struct _UHEADER {
X                          struct _UHEADER *next;
X                          char value[1];
X                        } UHEADER;
X
XHEADER hdr[] = { 	
X		"Path: "	,	NULL,
X		"Newsgroups: "	,	NULL,
X		"From: "	,	NULL,
X		"Approved: "	,	NULL,
X		"Reply-To: "	,	NULL,
X		"Followup-To: "	,	NULL,
X		"Date: "	,	NULL,
X		"Subject: "	,	NULL,
X		"Message-ID: "	,	NULL,
X		"Control: "	,	NULL,
X		"Sender: "	,	NULL,
X		"Distribution: ",	NULL,
X		"Organization: ",	NULL,
X		"References: "	,	NULL,
X                "Keywords: "    ,       NULL,
X                "Summary: "     ,       NULL,
X		"Expires: "	,	NULL,
X		"Supersedes: "	,	NULL,
X		"Nntp-Posting-Host: ",	NULL,
X		"Originator: "	,	NULL,
X		"Lines: "	,	NULL,
X		NULL		,	NULL  };
X
Xtypedef enum { PATH, NEWSGROUPS, FROM, APPROVED, REPLY_TO, 
X	       FOLLOWUP_TO, DATE, SUBJECT,
X               MESSAGE_ID, CONTROL, SENDER, DISTRIBUTION, ORG, REF,
X               KEYWORDS, SUMMARY,
X               EXPIRES, SUPERSEDES, NNTP, ORIG, LINES } ID;
X
XUHEADER *uhdr=NULL,*nuhdr=NULL;
X
Xchar *no[] = {	"no ", 
X		"keine ", 
X		"pas ",
X		"ignore",
X		NULL };
Xchar *answer[] = {	" answer",
X			" reply",
X			" antwort",
X			" reponse",
X			"ignore",
X			NULL };
X
Xchar *ignore[] = {	"ignore",
X			NULL };
X
Xvoid strlwr(s)
Xchar *s;
X{
X   for (; *s; s++) *s=tolower(*s);
X}
X
Xint strncasecmp(str1, str2, n)
Xchar *str1, *str2;
Xint n;
X{
X   int c1, c2;
X
X   while (n--) {
X      c1 = *str1++;
X      c2 = *str2++;
X      if (isupper(c1)) c1 += 32;
X      if (isupper(c2)) c2 += 32;
X      if (c1 == c2) {
X         if (!c1)
X            return(0);
X         continue;
X      } /* endif */
X      if (c1 < c2)
X         return -1;
X      return 1;
X   } /* endwhile */
X   return(0);
X}
X
Xvoid testignore(s)
Xchar *s;
X{
X   int i;
X
X   for (i=0; no[i]!=NULL; i++)
X      if (strstr(s,no[i])!=NULL) noreply|=1;
X   for (i=0; answer[i]!=NULL; i++)
X      if (strstr(s,answer[i])!=NULL) noreply|=2;
X   for (i=0; ignore[i]!=NULL; i++)
X      if (strstr(s,ignore[i])!=NULL) noreply|=3;
X}
X
Xusername(s)
Xchar *s;
X{
X   char *t;
X
X   t = line;
X   while (isspace(*s))
X      s++;
X   while (*s) {
X      if (isspace(*s)) {
X         *t++ = 0;
X         s++;
X         continue;
X      } /* endif */
X      if (*s == '(') {
X         while (*s)
X            if (*s++ == ')')
X               break;
X         while (isspace(*s))
X            s++;
X         continue;
X      } /* endif */
X      if (*s == '<') {
X         s++;
X         t = line;
X         while (*s) {
X            if (*s == '>')
X               break;
X            *t++ = *s++;
X         } /* endwhile */
X         if (t != line) {
X            *t = 0;
X            return;
X         } /* endif */
X         continue;
X      } /* endif */
X      *t++ = *s++;
X   } /* endwhile */
X   *t = 0;
X}
X
X#define TOKEN (h->token)
X#define VALUE (h->value)
X
Xmain()
X{
X   char *s;
X   time_t clock;
X   struct tm *tm;
X   int i;
X   HEADER *h;
X
X   user[0]=0;
X   while (fgets(line, sizeof(line), stdin)) {
X      if (line[0] == '\n')
X         break;
X      line[strlen(line)-1] = 0;
X      i=0;
X      for (h= &hdr[0]; TOKEN!=NULL; h++) {
X         if (strncasecmp(line,TOKEN,strlen(TOKEN))==0) {
X            if (VALUE==NULL) {
X               VALUE=malloc(strlen(line)-strlen(TOKEN)+1);
X               strcpy(VALUE,line+strlen(TOKEN));
X            } /* endif */
X            i=1; break;
X         } /* endif */
X      } /* endfor */
X      if (i==1) continue;
X      if (nuhdr==NULL) 
X         uhdr=nuhdr=(UHEADER *)malloc(sizeof(UHEADER)+strlen(line)+1);
X      else {
X         nuhdr->next=(UHEADER *)malloc(sizeof(UHEADER)+strlen(line)+1); 
X         nuhdr=nuhdr->next; 
X      } /* endif */
X      strcpy(nuhdr->value,line); nuhdr->next=NULL;
X   } /* endwhile */
X   for (i=0; i<5; i++) {
X      if (fgets(fl[i],256,stdin)==NULL) { fl[i][0]=0; break; }
X      strcpy(buf,fl[i]); strlwr(buf); testignore(buf);
X   } /* endfor */
X   if (hdr[FROM].value!=NULL) { 
X      username(hdr[FROM].value); 
X      strcpy(user,line);
X   } /* endif */
X   if (hdr[REPLY_TO].value!=NULL) { 
X      username(hdr[REPLY_TO].value); 
X      strcpy(user,line);
X   } /* endif */
X   if (hdr[KEYWORDS].value!=NULL) {
X      strcpy(line,hdr[KEYWORDS].value);
X      strlwr(line); testignore(line);
X   } /* endif */
X   if (hdr[SUMMARY].value!=NULL) {
X      strcpy(line,hdr[SUMMARY].value);
X      strlwr(line); testignore(line);
X   } /* endif */
X   if (hdr[SUBJECT].value!=NULL) {
X      strcpy(line,hdr[SUBJECT].value);
X      strlwr(line); testignore(line);
X   } /* endif */
X
X   if (noreply==3 || user[0]==0) exit(0);
X
X/* CUSTOM */
X   if (strpbrk(user,"`\\/")!=NULL) exit(1);
X#ifdef CC
X   sprintf(line, "%s %s %s", SENDMAIL, user, CC);
X#else
X   sprintf(line, "%s %s", SENDMAIL, user);
X#endif
X   if (!(reply = popen(line, "w"))) {
X      perror("popen");
X      exit(2);
X   } /* endif */
X
X/* CUSTOM */
X   time(&clock);
X   tm = localtime(&clock);
X   strftime(when, sizeof(when), "%a, %d %h %Y %T %Z", tm);
X   fprintf(reply, "\
XFrom: %s (News Administrator)\n\
XTo: %s\n\
XSubject: Automatic reply to your test message.\n\
XIn-reply-to: %s\n\
XOrganization: %s\n\
X\n\
XThis message has been generated automatically in order to help you track\n\
Xthe circulation in the test newsgroups. If you do not wish any reply from\n\
Xthis program, just include the words \"no reply\" or its translation in\n\
Xfrench or german in the subject line or in the 5 first lines of the\n\
Xbody of your message.\n\
X\n\
XYour article %s was received\n\
Xby %s at %s by the\npath %s\n", 
X        EMAIL, user, hdr[MESSAGE_ID].value, ORGANIZATION, 
X        hdr[MESSAGE_ID].value, NEWSNAME, when, hdr[PATH].value);
X
X#ifdef GETDATE
X   if (strpbrk(hdr[DATE].value,"`\\/")==NULL) {
X      sprintf(line,"%s \"%s\"",GETDATE,hdr[DATE].value);
X      h1=popen(line,"r"); line[0]=0;
X      fgets(line,1024,h1);
X      pclose(h1);
X      clock-=atol(line);
X      if (line[0]>='0' && line[0]<='9' && clock>=0) {
X         fprintf(reply,"\n\
XYour message travelled on the network during\n\
X%ld day(s), %ld hour(s), %ld minute(s), %ld second(s)\n\
Xbefore arriving here.\n\
X",clock/(3600L*24L),
X  (clock%(3600L*24L))/3600L,
X  (clock%3600L)/60L,
X  clock%60L);
X      } /* endif */
X   } /* endif */
X#endif
X
X   fprintf(reply,"\n\
XFollowing headers have been recognized in your message:\n\n");
X   for (h= &hdr[0]; TOKEN!=NULL; h++) {
X      if (VALUE!=NULL) {
X         fprintf(reply,"%s%s\n",TOKEN,VALUE);
X         free(VALUE);
X      } /* endif */
X   } /* endfor */
X   if (uhdr!=NULL) {
X      fprintf(reply,"\n\
XFollowing headers are present in your message but have not been recognized\n\
Xby the application. This does not necessarily mean that they are not\n\
Xlegal:\n\n");
X      while (uhdr!=NULL) {
X         fprintf(reply,"%s\n",uhdr->value);
X         nuhdr=uhdr->next; free(uhdr); uhdr=nuhdr;
X      } /* endwhile */
X   } /* endif */
X
X   if (fl[0][0]!=0) {
X      fprintf(reply,"\n\
XThe first lines in the body of your message are:\n\n");
X      for (i=0; i<5; i++) {
X	 if (fl[i][0]==0) break;
X	 fprintf(reply,"-> %s",fl[i]);
X      } /* endfor */
X   } /* endif */
X
X#ifdef EMAIL
X   fprintf(reply,"\n\
XIf you have any questions about this software, please send mail to\n\
X<%s>.\n",EMAIL);
X#endif
X
X   fclose(reply);
X}
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0
