home *** CD-ROM | disk | FTP | other *** search
- #include "listserv.h"
- #include "protos.h"
-
- static char rcsid[] = "$Id: subscribe.c,v 1.4.1.10 1993/12/29 06:56:57 simons Exp simons $";
-
- 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;
- int i;
-
- printf("subscription %s %s %d\n", from, command, add);
-
- i = sscanf(command,"%s%s%s", tmp, adr, grp);
- if (i < 2 || i > 3)
- sendhelp(from, command);
- if (i == 2)
- {
- strcpy(grp, adr);
- strcpy(adr, from);
- }
-
- if (!stricmp(grp, adr))
- {
- callmailer(LISTSERVMANAGER, from, "");
- fprintf(mailer,"Subscription address loop: %s\n", adr);
- fflush(mailer);
- pclose(mailer);
- return(-1);
- }
-
- sprintf(tmp,"%s%s/List", LISTDIR, grp);
- LockFile(tmp);
- if (access(tmp,R_OK))
- {
- UnLockFile(tmp);
- callmailer("", from, "");
- 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");
- fflush(mailer);
- pclose(mailer);
- return(-1);
- }
-
- if (add)
- {
- if (!(list = fopen(tmp, "a")))
- {
- UnLockFile(tmp);
- callmailer(LISTSERVMANAGER, from, "");
- fprintf(mailer,"Error[1] processing request. Please try later.\n");
- fprintf(mailer,">%s\n", command);
- fflush(mailer);
- pclose(mailer);
- return(-1);
- }
- fprintf(list, "%s\n", adr);
- fclose(list);
- UnLockFile(tmp);
- }
- else
- {
- del = 0;
- if (!(list = fopen(tmp, "r")))
- {
- UnLockFile(tmp);
- callmailer(LISTSERVMANAGER, from, "");
- fprintf(mailer,"Error[2] processing request. Please try later.\n");
- fprintf(mailer,">%s\n", command);
- fflush(mailer);
- pclose(mailer);
- return(-1);
- }
-
- sprintf(tmp2, "%s.tmp", tmp);
- LockFile(tmp2);
- if (!(listtmp = fopen(tmp2, "w")))
- {
- callmailer(LISTSERVMANAGER, from, "");
- fprintf(mailer,"Error[3] processing request. Please try later.\n");
- fprintf(mailer,">%s\n", command);
- fflush(mailer);
- 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.*/
-
- if (stricmp(from, adr))
- {
- callmailer(LISTSERVMANAGER, adr, command);
- fprintf(mailer, "Per request by %s\n", from);
- }
- else
- {
- callmailer(LISTSERVMANAGER, from, command);
- fprintf(mailer,"Per your request\n");
- }
-
- fprintf(mailer,"\t\"%s\"\n", command);
-
- if (add)
- {
- fprintf(mailer,"'%s' was ADDED to the '%s' mailing list.\n",
- adr, grp);
- fflush(mailer);
- pclose(mailer);
-
- /* mail introduction file --TODO
- */
-
- }
-
- else
- if (del)
- {
- fprintf(mailer,
- "'%s' was DELETED from the '%s' mailing list.\n",
- adr, grp);
- fprintf(mailer,
- "\nAlthough you have been deleted from the list,");
- fprintf(mailer,
- " some mail sent previous to your deletion may be\n");
- fprintf(mailer,
- "queued in the system. Please don't panic if you");
- fprintf(mailer,
- " receive a few last pieces of mail.\n");
- fflush(mailer);
- pclose(mailer);
- }
- else
- {
- fprintf(mailer,
- "'%s' was NOT FOUND on the '%s' mailing list.\n",
- adr, grp);
- fflush(mailer);
- pclose(mailer);
- }
-
- }
-