home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / MULTMAIL.C < prev    next >
Text File  |  1991-12-26  |  8KB  |  377 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1991 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15.  
  16.  
  17. #include "vars.h"
  18.  
  19. #pragma hdrstop
  20.  
  21. #include <dir.h>
  22.  
  23.  
  24.  
  25. #define ALLOW_FULLSCREEN 1
  26. #define EMAIL_STORAGE 2
  27.  
  28.  
  29. void multimail(int *un, int numu)
  30. {
  31.   int i,i1,f,len,an,cv,ok;
  32.   mailrec m,m1;
  33.   char s[81],s1[81],t[81];
  34.   userrec ur;
  35.   slrec ss;
  36.  
  37.   if (freek1(syscfg.msgsdir)<10.0) {
  38.     nl();
  39.     pl("Sorry, not enough disk space left.");
  40.     nl();
  41.     return;
  42.   }
  43.   nl();
  44.   sprintf(s,"%sEMAIL.DAT",syscfg.datadir);
  45.   ss=syscfg.sl[actsl];
  46.  
  47.   if (ss.ability & ability_email_anony)
  48.     i=anony_enable_anony;
  49.   else
  50.     i=0;
  51.   m.msg.storage_type=EMAIL_STORAGE;
  52.   strcpy(irt,"1Multi-Mail");
  53.   irt_name[0]=0;
  54.   inmsg(&m.msg,t,&i,1,"EMAIL",ALLOW_FULLSCREEN);
  55.   if (m.msg.stored_as==0xffffffff)
  56.     return;
  57.   strcpy(m.title,t);
  58.   m.anony=i;
  59.   m.fromsys=0;
  60.   m.fromuser=usernum;
  61.   m.tosys=0;
  62.   m.touser=0;
  63.   m.status=status_multimail;
  64.   time((long *)&(m.daten));
  65.   f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  66.   len=(int) filelength(f)/sizeof(mailrec);
  67.   if (len==0)
  68.     i=0;
  69.   else {
  70.     i=len-1;
  71.     lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
  72.     read(f,(void *)&m1,sizeof(mailrec));
  73.     while ((i>0) && (m1.tosys==0) && (m1.touser==0)) {
  74.       --i;
  75.       lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
  76.       i1=read(f,(void *)&m1,sizeof(mailrec));
  77.       if (i1==-1)
  78.         pl("DIDN'T READ RIGHT.");
  79.     }
  80.     if ((m1.tosys) || (m1.touser))
  81.       ++i;
  82.   }
  83.   lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
  84.   pl("1Mail sent to7:");
  85.   sysoplog("1Multi-Mail to7:");
  86.  
  87.   for (cv=0; cv<numu; cv++) {
  88.     read_user(un[cv],&ur);
  89.     ok=1;
  90.     if (((ur.sl==255) && (ur.waiting>(syscfg.maxwaiting * 5))) ||
  91.         ((ur.sl!=255) && (ur.waiting>syscfg.maxwaiting)) ||
  92.         (ur.waiting>200)) {
  93.       npr("%s  mailbox full, not sent.\r\n",nam(&ur,un[cv]));
  94.       ok=0;
  95.     }
  96.     if (ur.inact & inact_deleted) {
  97.       npr("User #%d deleted, not sent.\r\n",un[cv]);
  98.       ok=0;
  99.     }
  100.  
  101.     if (ok) {
  102.       m.touser=un[cv];
  103.       write(f,(void *)&m,sizeof(mailrec));
  104.       strcpy(s,"   ");
  105.       ++ur.waiting;
  106.       write_user(un[cv],&ur);
  107.       if (un[cv]==1)
  108.         ++fwaiting;
  109.       strcat(s,nam(&ur,un[cv]));
  110.       if (un[cv]==1)  {
  111.         ++status.fbacktoday;
  112.         ++thisuser.feedbacksent;
  113.     ++thisuser.fsenttoday1;
  114.     ++fsenttoday;
  115.       } else {
  116.         ++status.emailtoday;
  117.         ++thisuser.etoday;
  118.         ++thisuser.emailsent;
  119.       }
  120.       sysoplog(s);
  121.       pl(s);
  122.     }
  123.   }
  124.   close_user();
  125.   close(f);
  126.   save_status();
  127.   if (!wfc)
  128.     topscreen();
  129. }
  130.  
  131.  
  132. char *mml_s;
  133. int mml_started;
  134.  
  135.  
  136. int oneuser()
  137. {
  138.   char s[81],*ss;
  139.   unsigned short un,sn,i;
  140.   userrec u;
  141.  
  142.   if (mml_s) {
  143.     if (mml_started)
  144.       ss=strtok(NULL,"\r\n");
  145.     else
  146.       ss=strtok(mml_s,"\r\n");
  147.     mml_started=1;
  148.     if (ss==NULL) {
  149.       farfree(mml_s);
  150.       mml_s=NULL;
  151.       return(-1);
  152.     }
  153.     strcpy(s,ss);
  154.     for (i=0; s[i]!=0; i++)
  155.       s[i]=upcase(s[i]);
  156.   } else {
  157.     prt(2,">");
  158.     input(s,40);
  159.   }
  160.   un=finduser(s);
  161.   if (un==65535)
  162.     return(-1);
  163.   if (s[0]==0)
  164.     return(-1);
  165.   if (un<=0) {
  166.     nl();
  167.     pl("3Don't know 'em.");
  168.     nl();
  169.     return(0);
  170.   }
  171.   sn=0;
  172.   if (forwardm(&un,&sn)) {
  173.     nl();
  174.     pl("Forwarded.");
  175.     nl();
  176.     if (sn) {
  177.       pl("Forwarded to another system.");
  178.       pl("Can't send multi-mail to another system.");
  179.       nl();
  180.       return(0);
  181.     }
  182.   }
  183.   if (un==0) {
  184.     nl();
  185.     pl("3Don't know em.");
  186.     nl();
  187.     return(0);
  188.   }
  189.   read_user(un,&u);
  190.   if (((u.sl==255) && (u.waiting>(syscfg.maxwaiting * 5))) ||
  191.       ((u.sl!=255) && (u.waiting>syscfg.maxwaiting)) ||
  192.       (u.waiting>200)) {
  193.     nl();
  194.     pl("Mailbox full.");
  195.     nl();
  196.     return(0);
  197.   }
  198.   if (u.inact & inact_deleted) {
  199.     nl();
  200.     pl("Deleted user.");
  201.     nl();
  202.     return(0);
  203.   }
  204.   sprintf(s,"     -> %s",nam(&u,un));
  205.   pl(s);
  206.   return(un);
  207. }
  208.  
  209.  
  210. void add_list(int *un, int *numu, int maxu, int allowdup)
  211. {
  212.   int i,i1,i2,done, mml;
  213.  
  214.   done=0;
  215.   mml=(mml_s!=NULL);
  216.   mml_started=0;
  217.   while ((!done) && (!hangup) && (*numu<maxu)) {
  218.     i=oneuser();
  219.     if (mml && (!mml_s))
  220.       done=1;
  221.     if (i==-1)
  222.       done=1;
  223.     else
  224.       if (i) {
  225.         if (!allowdup)
  226.           for (i1=0; i1<*numu; i1++)
  227.             if (un[i1]==i) {
  228.               nl();
  229.               pl("Already in list, not added.");
  230.               nl();
  231.               i=0;
  232.             }
  233.         if (i)
  234.           un[(*numu)++]=i;
  235.       }
  236.   }
  237.   if (*numu==maxu) {
  238.     nl();
  239.     pl("6List full.");
  240.     nl();
  241.   }
  242. }
  243.  
  244.  
  245. #define MAX_LIST 40
  246.  
  247.  
  248. void slash_e()
  249. {
  250.   int un[MAX_LIST],numu,done,i,i1,f1;
  251.   char s[81],s1[81],ch,*sss;
  252.   slrec ss;
  253.   userrec u;
  254.   struct ffblk ff;
  255.  
  256.   mml_s=NULL;
  257.   mml_started=0;
  258.   ss=syscfg.sl[actsl];
  259.   if (freek1(syscfg.msgsdir)<10.0) {
  260.     nl();
  261.     pl("Sorry, not enough disk space left.");
  262.     nl();
  263.     return;
  264.   }
  265.   if (((fsenttoday>=5) || (thisuser.fsenttoday1>=10) ||
  266.     (thisuser.etoday>=ss.emails)) && (!cs())) {
  267.     pl("Too much mail sent today.");
  268.     return;
  269.   }
  270.   if (restrict_email & thisuser.restrict) {
  271.     pl("You can't send mail.");
  272.     return;
  273.   }
  274.   done=0;
  275.   numu=0;
  276.   do {
  277.     nl();
  278.     nl();
  279.     prt(1,"Multi-Mail3:5 A1,5M1,5D1,5L1,5E1,5Q1,3?7 : ");
  280.     ch=onek("QAMDEL?");
  281.     switch(ch) {
  282.       case '?':
  283.         printmenu(12);
  284.         break;
  285.       case 'Q':
  286.         done=1;
  287.         break;
  288.       case 'A':
  289.         nl();
  290.     pl("1Enter names/numbers for users, one per line, max 20.");
  291.     nl();
  292.     helpl=5;
  293.     mml_s=NULL;
  294.     add_list(un,&numu,MAX_LIST,so());
  295.     break;
  296.       case 'M':
  297.         sprintf(s,"%s*.MML",syscfg.datadir);
  298.         f1=findfirst(s,&ff,0);
  299.         if (f1) {
  300.           nl();
  301.       pl("3No mailing lists available.");
  302.       nl();
  303.       break;
  304.     }
  305.     nl();
  306.     pl("7Available mailing lists:");
  307.     nl();
  308.         while (f1==0) {
  309.           strcpy(s,ff.ff_name);
  310.           sss=strchr(s,'.');
  311.           if (sss)
  312.             *sss=0;
  313.           pl(s);
  314.  
  315.           f1=findnext(&ff);
  316.         }
  317.  
  318.         nl();
  319.     prt(2,"1Which? ");
  320.     input(s,8);
  321.  
  322.         sprintf(s1,"%s%s.MML",syscfg.datadir,s);
  323.         i=open(s1,O_RDONLY | O_BINARY);
  324.         if (i<0) {
  325.           nl();
  326.       pl("3Unknown mailing list.");
  327.       nl();
  328.     } else {
  329.       i1=filelength(i);
  330.       mml_s=malloca(i1+10L);
  331.       read(i,mml_s,i1);
  332.       mml_s[i1]='\n';
  333.       mml_s[i1+1]=0;
  334.       close(i);
  335.       mml_started=0;
  336.       add_list(un,&numu,MAX_LIST,so());
  337.       if (mml_s) {
  338.         farfree(mml_s);
  339.         mml_s=NULL;
  340.       }
  341.     }
  342.     break;
  343.       case 'E':
  344.         if (!numu) {
  345.           nl();
  346.           pl("Need to specify some users first - use A or M");
  347.           nl();
  348.         } else {
  349.           multimail(un,numu);
  350.           done=1;
  351.         }
  352.         break;
  353.       case 'D':
  354.         if (numu) {
  355.           nl();
  356.           prt(2,"Delete which? ");
  357.           input(s,2);
  358.           i=atoi(s);
  359.           if ((i>0) && (i<=numu)) {
  360.             --numu;
  361.             for (i1=i-1; i1<numu; i1++)
  362.               un[i1]=un[i1+1];
  363.           }
  364.         }
  365.         break;
  366.       case 'L':
  367.         for (i=0; i<numu; i++) {
  368.           read_user(un[i],&u);
  369.           npr("%d. %s\r\n",i+1,nam(&u,un[i]));
  370.         }
  371.         break;
  372.     }
  373.   } while ((!done) && (!hangup));
  374. }
  375.  
  376.  
  377.