home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / ListSERV1_4.lha / ListSERV / source / subscribe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-29  |  5.8 KB  |  169 lines

  1. #include "listserv.h"
  2. #include "protos.h"
  3.  
  4. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.10 1993/12/29 06:56:57 simons Exp simons $";
  5.  
  6. int subscription(char *from,
  7.                  char *command,
  8.                  int add)
  9. {
  10.         FILE *list;
  11.         FILE *listtmp;
  12.         char grp[256], adr[256], tmp[256], tmp2[256], buf[BUFSIZ];
  13.         int del = 0;
  14.         int i;
  15.  
  16.         printf("subscription %s %s %d\n", from, command, add);
  17.  
  18.         i = sscanf(command,"%s%s%s", tmp, adr, grp);
  19.         if (i < 2 || i > 3)
  20.                 sendhelp(from, command);
  21.         if (i == 2)
  22.                 {
  23.                 strcpy(grp, adr);
  24.                 strcpy(adr, from);
  25.                 }
  26.  
  27.         if (!stricmp(grp, adr))
  28.                 {
  29.                 callmailer(LISTSERVMANAGER, from, "");
  30.                 fprintf(mailer,"Subscription address loop: %s\n", adr);
  31.                 fflush(mailer);
  32.                 pclose(mailer);
  33.                 return(-1);
  34.                 }
  35.  
  36.         sprintf(tmp,"%s%s/List", LISTDIR, grp);
  37.         LockFile(tmp);
  38.         if (access(tmp,R_OK))
  39.                 {
  40.                 UnLockFile(tmp);
  41.                 callmailer("", from, "");
  42.                 fprintf(mailer,"The mailing list \"%s\" could not be found.\n",
  43.                         grp);
  44.                 fprintf(mailer,"You may use the INDEX command to get a listing\n");
  45.                 fprintf(mailer,"of available mailing lists.\n");
  46.                 fflush(mailer);
  47.                 pclose(mailer);
  48.                 return(-1);
  49.                 }
  50.  
  51.         if (add)
  52.                 {
  53.                 if (!(list = fopen(tmp, "a")))
  54.                         {
  55.                         UnLockFile(tmp);
  56.                         callmailer(LISTSERVMANAGER, from, "");
  57.                         fprintf(mailer,"Error[1] processing request. Please try later.\n");
  58.                         fprintf(mailer,">%s\n", command);
  59.                         fflush(mailer);
  60.                         pclose(mailer);
  61.                         return(-1);
  62.                         }
  63.                 fprintf(list, "%s\n", adr);
  64.                 fclose(list);
  65.                 UnLockFile(tmp);
  66.                 }
  67.         else
  68.                 {
  69.                 del = 0;
  70.                 if (!(list = fopen(tmp, "r")))
  71.                         {
  72.                         UnLockFile(tmp);
  73.                         callmailer(LISTSERVMANAGER, from, "");
  74.                         fprintf(mailer,"Error[2] processing request. Please try later.\n");
  75.                         fprintf(mailer,">%s\n", command);
  76.                         fflush(mailer);
  77.                         pclose(mailer);
  78.                         return(-1);
  79.                         }
  80.  
  81.                 sprintf(tmp2, "%s.tmp", tmp);
  82.                 LockFile(tmp2);
  83.                 if (!(listtmp = fopen(tmp2, "w")))
  84.                         {
  85.                         callmailer(LISTSERVMANAGER, from, "");
  86.                         fprintf(mailer,"Error[3] processing request. Please try later.\n");
  87.                         fprintf(mailer,">%s\n", command);
  88.                         fflush(mailer);
  89.                         pclose(mailer);
  90.                         return(-1);
  91.                         }
  92.                 /* copy the list, omitting the one address */
  93.                 while (fgets(buf, sizeof(buf), list))
  94.                         {
  95.                         buf[strlen(buf)-1] = '\0';
  96.                         if (stricmp(buf, adr))
  97.                                 {
  98.                                 fputs(buf, listtmp);
  99.                                 fputs("\n", listtmp);
  100.                                 }
  101.                         else
  102.                                 del++;
  103.                         }
  104.                 fclose(listtmp);
  105.                 fclose(list);
  106.                 /* replace the old list with the shortened one */
  107.  
  108.                 remove(tmp);            /* delete original file */
  109.                 rename(tmp2, tmp);      /* put updated one in place */
  110.                 UnLockFile(tmp);
  111.                 UnLockFile(tmp2);
  112.                 }
  113.  
  114.  
  115.         /* Mail subscription confirmation and introduction files.*/
  116.  
  117.         if (stricmp(from, adr))
  118.                 {
  119.                 callmailer(LISTSERVMANAGER, adr, command);
  120.                 fprintf(mailer, "Per request by %s\n", from);
  121.                 }
  122.         else
  123.                 {
  124.                 callmailer(LISTSERVMANAGER, from, command);
  125.                 fprintf(mailer,"Per your request\n");
  126.                 }
  127.  
  128.                 fprintf(mailer,"\t\"%s\"\n", command);
  129.  
  130.         if (add)
  131.                 {
  132.                 fprintf(mailer,"'%s' was ADDED to the '%s' mailing list.\n",
  133.                         adr, grp);
  134.                 fflush(mailer);
  135.                 pclose(mailer);
  136.  
  137.                 /* mail introduction file       --TODO
  138.                  */
  139.  
  140.                 }
  141.  
  142.         else
  143.                 if (del)
  144.                         {
  145.                         fprintf(mailer,
  146.                         "'%s' was DELETED from the '%s' mailing list.\n",
  147.                                 adr, grp);
  148.                         fprintf(mailer,
  149.                         "\nAlthough you have been deleted from the list,");
  150.                         fprintf(mailer,
  151.                         " some mail sent previous to your deletion may be\n");
  152.                         fprintf(mailer,
  153.                         "queued in the system. Please don't panic if you");
  154.                         fprintf(mailer,
  155.                         " receive a few last pieces of mail.\n");
  156.                         fflush(mailer);
  157.                         pclose(mailer);
  158.                         }
  159.                 else
  160.                         {
  161.                         fprintf(mailer,
  162.                         "'%s' was NOT FOUND on the '%s' mailing list.\n",
  163.                                 adr, grp);
  164.                         fflush(mailer);
  165.                         pclose(mailer);
  166.                         }
  167.  
  168.         }
  169.