home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Filename: subscribe.c $
- * $Revision: 2.4 $
- * $Date: 1994/01/17 16:02:18 $
- *
- * Copyright (C) 1993 by Peter Simons <simons@peti.GUN.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id: subscribe.c,v 2.4 1994/01/17 16:02:18 simons Exp simons $
- *
- */
-
-
- /************************************* includes ***********/
- #include "listserv.h"
- #include "protos.h"
-
- /************************************* global variables ***/
- static char rcsid[] = "$Id: subscribe.c,v 2.4 1994/01/17 16:02:18 simons Exp simons $";
-
- /************************************* program ************/
- int subscription(char *from, char *command, int add)
- {
- FILE *list;
- FILE *listtmp;
- char grp[256], adr[256], tmp[256], tmp2[256], buf[BUFSIZ];
- int del = 0, found = 0, i;
-
- printf("subscription %s %s %d\n", from, command, add);
-
- i = sscanf(command,"%s%s%s", tmp, adr, grp);
- if ((i <= 1 && !def_listname) || i > 3) {
- sendhelp(from, command);
- return -1;
- }
- else if (i == 2)
- if (def_listname && (stristr(adr, "!") || stristr(adr, "@")))
- strcpy(grp, def_listname);
- else {
- strcpy(grp, adr);
- strcpy(adr, from);
- }
- else if (i == 1) {
- strcpy(grp, def_listname);
- strcpy(adr, from);
- }
-
- if (!stricmp(grp, adr))
- {
- callmailer(LISTSERVMANAGER, from, command);
- fprintf(mailer,"Subscription address loop: %s\n", adr);
- pclose(mailer);
- return(-1);
- }
-
- sprintf(tmp,"%s%s/List", LISTDIR, grp);
- LockFile(tmp);
- if (access(tmp,R_OK))
- {
- UnLockFile(tmp);
- callmailer("", from, command);
- fprintf(mailer,"The mailing list \"%s\" could not be found.\n",
- grp);
- fprintf(mailer,"You may use the INDEX command to get a listing\n");
- fprintf(mailer,"of available mailing lists.\n");
- pclose(mailer);
- return(-1);
- }
-
- if (add)
- {
- if (!(list = fopen(tmp, "r+")))
- {
- UnLockFile(tmp);
- callmailer(LISTSERVMANAGER, from, command);
- fprintf(mailer, FATALERROR_MSG, 1);
- pclose(mailer);
- return(-1);
- }
-
- /* check if address is already subscribed */
- while (fgets(buf, sizeof(buf), list)) {
- buf[strlen(buf)-1] = '\0';
- if (!stricmp(buf, adr))
- found++;
- }
- if (!found)
- if (fseek(list, 0L, SEEK_END) != -1)
- fprintf(list, "%s\n", adr);
- fclose(list);
- UnLockFile(tmp);
- }
- else
- {
- del = 0;
- if (!(list = fopen(tmp, "r")))
- {
- UnLockFile(tmp);
- callmailer(LISTSERVMANAGER, from, command);
- fprintf(mailer, FATALERROR_MSG, 2);
- pclose(mailer);
- return(-1);
- }
-
- sprintf(tmp2, "%s.tmp", tmp);
- LockFile(tmp2);
- if (!(listtmp = fopen(tmp2, "w")))
- {
- callmailer(LISTSERVMANAGER, from, command);
- fprintf(mailer, FATALERROR_MSG, 3);
- pclose(mailer);
- return(-1);
- }
- /* copy the list, omitting the one address */
- while (fgets(buf, sizeof(buf), list))
- {
- buf[strlen(buf)-1] = '\0';
- if (stricmp(buf, adr))
- {
- fputs(buf, listtmp);
- fputs("\n", listtmp);
- }
- else
- del++;
- }
- fclose(listtmp);
- fclose(list);
- /* replace the old list with the shortened one */
-
- remove(tmp); /* delete original file */
- rename(tmp2, tmp); /* put updated one in place */
- UnLockFile(tmp);
- UnLockFile(tmp2);
- }
-
-
- /* Mail subscription confirmation and introduction files.*/
-
- sprintf(tmp, "%s-Admin", grp);
- if (stricmp(from, adr)) {
- callmailer(tmp, adr, command);
- fprintf(mailer, "Per request by %s\n", from);
- }
- else {
- callmailer(tmp, from, command);
- fprintf(mailer,"Per your request\n");
- }
-
- fprintf(mailer,"\t\"%s\"\n", command);
-
- if (add)
- if (!found) {
- fprintf(mailer,"'%s' was ADDED to the '%s' mailing list.\n", adr, grp);
-
- sprintf(buf, "%s%s/Introduction", LISTDIR, grp);
- LockFile(buf);
- if (!access(buf,R_OK)) {
- UnLockFile(buf);
- fprintf(mailer, "\n\n------------------------ List introduction ---------------------------\n");
- mailcat(buf, "");
- fprintf(mailer, "----------------------------------------------------------------------\n");
- }
- else
- UnLockFile(buf);
- }
- else
- fprintf(mailer,"'%s' is already subscribed to the '%s' mailing list.\n", adr, grp);
- else
- if (del) {
- fprintf(mailer, "'%s' was DELETED from the '%s' mailing list.\n\n", adr, grp);
- fprintf(mailer, DELETED_MSG);
- }
- else
- fprintf(mailer, "'%s' was NOT FOUND on the '%s' mailing list.\n", adr, grp);
-
- pclose(mailer);
- }
-