home *** CD-ROM | disk | FTP | other *** search
- head 1.9;
- branch 1.9.1;
- access;
- symbols;
- locks
- simons:1.9.1.15
- andy:1.9; strict;
- comment @ * @;
-
-
- 1.9
- date 93.02.25.16.04.13; author andy; state Exp;
- branches
- 1.9.1.1;
- next ;
-
- 1.9.1.1
- date 93.12.26.00.42.01; author simons; state Exp;
- branches;
- next 1.9.1.2;
-
- 1.9.1.2
- date 93.12.26.00.51.59; author simons; state Exp;
- branches;
- next 1.9.1.3;
-
- 1.9.1.3
- date 93.12.26.00.53.53; author simons; state Exp;
- branches;
- next 1.9.1.4;
-
- 1.9.1.4
- date 93.12.26.18.45.38; author simons; state Exp;
- branches;
- next 1.9.1.5;
-
- 1.9.1.5
- date 93.12.26.19.35.55; author simons; state Exp;
- branches;
- next 1.9.1.6;
-
- 1.9.1.6
- date 93.12.26.21.22.27; author simons; state Exp;
- branches;
- next 1.9.1.7;
-
- 1.9.1.7
- date 93.12.27.17.24.01; author simons; state Exp;
- branches;
- next 1.9.1.8;
-
- 1.9.1.8
- date 93.12.28.00.18.12; author simons; state Exp;
- branches;
- next 1.9.1.9;
-
- 1.9.1.9
- date 93.12.28.17.00.52; author simons; state Exp;
- branches;
- next 1.9.1.10;
-
- 1.9.1.10
- date 93.12.28.17.37.42; author simons; state Exp;
- branches;
- next 1.9.1.11;
-
- 1.9.1.11
- date 93.12.28.21.57.37; author simons; state Exp;
- branches;
- next 1.9.1.12;
-
- 1.9.1.12
- date 93.12.28.22.16.34; author simons; state Exp;
- branches;
- next 1.9.1.13;
-
- 1.9.1.13
- date 93.12.29.06.24.47; author simons; state Exp;
- branches;
- next 1.9.1.14;
-
- 1.9.1.14
- date 93.12.29.07.07.06; author simons; state Exp;
- branches;
- next 1.9.1.15;
-
- 1.9.1.15
- date 93.12.29.07.26.54; author simons; state Exp;
- branches;
- next ;
-
-
- desc
- @Original Unix-Listserv distribution.
- @
-
-
- 1.9
- log
- @checked in with -k by simons at 1993/12/26 00:08:53
- @
- text
- @#include "listserv.h"
-
- static char rcsid[] = "$Header: /nfs/ucsd/local/src/mail/listserv/RCS/main.c,v 1.9 93/02/25 16:04:13 andy Exp Locker: andy $";
-
- FILE *mailer;
- FILE *logfile;
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- char from[256];
- char buf[BUFSIZ];
- char grp[64];
- char dat[64];
- char *p;
- int i;
- int gotcommand = 0;
- int outsider = 0;
- int inheader;
- int log;
- int garbage = 0;
-
- /* gotta have some default if the From: line is missing */
- strcpy(from, "ListServ");
-
- inheader = 1;
- while (fgets(buf,BUFSIZ,stdin) != NULL)
- {
- /* drop trailing newline */
- while (buf[(i=strlen(buf)-1)] == '\n')
- buf[i] = '\0';
-
- /* drop trailing blanks */
- p = buf + (strlen(buf) - 1);
- while (p && *p && p >= buf && isspace(*p))
- *p-- = '\0';
-
- /* deblank beginning of line */
- p = buf;
- while (p && *p && isspace(*p))
- p++;
- if (p != buf)
- strcpy(buf, p);
-
- if (strlen(buf) == 0) /* blank line ends header */
- {
- inheader = 0;
- continue;
- }
-
- /*
- get the From: line so we can return the answer
-
- Note that we DON'T check that we're in the header when
- picking up the From: line; that's so that we'll take the
- last from line we encounter which makes it handle
- forwarded messages correctly.
- */
- if (strncasecmp(buf,"From: ",6) == 0)
- {
- strcpy(from, &buf[6]);
- cleanup(from, &outsider);
- printf("outsider = %d\n", outsider);
- continue;
- }
- if (strncasecmp(buf, "From: listserv", 14) == 0
- || strncasecmp(buf,
- "subject: re: your listserve request", 35) == 0)
- {
- printf("loop detected, flushing mail\n");
- exit(0);
- }
-
- /*
- don't look for commands in the header
- */
- if (inheader)
- continue;
-
- /* avoid mail loops - ignore requests from ourself! */
- if (!strncasecmp(from, "listserv", 8))
- {
- printf("I refuse to talk to myself.\n");
- exit(0);
- }
-
- /* Throw away bounced mail */
- if (strstr(from, "daemon") != NULL)
- {
- printf("We don't do business with your type.\n");
- exit(0);
- }
-
- /* force to lower case and scan for commands */
- p = buf;
- while (p && *p)
- {
- if (isupper(*p))
- *p = tolower(*p);
- p++;
- }
-
- /* log the request */
- log = open(LOGFILE, AFLAGS, AMODE);
- if (log == -1)
- perror(LOGFILE);
- else
- {
- logfile = fdopen(log, "a");
- if (logfile != NULL)
- {
- long clock = time(0);
- strcpy(dat,ctime(&clock));
- /* drop trailing newline */
- while (dat[(i=strlen(dat)-1)] == '\n')
- dat[i] = '\0';
- printf("logfile: %s|%s|%s\n", dat, from, buf);
- fprintf(logfile,"%s|%s|%s\n", dat, from, buf);
- fflush(logfile);
- close(log);
- }
- else
- perror(LOGFILE);
- }
-
- if (!strncasecmp(buf, "list ",5)
- || !strncasecmp(buf, "delete-all ",11)
- || !strncasecmp(buf, "del-all ",8)
- || !strncasecmp(buf, "unsubscribe-all ",16)
- || !strncasecmp(buf, "unsub-all ",10)
- || !strcasecmp(buf, "list")
- || !strcasecmp(buf, "delete-all")
- || !strcasecmp(buf, "del-all")
- || !strcasecmp(buf, "unsubscribe-all")
- || !strcasecmp(buf, "unsub-all"))
- {
- gotcommand++;
- listsearch(from, buf);
- continue;
- }
-
- if (!strncasecmp(buf,"add ", 4)
- || !strncasecmp(buf,"subscribe ", 10)
- || !strncasecmp(buf,"sub ",4))
- {
- gotcommand++;
- subscription(from,buf,1,outsider);
- continue;
- }
-
- if (!strncasecmp(buf,"delete ", 7)
- || !strncasecmp(buf,"del ",4)
- || !strncasecmp(buf,"unsubscribe ", 12)
- || !strncasecmp(buf,"unsub ",6))
- {
- gotcommand++;
- subscription(from,buf,0,outsider);
- continue;
- }
-
- if (!strcasecmp(buf,"index")
- || !strcasecmp(buf,"longindex"))
- {
- gotcommand++;
- sendindex(from,buf,!strcasecmp(buf,"longindex"),
- outsider);
- continue;
- }
-
- if (!strncasecmp(buf, "faq ", 4))
- {
- gotcommand++;
- sendfaq(from, buf, outsider);
- continue;
- }
-
- if (!strcasecmp(buf, "faq"))
- {
- gotcommand++;
- faqindex(from, buf);
- continue;
- }
-
- if (!strcasecmp(buf, "info"))
- {
- gotcommand++;
- infoindex(from, buf);
- continue;
- }
-
- if (!strncasecmp(buf, "info ", 5)
- || !strncasecmp(buf, "get ",4))
- {
- gotcommand++;
- sendinfo(from, buf);
- continue;
- }
-
- if (!strcasecmp(buf,"help"))
- {
- gotcommand++;
- sendhelp(from,buf);
- continue;
- }
-
- if (!strncasecmp(buf,"help ",5))
- {
- gotcommand++;
- sscanf(buf,"%*s%s", grp);
- listhelp(from,grp,buf,outsider);
- continue;
- }
- /* Flush message if > 5 lines of garbage */
- if (++garbage > 5)
- {
- printf("Garbled message, flushing...\n");
- exit(0);
- }
- }
- if (gotcommand == 0)
- sendhelp(from, "indecipherable");
- exit(0);
- }
-
- callmailer(redirect, toaddr, request)
- char *redirect, *toaddr, *request;
- {
- char cbuf[BUFSIZ];
-
- printf("callmailer \"%s\",\"%s\",\"%s\"\n", redirect, toaddr, request);
-
- strcpy(cbuf, MAILER);
- strcat(cbuf, " -f");
- strcat(cbuf, LISTSERVMANAGER);
- strcat(cbuf, " -F\"Mailing List Processor\"");
- strcat(cbuf, " -t -oi");
- strcat(cbuf, " "); strcat(cbuf, redirect);
- mailer = popen(cbuf,"w");
- printf("mailer popen '%s'\n", cbuf);
- if (mailer == NULL)
- {
- perror(cbuf);
- exit(1);
- }
- fprintf(mailer,"From: ");
- fprintf(mailer, LISTSERVADDR);
- fprintf(mailer, " (Mailing List Processor)\n");
- fprintf(mailer,"To: %s\n", toaddr);
- fprintf(mailer,"Subject: Re: your LISTSERV request \"%s\"\n", request);
- fprintf(mailer,"\n");
- }
-
- mailcat(mfname,prefix)
- char *mfname, *prefix;
- {
- FILE *mf;
- char buf[BUFSIZ];
-
- printf("mailcat \"%s\", \"%s\"\n", mfname, prefix);
-
- mf = fopen(mfname,"r");
- if (mf == NULL)
- {
- perror(mfname);
- fprintf(mailer,"This should have been the contents of\n");
- fprintf(mailer,"file '%s' but it's missing!\n",mfname);
- return;
- }
-
- /* copy the message file into the mailer */
- while (fgets(buf,BUFSIZ,mf) != NULL)
- {
- fputs(prefix,mailer);
- fputs(buf,mailer);
- }
- fclose(mf);
- return;
- }
-
- cleanup(from, outsider)
- char *from;
- int *outsider;
- {
- char *p, *q;
-
- printf("cleanup \"%s\"\n", from);
-
- while (p = index(from,'~'))
- *p = 'X';
-
- while (p = index(from,'|'))
- *p = 'X';
-
- /* elide stuff in parenthesis */
- if (p = index(from,'('))
- {
- if ( (q=rindex(from,')')) == NULL)
- {
- /* zap the from line; it's invalid */
- *p = '\0';
- return;
- }
- strcpy(p, q+1);
- }
-
- if (p = index(from,'<'))
- {
- if ( (q=index(from,'>')) == NULL)
- {
- /* zap the from line; it's invalid */
- *p = '\0';
- return;
- }
- *q = '\0';
- strcpy(from, p+1);
- }
-
- p = from;
-
- /* drop trailing blanks */
- p = from + (strlen(from) - 1);
- while (p && *p && p >= from && isspace(*p))
- *p-- = '\0';
-
- /* 'outsider' indicates whether it's mail from a local user
- or not. 'subscribe' uses that to determine whether
- to acknowledge the existence of the list. (local users
- may subscribe to anything with a .info file; others
- may only subscribe if there is a .pub file)
- */
-
- if (index(from, '!') != NULL) /* uucp sites are foreign */
- {
- *outsider = 1;
- return;
- }
- if ((p = index(from, '@@')) == NULL) /* on-machine user */
- {
- *outsider = 0;
- return;
- }
-
- if (strcasecmp(p+1, DOMAIN) == 0)
- {
- *outsider = 0;
- return;
- }
- if ((p = index(p, '.')) == NULL) /* in-domain user */
- {
- *outsider = 0;
- return;
- }
- if (strncasecmp(p+1, DOMAIN,8) == 0)
- {
- *outsider = 0;
- return;
- }
-
- *outsider = 1;
- return;
- }
-
- @
-
-
- 1.9.1.1
- log
- @Changed source code to compiler under SAS/C 6.50.
- @
- text
- @a1 1
- #include "protos.h"
- d3 1
- a3 1
- static char rcsid[] = "$Id$";
- d5 2
- a6 1
- FILE *mailer, *logfile;
- d8 1
- a8 1
- int main(argc,argv)
- d226 1
- a226 1
- void callmailer(redirect, toaddr, request)
- d234 1
- a234 1
- strcat(cbuf, " -f ");
- d236 2
- a237 1
- strcat(cbuf, " -R \"Mailing List Processor\"");
- d246 3
- d254 1
- a254 1
- void mailcat(mfname,prefix)
- d281 1
- a281 1
- void cleanup(from, outsider)
- @
-
-
- 1.9.1.2
- log
- @callmailer() now uses the redirect parameter as username.
- @
- text
- @d4 1
- a4 1
- static char rcsid[] = "$Id: main.c,v 1.9.1.1 1993/12/26 00:42:01 simons Exp simons $";
- d235 1
- a235 1
- strcat(cbuf, (redirect) ? redirect : LISTSERVMANAGER);
- d237 1
- @
-
-
- 1.9.1.3
- log
- @Test for contents of >redirect< was wrong: In case we have to use the
- default, we get an empty string (""), not NULL.
- @
- text
- @d235 1
- a235 1
- strcat(cbuf, (*redirect) ? redirect : LISTSERVMANAGER);
- @
-
-
- 1.9.1.4
- log
- @Added a short startup-message, containing the name of the program.
- @
- text
- @d4 1
- a4 1
- static char rcsid[] = "$Id: main.c,v 1.9.1.3 1993/12/26 00:53:53 simons Exp simons $";
- a22 2
-
- printf("ListSERV -- amiga version by Peter Simons <simons@@peti.GUN.de>\n");
- @
-
-
- 1.9.1.5
- log
- @Removed the complete local/non-local user determination, including
- all >outsider< parameters and the cleanup() routine.
- Changed UNIX-paths to conform with AmigaDOS.
- @
- text
- @d4 1
- a4 1
- static char rcsid[] = "$Id: main.c,v 1.9.1.4 1993/12/26 18:45:38 simons Exp simons $";
- d19 1
- d65 2
- d150 1
- a150 1
- subscription(from,buf,1);
- d160 1
- a160 1
- subscription(from,buf,0);
- d168 2
- a169 1
- sendindex(from,buf,!strcasecmp(buf,"longindex"));
- d176 1
- a176 1
- sendfaq(from, buf);
- d213 1
- a213 1
- listhelp(from, grp, buf);
- d275 83
- @
-
-
- 1.9.1.6
- log
- @Added filelocking mechanism.
- @
- text
- @d4 1
- a4 1
- static char rcsid[] = "$Id: main.c,v 1.9.1.5 1993/12/26 19:35:55 simons Exp simons $";
- a103 1
- LockFile(LOGFILE);
- a124 1
- UnLockFile(LOGFILE);
- a254 1
- LockFile(mfname);
- a257 1
- UnLockFile(mfname);
- a270 1
- UnLockFile(mfname);
- @
-
-
- 1.9.1.7
- log
- @Removed the 'INFO'-command--for the moment.
- @
- text
- @d4 1
- a4 1
- static char rcsid[] = "$Id: main.c,v 1.9.1.6 1993/12/26 21:22:27 simons Exp simons $";
- d185 15
- a199 16
- /* if (!strcasecmp(buf, "info"))
- * {
- * gotcommand++;
- * infoindex(from, buf);
- * continue;
- *
- * }
- *
- * if (!strncasecmp(buf, "info ", 5)
- * || !strncasecmp(buf, "get ",4))
- * {
- * gotcommand++;
- * sendinfo(from, buf);
- * continue;
- * }
- */
- @
-
-
- 1.9.1.8
- log
- @Changed the default user that is used in From-line to 'listserv' instead
- of postmaster, so people can simply reply to the mails they get.
- Added support for C='s bumprev.
- Added AmigaDOS version string and changes startupmessage.
- @
- text
- @a2 1
- #include "ListSERV_rev.h"
- d4 1
- a4 1
- #define STARTUP "Amiga " VERS " -- written by by Peter Simons <simons@@peti.GUN.de>\n"
- a5 3
- static char rcssid[] = "$Id: main.c,v 1.9.1.7 1993/12/27 17:24:01 simons Exp simons $";
- static char dosid[] = VERSTAG;
-
- d23 1
- a23 1
- printf(STARTUP);
- d236 1
- a236 1
- strcat(cbuf, (*redirect) ? redirect : LISTSERVADDR);
- a246 1
- fprintf(mailer,"X-ListSERV: Amiga " VERS " (" DATE ")\n");
- @
-
-
- 1.9.1.9
- log
- @Changed callmail(): The from-line will now always contain the address of
- the listserver. The redirect parameter is unused now.
- @
- text
- @d7 1
- a7 1
- static char rcssid[] = "$Id: main.c,v 1.9.1.8 1993/12/28 00:18:12 simons Exp simons $";
- d239 3
- a241 2
- strcat(cbuf, " -f " LISTSERVADDR " -R \"Mailing List Processor\"");
-
- @
-
-
- 1.9.1.10
- log
- @Changed callmailer(): Former redirect parameter is now called carboncopy
- and contains the address of one or more additional receipients.
- @
- text
- @d7 1
- a7 1
- static char rcssid[] = "$Id: main.c,v 1.9.1.9 1993/12/28 17:00:52 simons Exp simons $";
- d231 2
- a232 2
- void callmailer(carboncopy, toaddr, request)
- char *carboncopy, *toaddr, *request;
- d236 1
- a236 1
- printf("callmailer \"%s\",\"%s\",\"%s\"\n", carboncopy, toaddr, request);
- d240 1
- a240 4
- if (carboncopy && *carboncopy) {
- strcat(cbuf, " -c ");
- strcat(cbuf, carboncopy);
- }
- @
-
-
- 1.9.1.11
- log
- @Changed X-ListSERV: field in the mailheaders to "Peti's Amiga ListSERV".
- @
- text
- @d7 1
- a7 1
- static char rcssid[] = "$Id: main.c,v 1.9.1.10 1993/12/28 17:37:42 simons Exp simons $";
- d253 1
- a253 1
- fprintf(mailer,"X-ListSERV: Peti's Amiga " VERS " (" DATE ")\n");
- @
-
-
- 1.9.1.12
- log
- @Changed function declarations to ANSI-compliant style.
- Added automatic stack allocation when the provided stack is < 5k.
- @
- text
- @d7 1
- a7 1
- static char rcssid[] = "$Id: main.c,v 1.9.1.11 1993/12/28 21:57:37 simons Exp simons $";
- d12 4
- a15 7
- long __stack = 1024*5; /* In case the stack is too small, allocate a
- * new one. (SAS/C 6.3+)
- */
-
- int main(int argc,
- char **argv)
- {
- d231 3
- a233 4
- void callmailer(char *carboncopy,
- char *toaddr,
- char *request)
- {
- d257 3
- a259 3
- void mailcat(char *mfname,
- char *prefix)
- {
- @
-
-
- 1.9.1.13
- log
- @Removed the strange internal string compare routines.
- @
- text
- @d7 1
- a7 1
- static char rcssid[] = "$Id: main.c,v 1.9.1.12 1993/12/28 22:16:34 simons Exp simons $";
- d68 1
- a68 1
- if (strnicmp(buf,"From: ",6) == 0)
- d73 2
- a74 2
- if (strnicmp(buf, "From: listserv", 14) == 0
- || strnicmp(buf,
- d88 1
- a88 1
- if (!strnicmp(from, "listserv", 8))
- d135 10
- a144 10
- if (!strnicmp(buf, "list ",5)
- || !strnicmp(buf, "delete-all ",11)
- || !strnicmp(buf, "del-all ",8)
- || !strnicmp(buf, "unsubscribe-all ",16)
- || !strnicmp(buf, "unsub-all ",10)
- || !stricmp(buf, "list")
- || !stricmp(buf, "delete-all")
- || !stricmp(buf, "del-all")
- || !stricmp(buf, "unsubscribe-all")
- || !stricmp(buf, "unsub-all"))
- d151 3
- a153 3
- if (!strnicmp(buf,"add ", 4)
- || !strnicmp(buf,"subscribe ", 10)
- || !strnicmp(buf,"sub ",4))
- d160 4
- a163 4
- if (!strnicmp(buf,"delete ", 7)
- || !strnicmp(buf,"del ",4)
- || !strnicmp(buf,"unsubscribe ", 12)
- || !strnicmp(buf,"unsub ",6))
- d170 2
- a171 2
- if (!stricmp(buf,"index")
- || !stricmp(buf,"longindex"))
- d174 1
- a174 1
- sendindex(from,buf,!stricmp(buf,"longindex"));
- d178 1
- a178 1
- if (!strnicmp(buf, "faq ", 4))
- d185 1
- a185 1
- if (!stricmp(buf, "faq"))
- d192 1
- a192 1
- /* if (!stricmp(buf, "info"))
- d200 2
- a201 2
- * if (!strnicmp(buf, "info ", 5)
- * || !strnicmp(buf, "get ",4))
- d208 1
- a208 1
- if (!stricmp(buf,"help"))
- d215 1
- a215 1
- if (!strnicmp(buf,"help ",5))
- @
-
-
- 1.9.1.14
- log
- @Invented real address parsing with ParseAddress(), taken from my
- PGPSendMail.
- Changed a few comments, straightened some code.
- Removed lots of strange and useless header-parsing stuff. I really
- wonder why the original author converted all characters to lower-case
- and compared them with an case-independant routine afterwards...
- However, all this stuff is gone.
- Changed the Subject:-line to "ListSERV". Names are very important! :-)
- @
- text
- @d7 1
- a7 1
- static char rcssid[] = "$Id: main.c,v 1.9.1.13 1993/12/29 06:24:47 simons Exp simons $";
- d42 12
- a59 1
-
- d61 1
- a61 7
- * get the From: line so we can return the answer
- *
- * Note that we DON'T check that we're in the header when
- * picking up the From: line; that's so that we'll take the
- * last from line we encounter which makes it handle
- * forwarded messages correctly.
- */
- d63 7
- a69 1
- if (!strnicmp(buf,"From: ",6)) {
- a70 1
- ParseAddress(from);
- d72 8
- a79 1
- }
- d81 3
- a83 1
- /* don't look for commands in the header */
- d95 1
- a95 1
- if (strstr(from, "daemon"))
- d101 1
- a101 1
- /* force to lower case and scan for commands
- a108 1
- */
- d192 16
- d234 3
- a236 1
- void callmailer(char *carboncopy, char *toaddr, char *request)
- d256 1
- a256 1
- fprintf(mailer,"Subject: Re: your ListSERV request \"%s\"\n", request);
- d259 1
- a259 1
- }
- d261 2
- a262 1
- void mailcat(char *mfname, char *prefix)
- a288 28
- }
-
-
- void ParseAddress(char *line)
- {
- int brackets, i, z;
-
- for (i = 0, z = 0, brackets = 0; line[i] != '\0'; i++) {
- if (line[i] == '(' && (i == 0 || isspace(line[i-1])))
- brackets = 1;
- if (line[i] == ')' && (line[i+1] == '\0' || isspace(line[i+1])))
- brackets = 0;
- if (line[i] == '<' && brackets == 0) {
- i++;
- while (1) { /* Forever! */
- if (line[i] == '>' && (line[i+1] == '\0' || isspace(line[i+1])))
- break;
- line[z++] = line[i++];
- }
- line[z] = '\0';
- break;
- }
- }
- if (z == 0) { /* No <address> occured. */
- i = 0;
- while (!isspace(line[i]))
- i++;
- line[i] = '\0';
- a289 1
- }
- @
-
-
- 1.9.1.15
- log
- @Changed the username that is used to recognize bounced mail to
- "-daemon" to avoid confusion in case someone likes strange names. :-)
- The X-ListSERV:-field now doesn't contain the date of the current
- version anymore, will save some bandwidth--the number is sufficient.
- Added a usage text when started with "?" or "-h".
- @
- text
- @a5 1
- #define USAGE "USAGE: ListSERV <mailfile\n"
- d7 1
- a7 1
- static char rcssid[] = "$Id: main.c,v 1.9.1.14 1993/12/29 07:07:06 simons Exp simons $";
- d16 2
- a17 1
- int main(int argc, char **argv)
- d23 1
- a30 5
- if (argc == 2 && (!strcmp(argv[1], "?") ||
- !stricmp(argv[1], "-h"))) {
- printf(USAGE);
- return 0;
- }
- d76 1
- a76 1
- if (strstr(from, "-daemon"))
- d221 1
- a221 1
- fprintf(mailer,"X-ListSERV: Peti's Amiga " VERS "\n");
- @
-