home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / MULTMAIL.C < prev    next >
C/C++ Source or Header  |  1995-08-25  |  8KB  |  379 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1993 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(get_string(332));
  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,get_string(333));
  53.   irt_name[0]=0;
  54.   unlink("quotes.txt");
  55.   inmsg(&m.msg,t,&i,1,"EMAIL",ALLOW_FULLSCREEN, get_string(333), 0);
  56.   if (m.msg.stored_as==0xffffffff)
  57.     return;
  58.   strcpy(m.title,t);
  59.   m.anony=i;
  60.   m.fromsys=0;
  61.   m.fromuser=usernum;
  62.   m.tosys=0;
  63.   m.touser=0;
  64.   m.status=status_multimail;
  65.   time((long *)&(m.daten));
  66.   f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  67.   len=(int) filelength(f)/sizeof(mailrec);
  68.   if (len==0)
  69.     i=0;
  70.   else {
  71.     i=len-1;
  72.     lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
  73.     read(f,(void *)&m1,sizeof(mailrec));
  74.     while ((i>0) && (m1.tosys==0) && (m1.touser==0)) {
  75.       --i;
  76.       lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
  77.       i1=read(f,(void *)&m1,sizeof(mailrec));
  78.       if (i1==-1)
  79.         pl("DIDN'T READ RIGHT.");
  80.     }
  81.     if ((m1.tosys) || (m1.touser))
  82.       ++i;
  83.   }
  84.   lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
  85.   pl(get_string(334));
  86.   sysoplog(get_stringx(1,20));
  87.  
  88.   for (cv=0; cv<numu; cv++) {
  89.     read_user(un[cv],&ur);
  90.     ok=1;
  91.     if (((ur.sl==255) && (ur.waiting>(syscfg.maxwaiting * 5))) ||
  92.         ((ur.sl!=255) && (ur.waiting>syscfg.maxwaiting)) ||
  93.         (ur.waiting>200)) {
  94.       outstr(nam(&ur,un[cv]));
  95.       outstr(get_string(335));
  96.       ok=0;
  97.     }
  98.     if (ur.inact & inact_deleted) {
  99.       pl(get_string(336));
  100.       ok=0;
  101.     }
  102.  
  103.     if (ok) {
  104.       m.touser=un[cv];
  105.       write(f,(void *)&m,sizeof(mailrec));
  106.       strcpy(s,"   ");
  107.       ++ur.waiting;
  108.       write_user(un[cv],&ur);
  109.       if (un[cv]==1)
  110.         ++fwaiting;
  111.       strcat(s,nam(&ur,un[cv]));
  112.       if (un[cv]==1)  {
  113.         ++status.fbacktoday;
  114.         ++thisuser.feedbacksent;
  115.     ++thisuser.fsenttoday1;
  116.     ++fsenttoday;
  117.       } else {
  118.         ++status.emailtoday;
  119.         ++thisuser.etoday;
  120.         ++thisuser.emailsent;
  121.       }
  122.       sysoplog(s);
  123.       pl(s);
  124.     }
  125.   }
  126.   close_user();
  127.   close(f);
  128.   save_status();
  129.   if (!wfc)
  130.     topscreen();
  131. }
  132.  
  133.  
  134. char *mml_s;
  135. int mml_started;
  136.  
  137.  
  138. int oneuser(void)
  139. {
  140.   char s[81],*ss;
  141.   unsigned short un,sn,i;
  142.   userrec u;
  143.  
  144.   if (mml_s) {
  145.     if (mml_started)
  146.       ss=strtok(NULL,"\r\n");
  147.     else
  148.       ss=strtok(mml_s,"\r\n");
  149.     mml_started=1;
  150.     if (ss==NULL) {
  151.       farfree(mml_s);
  152.       mml_s=NULL;
  153.       return(-1);
  154.     }
  155.     strcpy(s,ss);
  156.     for (i=0; s[i]!=0; i++)
  157.       s[i]=upcase(s[i]);
  158.   } else {
  159.     prt(2,">");
  160.     input(s,40);
  161.   }
  162.   un=finduser1(s);
  163.   if (un==65535)
  164.     return(-1);
  165.   if (s[0]==0)
  166.     return(-1);
  167.   if (un<=0) {
  168.     nl();
  169.     pl(get_string(8));
  170.     nl();
  171.     return(0);
  172.   }
  173.   sn=0;
  174.   if (forwardm(&un,&sn)) {
  175.     nl();
  176.     pl(get_string(337));
  177.     nl();
  178.     if (sn) {
  179.       pl(get_string(338));
  180.       pl(get_string(339));
  181.       nl();
  182.       return(0);
  183.     }
  184.   }
  185.   if (un==0) {
  186.     nl();
  187.     pl(get_string(8));
  188.     nl();
  189.     return(0);
  190.   }
  191.   read_user(un,&u);
  192.   if (((u.sl==255) && (u.waiting>(syscfg.maxwaiting * 5))) ||
  193.       ((u.sl!=255) && (u.waiting>syscfg.maxwaiting)) ||
  194.       (u.waiting>200)) {
  195.     nl();
  196.     pl(get_string(340));
  197.     nl();
  198.     return(0);
  199.   }
  200.   if (u.inact & inact_deleted) {
  201.     nl();
  202.     pl(get_string(341));
  203.     nl();
  204.     return(0);
  205.   }
  206.   sprintf(s,"     -> %s",nam(&u,un));
  207.   pl(s);
  208.   return(un);
  209. }
  210.  
  211.  
  212. void add_list(int *un, int *numu, int maxu, int allowdup)
  213. {
  214.   int i,i1,i2,done, mml;
  215.  
  216.   done=0;
  217.   mml=(mml_s!=NULL);
  218.   mml_started=0;
  219.   while ((!done) && (!hangup) && (*numu<maxu)) {
  220.     i=oneuser();
  221.     if (mml && (!mml_s))
  222.       done=1;
  223.     if (i==-1)
  224.       done=1;
  225.     else
  226.       if (i) {
  227.         if (!allowdup)
  228.           for (i1=0; i1<*numu; i1++)
  229.             if (un[i1]==i) {
  230.               nl();
  231.               pl(get_string(342));
  232.               nl();
  233.               i=0;
  234.             }
  235.         if (i)
  236.           un[(*numu)++]=i;
  237.       }
  238.   }
  239.   if (*numu==maxu) {
  240.     nl();
  241.     pl(get_string(343));
  242.     nl();
  243.   }
  244. }
  245.  
  246.  
  247. #define MAX_LIST 500
  248.  
  249.  
  250. void slash_e(void)
  251. {
  252.   int un[MAX_LIST],numu,done,i,i1,f1;
  253.   char s[81],s1[81],ch,*sss;
  254.   slrec ss;
  255.   userrec u;
  256.   struct ffblk ff;
  257.  
  258.   mml_s=NULL;
  259.   mml_started=0;
  260.   ss=syscfg.sl[actsl];
  261.   if (freek1(syscfg.msgsdir)<10.0) {
  262.     nl();
  263.     pl(get_string(332));
  264.     nl();
  265.     return;
  266.   }
  267.   if (((fsenttoday>=5) || (thisuser.fsenttoday1>=10) ||
  268.     (thisuser.etoday>=ss.emails)) && (!cs())) {
  269.     pl(get_string(344));
  270.     return;
  271.   }
  272.   if (restrict_email & thisuser.restrict) {
  273.     pl(get_string(345));
  274.     return;
  275.   }
  276.   done=0;
  277.   numu=0;
  278.   do {
  279.     nl();
  280.     nl();
  281.     prt(2,get_string(346));
  282.     ch=onek("QAMDEL?");
  283.     switch(ch) {
  284.       case '?':
  285.         printmenu(12);
  286.         break;
  287.       case 'Q':
  288.         done=1;
  289.         break;
  290.       case 'A':
  291.         nl();
  292.         pl(get_string(347));
  293.         nl();
  294.         helpl=5;
  295.         mml_s=NULL;
  296.         add_list(un,&numu,MAX_LIST,so());
  297.         break;
  298.       case 'M':
  299.         sprintf(s,"%s*.MML",syscfg.datadir);
  300.         f1=findfirst(s,&ff,0);
  301.         if (f1) {
  302.           nl();
  303.           pl(get_string(348));
  304.           nl();
  305.           break;
  306.         }
  307.         nl();
  308.         pl(get_string(349));
  309.         nl();
  310.         while (f1==0) {
  311.           strcpy(s,ff.ff_name);
  312.           sss=strchr(s,'.');
  313.           if (sss)
  314.             *sss=0;
  315.           pl(s);
  316.  
  317.           f1=findnext(&ff);
  318.         }
  319.  
  320.         nl();
  321.         prt(2,get_string(297));
  322.         input(s,8);
  323.  
  324.         sprintf(s1,"%s%s.MML",syscfg.datadir,s);
  325.         i=open(s1,O_RDONLY | O_BINARY);
  326.         if (i<0) {
  327.           nl();
  328.           pl(get_string(350));
  329.           nl();
  330.         } else {
  331.           i1=filelength(i);
  332.           mml_s=malloca(i1+10L);
  333.           read(i,mml_s,i1);
  334.           mml_s[i1]='\n';
  335.           mml_s[i1+1]=0;
  336.           close(i);
  337.           mml_started=0;
  338.           add_list(un,&numu,MAX_LIST,so());
  339.           if (mml_s) {
  340.             farfree(mml_s);
  341.             mml_s=NULL;
  342.           }
  343.         }
  344.         break;
  345.       case 'E':
  346.         if (!numu) {
  347.           nl();
  348.           pl(get_string(351));
  349.           nl();
  350.         } else {
  351.           multimail(un,numu);
  352.           done=1;
  353.         }
  354.         break;
  355.       case 'D':
  356.         if (numu) {
  357.           nl();
  358.           prt(2,get_string(352));
  359.           input(s,2);
  360.           i=atoi(s);
  361.           if ((i>0) && (i<=numu)) {
  362.             --numu;
  363.             for (i1=i-1; i1<numu; i1++)
  364.               un[i1]=un[i1+1];
  365.           }
  366.         }
  367.         break;
  368.       case 'L':
  369.         for (i=0; i<numu; i++) {
  370.           read_user(un[i],&u);
  371.           npr("%d. %s\r\n",i+1,nam(&u,un[i]));
  372.         }
  373.         break;
  374.     }
  375.   } while ((!done) && (!hangup));
  376. }
  377.  
  378.  
  379.