home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / MSGBASE1.C < prev    next >
Text File  |  1995-12-16  |  47KB  |  1,868 lines

  1. #include "vars.h"
  2.  
  3. #pragma hdrstop
  4.  
  5. #include "subxtr.h"
  6.  
  7. #include <dir.h>
  8.  
  9.  
  10.  
  11.  
  12. #define ALLOW_FULLSCREEN 1
  13. #define EMAIL_STORAGE 2
  14.  
  15. int deleted_flag;
  16.  
  17. /****************************************************************************/
  18.  
  19. void send_net_post(postrec *p, char *extra, int subnum)
  20. {
  21.   net_header_rec nh, nh1;
  22.   char *b, *b1,*ss;
  23.   long len1, len2;
  24.   char s[81];
  25.   int f,i,onn,nn,n,nn1;
  26.   unsigned int *list;
  27.   xtrasubsnetrec *xnp;
  28.  
  29.   b=readfile(&(p -> msg),extra,&len1);
  30.   if (b==NULL)
  31.     return;
  32.  
  33.   onn=net_num;
  34.   if (p->status & status_post_new_net)
  35.     nn=p->title[80];
  36.   else if (xsubs[subnum].num_nets)
  37.     nn=xsubs[subnum].nets[0].net_num;
  38.   else
  39.     nn=net_num;
  40.  
  41.   nn1=nn;
  42.   if (p->ownersys==0)
  43.     nn=-1;
  44.  
  45.   nh1.tosys=0;
  46.   nh1.touser=0;
  47.   nh1.fromsys=p->ownersys;
  48.   nh1.fromuser=p->owneruser;
  49.   nh1.list_len=0;
  50.   nh1.daten=p->daten;
  51.   nh1.length=len1+1+strlen(p -> title);
  52.   nh1.method=0;
  53.  
  54.   if (nh1.length > 32755) {
  55.     outstr(get_string(645));
  56.     npr("%lu",nh1.length-32755L);
  57.     outstr(get_string(646));
  58.     nh1.length = 32755;
  59.     len1=nh1.length-strlen(p->title)-1;
  60.   }
  61.  
  62.   if ((b1=malloca(nh1.length+100))==NULL) {
  63.     farfree(b);
  64.     set_net_num(onn);
  65.     return;
  66.   }
  67.  
  68.   strcpy(b1,p -> title);
  69.   memmove(&(b1[strlen(p -> title)+1]),b,(unsigned int) len1);
  70.   farfree(b);
  71.  
  72.   for (n=0; n<xsubs[subnum].num_nets; n++) {
  73.     xnp=&(xsubs[subnum].nets[n]);
  74.  
  75.     if ((xnp->net_num==nn) && (xnp->host))
  76.       continue;
  77.  
  78.     set_net_num(xnp->net_num);
  79.  
  80.     nh=nh1;
  81.     list=NULL;
  82.     nh.minor_type=xnp->type;
  83.     if (!nh.fromsys)
  84.       nh.fromsys=net_sysnum;
  85.  
  86.     if (xnp->host) {
  87.       nh.main_type=main_type_pre_post;
  88.       nh.tosys=xnp->host;
  89.     } else {
  90.       nh.main_type=main_type_post;
  91.       sprintf(s,"%sN%s.NET",net_data, xnp->stype);
  92.       f=open(s,O_RDONLY|O_BINARY);
  93.       if (f>0) {
  94.         len1=filelength(f);
  95.         list=(unsigned int *)malloca(len1*2+1);
  96.         if (!list)
  97.           continue;
  98.         if ((b=malloca(len1+100L))==NULL) {
  99.           farfree(list);
  100.           continue;
  101.         }
  102.         read(f,b,len1);
  103.         close(f);
  104.         b[len1]=0;
  105.         len2=0;
  106.         while (len2<len1) {
  107.           while ((len2<len1) && ((b[len2]<'0') || (b[len2]>'9')))
  108.             ++len2;
  109.           if ((b[len2]>='0') && (b[len2]<='9') && (len2<len1)) {
  110.             i=atoi(&(b[len2]));
  111.             if (((net_num!=nn) || (nh.fromsys!=i)) && (i!=net_sysnum))
  112.               list[(nh.list_len)++]=i;
  113.             while ((len2<len1) && (b[len2]>='0') && (b[len2]<='9'))
  114.               ++len2;
  115.           }
  116.         }
  117.         farfree(b);
  118.       }
  119.       if (!nh.list_len) {
  120.         if (list)
  121.           farfree(list);
  122.         continue;
  123.       }
  124.     }
  125.     if (!xnp->type)
  126.       nh.main_type=main_type_new_post;
  127.     if (nn1==net_num)
  128.       send_net(&nh, list, b1, xnp->type?NULL:xnp->stype);
  129.     else
  130.       gate_msg(&nh, b1, xnp->net_num, xnp->stype, list, nn);
  131.     if (list)
  132.       farfree(list);
  133.   }
  134.  
  135.   farfree(b1);
  136.   set_net_num(onn);
  137. }
  138.  
  139. /****************************************************************************/
  140.  
  141. void post(void)
  142. {
  143.   messagerec m;
  144.   postrec p;
  145.   char s[121],*b,*b1;
  146.   int i,dm,a,f;
  147.   slrec ss;
  148.   long len1,len2;
  149.   unsigned int *list;
  150.  
  151.   iscan(cursub);
  152.   if (curlsub<0) {
  153.     nl();
  154.     pl(get_string(668));
  155.     nl();
  156.     return;
  157.   }
  158.  
  159.   ss=syscfg.sl[actsl];
  160.  
  161.   if (freek1(syscfg.msgsdir)<10.0) {
  162.     nl();
  163.     pl(get_string(332));
  164.     nl();
  165.     return;
  166.   }
  167.  
  168.   if ((restrict_post & thisuser.restrict) || (thisuser.posttoday>=ss.posts)) {
  169.     nl();
  170.     pl(get_string(669));
  171.     nl();
  172.     return;
  173.   }
  174.  
  175.   if (actsl<subboards[curlsub].postsl) {
  176.     nl();
  177.     pl(get_string(670));
  178.     nl();
  179.     return;
  180.   }
  181.  
  182.   m.storage_type=subboards[curlsub].storage_type;
  183.   a=subboards[curlsub].anony & 0x0f;
  184.   if ((a==0) && (ss.ability & ability_post_anony))
  185.     a=anony_enable_anony;
  186.   if ((a==anony_enable_anony) && (thisuser.restrict & restrict_anony))
  187.     a=0;
  188.   if (xsubs[curlsub].num_nets) {
  189.     a &= (anony_real_name);
  190.     if (thisuser.restrict & restrict_net) {
  191.       nl();
  192.       pl(get_string(671));
  193.       nl();
  194.       return;
  195.     }
  196.     if (thisuser.restrict & (restrict_validate)) {
  197.       nl();
  198.       pl(get_string(671));
  199.       nl();
  200.       return;
  201.     }
  202.     if (net_sysnum) {
  203.       nl();
  204.       outstr(get_string(672));
  205.       for (i=0; i<xsubs[curlsub].num_nets; i++) {
  206.         if (i)
  207.           outstr(", ");
  208.         outstr(net_networks[xsubs[curlsub].nets[i].net_num].name);
  209.       }
  210.       outstr(".\r\n");
  211.       nl();
  212.     }
  213.   }
  214.   inmsg(&m,p.title,&a,1,(subboards[curlsub].filename),ALLOW_FULLSCREEN,
  215.     subboards[curlsub].name, (subboards[curlsub].anony&anony_no_tag)?1:0);
  216.   if (m.stored_as!=0xffffffff) {
  217.     p.anony=a;
  218.     p.msg=m;
  219.     p.ownersys=0;
  220.     p.owneruser=usernum;
  221.     p.qscan=status.qscanptr++;
  222.     time((long *)(&p.daten));
  223.     /*if (thisuser.restrict & restrict_auto_msg_delete)
  224.       p.status=status_delete;*/
  225.     /*else*/
  226.       if (thisuser.restrict & restrict_validate)
  227.         p.status=status_unvalidated;
  228.       else
  229.         p.status=0;
  230.     if ((xsubs[curlsub].num_nets) &&
  231.       (subboards[curlsub].anony & anony_val_net) && (!lcs() || irt[0])) {
  232.       p.status |= status_pending_net;
  233.       dm=1;
  234.       for (i=1; i<=nummsgs; i++)
  235.         if (msgs[i].status & status_pending_net)
  236.           dm=0;
  237.       if (dm) {
  238.         sprintf(s,get_stringx(1,37),subboards[curlsub].name);
  239.         ssm(1,0,s);
  240.       }
  241.     }
  242.     if (nummsgs>=subboards[curlsub].maxmsgs) {
  243.       i=1;
  244.       dm=0;
  245.       while ((dm==0) && (i<=nummsgs)) {
  246.         if ((msgs[i].status & status_no_delete)==0)
  247.           dm=i;
  248.         ++i;
  249.       }
  250.       if (dm==0)
  251.         dm=1;
  252.       delete(dm);
  253.       deleted_flag=dm;
  254.     }
  255.     msgs[++nummsgs]=p;
  256.     sub_dates[curlsub]=p.qscan;
  257.     bchanged=1;
  258.     savebase();
  259.     ++thisuser.msgpost;
  260.     ++thisuser.posttoday;
  261.     ++status.msgposttoday;
  262.     save_status();
  263.     topscreen();
  264.     sprintf(s,get_stringx(1,38),p.title,subboards[curlsub].name);
  265.     sysoplog(s);
  266.     outstr(get_string(673));
  267.     pl(subboards[curlsub].name);
  268.     save_status();
  269.     npr("\r\n1Your p/c ratio is now %-5.3f",post_ratio());
  270.     thisuser.gold=thisuser.gold+1;
  271.     if (xsubs[curlsub].num_nets) {
  272.       ++thisuser.postnet;
  273.       if (!(p.status & status_pending_net))
  274.         send_net_post(&p, subboards[curlsub].filename, curlsub);
  275.     }
  276.   }
  277. }
  278.  
  279.  
  280. void extract_out(char *b, long len, char *title)
  281. {
  282.   char s1[81],s2[81],ch=26,ch1;
  283.   int i;
  284.  
  285.   do {
  286.     prt(2,get_string(674));  /*Save under what filename*/
  287.     input(s1,50);
  288.     if (s1[0]) {
  289.       if (strchr(s1,':') || strchr(s1,'\\'))
  290.         strcpy(s2,s1);
  291.       else
  292.         sprintf(s2,"%s%s",syscfg.gfilesdir,s1);
  293.       if (exist(s2)) {
  294.         nl();
  295.     pl(get_string(675)); /*filename already in use*/
  296.     nl();
  297.     prt(2,get_string(676)); /*Overwrite,append,etc..*/
  298.     ch1=onek("QOAN");
  299.     switch(ch1) {
  300.       case 'Q':
  301.         s2[0]=0;
  302.         s1[0]=0;
  303.         break;
  304.       case 'N':
  305.         s1[0]=0;
  306.         break;
  307.       case 'A':
  308.         break;
  309.       case 'O':
  310.         unlink(s2);
  311.         break;
  312.     }
  313.     nl();
  314.       }
  315.     } else
  316.       s2[0]=0;
  317.   } while ((!hangup) && (s2[0]!=0) && (s1[0]==0));
  318.   if ((s1[0]) && (!hangup)) {
  319.     i=open(s2,O_RDWR | O_BINARY | O_CREAT , S_IREAD | S_IWRITE);
  320.     if (i<=0) {
  321.       pl(get_string(933)); /*Could not open file for writing*/
  322.     } else {
  323.       if (filelength(i)) {
  324.         lseek(i, -1L, SEEK_END);
  325.         read(i, ((void *)&ch1), 1);
  326.         if (ch1 == 26)
  327.           lseek(i, -1L, SEEK_END);
  328.       }
  329.       write(i,title,strlen(title));
  330.       write(i,"\r\n",2);
  331.       write(i,(void *)b,len);
  332.       write(i,&ch,1);
  333.       close(i);
  334.       outstr(get_string(677)); /*Message written to : */
  335.       pl(s2);
  336.     }
  337.   }
  338.   farfree(b);
  339. }
  340.  
  341. void quote_out(char *b, long len, char *title)
  342. {
  343.   char s1[81],s2[81],ch=26,ch1;
  344.   int i;
  345.  
  346.   do {
  347.     strcpy(s1,"QUOTE");
  348.     if (s1[0]) {
  349.       if (strchr(s1,':') || strchr(s1,'\\'))
  350.         strcpy(s2,s1);
  351.       else
  352.         sprintf(s2,"%s%s",syscfg.gfilesdir,s1);
  353.       if (exist(s2)) {
  354.         unlink(s2);
  355.     nl();
  356.       }
  357.     } else
  358.       s2[0]=0;
  359.   } while ((!hangup) && (s2[0]!=0) && (s1[0]==0));
  360.   if ((s1[0]) && (!hangup)) {
  361.     i=open(s2,O_RDWR | O_BINARY | O_CREAT , S_IREAD | S_IWRITE);
  362.     if (i<=0) {
  363.       pl(get_string(933)); /*Could not open file for writing*/
  364.     } else {
  365.       if (filelength(i)) {
  366.         lseek(i, -1L, SEEK_END);
  367.         read(i, ((void *)&ch1), 1);
  368.         if (ch1 == 26)
  369.           lseek(i, -1L, SEEK_END);
  370.       }
  371.       write(i,title,strlen(title));
  372.       write(i,"\r\n",2);
  373.       write(i,(void *)b,len);
  374.       write(i,&ch,1);
  375.       close(i);
  376. /*      outstr(get_string(677)); Message written to :
  377.       pl(s2);*/
  378.     }
  379.   }
  380.   farfree(b);
  381. }
  382.  
  383. void grab_user_name(messagerec *m, char *fn)
  384. {
  385.   char *ss,*ss1,*ss2;
  386.   long len;
  387.  
  388.   ss=readfile(m,fn,&len);
  389.   if (ss) {
  390.     ss1=strchr(ss,'\r');
  391.     if (ss1) {
  392.       *ss1=0;
  393.       ss2=ss;
  394.       if ((ss[0]=='`') && (ss[1]=='`')) {
  395.         for (ss1=ss+2; *ss1; ss1++) {
  396.           if ((ss1[0]=='`') && (ss1[1]=='`'))
  397.             ss2=ss1+2;
  398.         }
  399.         while (*ss2==' ')
  400.           ++ss2;
  401.       }
  402.       strcpy(net_email_name,ss2);
  403.     } else
  404.       net_email_name[0]=0;
  405.     farfree(ss);
  406.   } else
  407.     net_email_name[0]=0;
  408. }
  409.  
  410.  
  411.  
  412. void scan(int msgnum, int optype, int *nextsub)
  413. {
  414.   char s[81],s1[81],s2[81],*b,*ss1;
  415.   int i,i1,i2,done,quit,abort,next,val,realexpress;
  416.   slrec ss;
  417.   long l,len;
  418.   postrec p,p1;
  419.  
  420.   irt[0]=0;
  421.   irt_name[0]=0;
  422.   done=0;
  423.   quit=0;
  424.   val=0;
  425.   realexpress=express;
  426.   iscan(cursub);
  427.   if (curlsub<0) {
  428.     nl();
  429.     pl(get_string(668));
  430.     nl();
  431.     return;
  432.   }
  433.   do {
  434.     tleft(1);
  435.     if (xsubs[curlsub].num_nets)
  436.       set_net_num(xsubs[curlsub].nets[0].net_num);
  437.     else
  438.       set_net_num(0);
  439.     switch(optype) {
  440.       case 0: /* Read Prompt */
  441.     sprintf(s,"1%s5:7(11-%u7,1^%u7)5,7? 5:",get_string(678), nummsgs,msgnum);
  442.         nl();
  443.         if (express) {
  444.           s[0]=0;
  445.           nl();
  446.           nl();
  447.         } else {
  448.       sprintf(s1,"7[1%s7]\r\n",subboards[usub[cursub].subnum].name);
  449.       prt(2,s1);
  450.       prt(2,s);
  451.       helpl=16;
  452.           input(s,3);
  453.       while (s[0]==32) {
  454.         strcpy(s1,&(s[1]));
  455.         strcpy(s,s1);
  456.       }
  457.         }
  458.         optype=0;
  459.         i=atoi(s);
  460.         if (s[0]==0) {
  461.           i=msgnum+1;
  462.           if (i>=nummsgs+1)
  463.             done=1;
  464.         }
  465.         if ((i!=0) && (i<=nummsgs) && (i>=1)) {
  466.           optype=2;
  467.           msgnum=i;
  468.         } else
  469.           if (s[1]==0) {
  470.             switch(s[0]) {
  471.               case 'Q':
  472.                 quit=1;
  473.                 done=1;
  474.                 *nextsub=0;
  475.                 break;
  476.               case 'B':
  477.                 if (*nextsub!=0) {
  478.                   *nextsub=1;
  479.                   done=1;
  480.                   quit=1;
  481.                 }
  482.                 break;
  483.               case 'T':
  484.                 optype=1;
  485.                 break;
  486.               case 'R':
  487.                 optype=2;
  488.                 break;
  489.           case 'A':
  490.            if(okfsed()){
  491.         prt(5,"Quote message? ");
  492.         if(yn()) {
  493.         b=readfile(&(msgs[msgnum].msg),(subboards[curlsub].filename),&len);
  494.         quote_out(b,len, msgs[msgnum].title);
  495.         nl();
  496.         strcpy(s, "C:\\WWIV\\GFILES\\QUOTE");
  497.         if (s[0]) {
  498.           nl();
  499.           load_workspace(s,0);
  500.          }
  501.         }
  502.            }
  503.         if ((msgs[msgnum].ownersys) && (!msgs[msgnum].owneruser))
  504.           grab_user_name(&(msgs[msgnum].msg),subboards[curlsub].filename);
  505.         grab_quotes(&(msgs[msgnum].msg),subboards[curlsub].filename);
  506.         ss=syscfg.sl[actsl];
  507.         if (msgs[msgnum].status & status_post_new_net) {
  508.           set_net_num(msgs[msgnum].title[80]);
  509.           if (msgs[msgnum].title[80]==-1) {
  510.             pl(get_string(679));
  511.             break;
  512.           }
  513.         }
  514.         if ((lcs()) || (ss.ability & ability_read_post_anony) || (msgs[msgnum].anony==0))
  515.                   email(msgs[msgnum].owneruser,msgs[msgnum].ownersys,0,0);
  516.                 else
  517.                   email(msgs[msgnum].owneruser,msgs[msgnum].ownersys,0,msgs[msgnum].anony);
  518.                 grab_quotes(NULL, NULL);
  519.                 break;
  520.               case 'P':
  521.                 irt[0]=0;
  522.                 irt_name[0]=0;
  523.           case 'W':
  524.            if (s[0]=='W') {
  525.            if(okfsed()){
  526.         prt(5,"Quote message? ");
  527.         if(yn()) {
  528.         b=readfile(&(msgs[msgnum].msg),(subboards[curlsub].filename),&len);
  529.         quote_out(b,len, msgs[msgnum].title);
  530.         nl();
  531.         strcpy(s, "C:\\WWIV\\GFILES\\QUOTE");
  532.         if (s[0]) {
  533.           nl();
  534.           load_workspace(s,0);
  535.          }
  536.         }
  537.            }}
  538.                 deleted_flag=0;
  539.                 grab_quotes(&(msgs[msgnum].msg),subboards[curlsub].filename);
  540.                 post();
  541.                 if (deleted_flag && (deleted_flag<=msgnum))
  542.                   --msgnum;
  543.                 grab_quotes(NULL, NULL);
  544.                 break;
  545.               case '?':
  546.         if (lcs())
  547.           printmenu(13);
  548.         else
  549.                   printmenu(1);
  550.                 break;
  551.           case '-':
  552.         if ((msgnum>1) && (msgnum-1<nummsgs)) {
  553.           --msgnum;
  554.           optype=2;
  555.         }
  556.         break;
  557.           case 'C':
  558.         express=1;
  559.         break;
  560. /*************/
  561.               case 'V':
  562.                 if ((cs()) && (msgs[msgnum].ownersys==0) && (msgnum>0) && (msgnum<=nummsgs))
  563.                   valuser(msgs[msgnum].owneruser);
  564.         else
  565.                   if ((cs()) && (msgnum>0) && (msgnum<=nummsgs)) {
  566.             nl();
  567.             pl(get_string(680));
  568.             nl();
  569.           }
  570.                 break;
  571.           case 'N':
  572.         if ((lcs()) && (msgnum>0) && (msgnum<=nummsgs)) {
  573.           msgs[msgnum].status ^= status_no_delete;
  574.                   bchanged=1;
  575.           nl();
  576.           if (msgs[msgnum].status & status_no_delete)
  577.                     pl(get_string(681));
  578.           else
  579.             pl(get_string(682));
  580.           nl();
  581.         }
  582.         break;
  583.               case 'X':
  584.                 if ((lcs()) && (msgnum>0) && (msgnum<=nummsgs) &&
  585.                     (subboards[curlsub].anony & anony_val_net) &&
  586.                     (xsubs[curlsub].num_nets)) {
  587.                   msgs[msgnum].status ^= status_pending_net;
  588.                   bchanged=1;
  589.           nl();
  590.                   if (msgs[msgnum].status & status_pending_net) {
  591.                     val |= 2;
  592.                     pl(get_string(683));
  593.                   } else
  594.                     pl(get_string(684));
  595.           nl();
  596.         }
  597.         break;
  598.           case 'U':
  599.         if ((lcs()) && (msgnum>0) && (msgnum<=nummsgs)) {
  600.           msgs[msgnum].anony=0;
  601.                   bchanged=1;
  602.           nl();
  603.                   pl(get_string(685));
  604.         }
  605.         break;
  606.               case 'D':
  607.                 if (lcs()) {
  608.                   if (msgnum) {
  609.                     delete(msgnum);
  610.                     if (msgnum>1)
  611.                       msgnum--;
  612.                     savebase();
  613.                   }
  614.                 }
  615.                 break;
  616.           case 'E':
  617.         if (so()) {
  618.                   if ((msgnum>0) && (msgnum<=nummsgs)) {
  619.                     b=readfile(&(msgs[msgnum].msg),(subboards[curlsub].filename),&len);
  620.                     extract_out(b,len, msgs[msgnum].title);
  621.                   }
  622.         }
  623.         break;
  624.           case 'M':
  625.                 if ((lcs()) && (msgnum>0) && (msgnum<=nummsgs)) {
  626.                   nl();
  627.           do {
  628.                     prt(2,get_string(686));
  629.                     ss1=mmkey(0);
  630.             if (ss1[0]=='?')
  631.               sublist();
  632.           } while ((!hangup) && (ss1[0]=='?'));
  633.           i=-1;
  634.           if (ss1[0]==0)
  635.             break;
  636.                   for (i1=0; (i1<num_subs) && (usub[i1].subnum!=-1); i1++)
  637.                     if (strcmp(usub[i1].keys,ss1)==0)
  638.                       i=i1;
  639.                   if (i!=-1) {
  640.             p=msgs[msgnum];
  641.                     b=readfile(&(p.msg),(subboards[curlsub].filename),&len);
  642.                     delete(msgnum);
  643.                     if (msgnum>1)
  644.                       msgnum--;
  645.             savebase();
  646.                     iscan(i);
  647.             p.msg.storage_type=subboards[curlsub].storage_type;
  648.             savefile(b,len,&(p.msg),(subboards[curlsub].filename));
  649.                     p.qscan=status.qscanptr++;
  650.             if (nummsgs>=subboards[curlsub].maxmsgs) {
  651.                       i1=1;
  652.                       i2=0;
  653.                       while ((i2==0) && (i1<=nummsgs)) {
  654.                         if ((msgs[i1].status & status_no_delete)==0)
  655.                           i2=i1;
  656.                         ++i1;
  657.                        }
  658.                        if (i2==0)
  659.                          i2=1;
  660.                        p1=msgs[i2];
  661.                        remove_link(&p1.msg,(subboards[curlsub].filename));
  662.                        for (i1=i2; i1<nummsgs; i1++)
  663.                          msgs[i1]=msgs[i1+1];
  664.                --nummsgs;
  665.                      }
  666.                      if ((!(subboards[curlsub].anony & anony_val_net)) ||
  667.                          (!xsubs[curlsub].num_nets))
  668.                        p.status &= ~status_pending_net;
  669.                      msgs[++nummsgs]=p;
  670.                      sub_dates[curlsub]=p.qscan;
  671.                      bchanged=1;
  672.                      savebase();
  673.                      save_status();
  674.                      iscan(cursub);
  675.              nl();
  676.              pl(get_string(687));
  677.              nl();
  678.           }
  679.         }
  680.         break;
  681.           case 'L':
  682.         if (!so())
  683.           break;
  684.         nl();
  685.         prt(2,get_string(7)); /*Filename?*/
  686.         input(s,50);
  687.         if (s[0]) {
  688.           nl();
  689.           prt(5,get_string(17)); /*Allow editing?*/
  690.           if (yn()) {
  691.             nl();
  692.             load_workspace(s,0);
  693.           } else {
  694.             nl();
  695.             load_workspace(s,1);
  696.           }
  697.         }
  698.         break;
  699. /*************/
  700.             }
  701.       } else {
  702.         if (strcmp(s,"CLS")==0)
  703.           outchr('\x0c');
  704.       }
  705.         break;
  706.       case 1: /* List Titles */
  707.         i=0;
  708.         abort=0;
  709.         if (msgnum>=nummsgs)
  710.           abort=1;
  711.         while ((!abort) && (!hangup) && (++i<=10)) {
  712.           ++msgnum;
  713.           if ((msgs[msgnum].ownersys==0) && (msgs[msgnum].owneruser==usernum))
  714.             sprintf(s1,"[%d]",msgnum);
  715.           else if (msgs[msgnum].ownersys!=0)
  716.             sprintf(s1,"<%d>",msgnum);
  717.           else
  718.             sprintf(s1,"(%d)",msgnum);
  719.           for (i1=0; i1<5; i1++)
  720.             s[i1]=32;
  721.           if (msgs[msgnum].qscan>qsc_p[curlsub])
  722.             s[0]='*';
  723.           if (msgs[msgnum].status & (status_pending_net | status_unvalidated))
  724.             s[0]='-';
  725.           strcpy(&s[7-strlen(s1)],s1);
  726.           strcat(s," ");
  727.           if ((msgs[msgnum].status&(status_unvalidated|status_delete))&&(!lcs()))
  728.             strcat(s,get_string(665));
  729.           else
  730.             strcat(s,msgs[msgnum].title);
  731.           pla(s,&abort);
  732.           if (msgnum>=nummsgs)
  733.             abort=1;
  734.         }
  735.         optype=0;
  736.         break;
  737.       case 2: /* Read Message */
  738.     if ((msgnum>0) && (msgnum<=nummsgs))
  739.           read_message(msgnum,&next,&val);
  740.     ansic(0);
  741.         nl();
  742.         if (next) {
  743.           ++msgnum;
  744.           if (msgnum>nummsgs)
  745.             done=1;
  746.           optype=2;
  747.         } else
  748.           optype=0;
  749.         if (expressabort)
  750.       if (realexpress) {
  751.             done=1;
  752.             quit=1;
  753.             *nextsub=0;
  754.           } else {
  755.         expressabort=0;
  756.         express=0;
  757.         optype=0;
  758.       }
  759.         break;
  760.     }
  761.   } while ((!done) && (!hangup));
  762.   if (!realexpress) {
  763.     express=0;
  764.     expressabort=0;
  765.   }
  766.   if ((val & 1) && (lcs()) && (!express)) {
  767.     nl();
  768.     prt(5,get_string(688));
  769.     if (yn()) {
  770.       for (i=1; i<=nummsgs; i++)
  771.         if (msgs[i].status & (status_unvalidated | status_delete))
  772.           msgs[i].status &= (~(status_unvalidated | status_delete));
  773.       bchanged=1;
  774.     }
  775.   }
  776.   if ((val & 2) && (lcs()) && (!express)) {
  777.     nl();
  778.     prt(5,get_string(689));
  779.     if (yn()) {
  780.       i1=0;
  781.       for (i=1; i<=nummsgs; i++)
  782.         if (msgs[i].status & status_pending_net) {
  783.           send_net_post(msgs+i, subboards[curlsub].filename, curlsub);
  784.           ++i1;
  785.           msgs[i].status &= (~status_pending_net);
  786.         }
  787.       nl();
  788.       npr("%d",i1);
  789.       pl(get_string(690));
  790.       nl();
  791.       bchanged=1;
  792.     }
  793.   }
  794.   if ((!quit) && (!express)) {
  795.     nl();
  796.     ss=syscfg.sl[actsl];
  797.     if (
  798.         ((restrict_post & thisuser.restrict)==0) &&
  799.         (thisuser.posttoday<ss.posts) &&
  800.         (actsl>=subboards[curlsub].postsl)) {
  801.       sprintf(s,"%s %s? ",get_string(691), subboards[curlsub].name);
  802.       prt(5,s);
  803.       irt[0]=0;
  804.       irt_name[0]=0;
  805.       grab_quotes(NULL, NULL);
  806.       if (yn())
  807.         post();
  808.     }
  809.   }
  810.   savebase();
  811.   nl();
  812. }
  813.  
  814.  
  815. void qscan(int bn, int *ns)
  816. {
  817.   int i,nextsub,os,sn;
  818.   char s[81],s1[81];
  819.   unsigned long qscnptrx,sd;
  820.  
  821.   sn=usub[bn].subnum;
  822.  
  823.   if ((hangup) || (sn<0))
  824.     return;
  825.  
  826.   nl();
  827.  
  828.   qscnptrx=qsc_p[sn];
  829.   sd=sub_dates[sn];
  830.   if ((!sd) || (sd>qscnptrx)) {
  831.     nextsub=*ns;
  832.     os=cursub;
  833.     cursub=bn;
  834.     i=1;
  835.  
  836.     iscan(cursub);
  837.  
  838.     sprintf(s,"7< 3%s %s %s 7- 3%u %s 7>",get_string(692), subboards[curlsub].name,
  839.               usub[cursub].keys,nummsgs, "msgs");
  840.     prt(1,s);
  841.     nl();
  842.  
  843.     while ((i<=nummsgs) && (msgs[i].qscan<=qscnptrx))
  844.       ++i;
  845.     if ((nummsgs>0) && (msgs[nummsgs].qscan<=qscnptrx)) {
  846.       qsc_p[curlsub]=status.qscanptr-1;
  847.     }
  848.     if ((nummsgs>0) && (i<=nummsgs))
  849.       if (msgs[i].qscan>qsc_p[curlsub])
  850.         scan(i,2,&nextsub);
  851.  
  852.     cursub=os;
  853.     *ns=nextsub;
  854.     sprintf(s,"7< 3%s %s 7>",subboards[curlsub].name, get_string(693));
  855.     prt(1,s);
  856.   } else {
  857.     sprintf(s,"< %s %s %s >",get_string(694), subboards[sn].name, usub[bn].keys);
  858.     prt(1,s);
  859.   }
  860.   nl();
  861. }
  862.  
  863.  
  864. void nscan(int ss)
  865. {
  866.   int i,nextsub,abort,next;
  867.  
  868.   nl();
  869.   nextsub=1;
  870.   prt(3,get_string(695));
  871.   nl();
  872.   for (i=ss; (usub[i].subnum!=-1) && (i<num_subs) && (nextsub) && (!hangup); i++) {
  873.     if (qsc_q[usub[i].subnum/32]&(1L<<(usub[i].subnum%32)))
  874.       qscan(i,&nextsub);
  875.     abort=next=0;
  876.     checka(&abort,&next);
  877.     if (abort)
  878.       nextsub=0;
  879.   }
  880.   nl();
  881.   prt(3,get_string(696));
  882.   nl();
  883.   nl();
  884.   if ((nextsub) && (thisuser.sysstatus & sysstatus_nscan_file_system) &&
  885.     ((syscfg.sysconfig & sysconfig_no_xfer)==0))
  886.     nscanall();
  887. }
  888.  
  889. void scan2(void)
  890. {
  891.   char s[81];
  892.   int i,i1;
  893.  
  894.   iscan(cursub);
  895.   nl();
  896.   if (curlsub<0) {
  897.     pl(get_string(668));
  898.     nl();
  899.     return;
  900.   }
  901.   npr("%d",nummsgs);
  902.   outstr(get_string(697));
  903.   pl(subboards[curlsub].name);
  904.   if (nummsgs==0)
  905.     return;
  906.   helpl=11;
  907.   prt(2,get_string(698));
  908.   input(s,4);
  909.   i=atoi(s);
  910.   if (i<1)
  911.     i=0;
  912.   else
  913.     if (i>nummsgs)
  914.       i=nummsgs;
  915.     else
  916.       i--;
  917.   i1=0;
  918.   if (strcmp(s,"S")==0)
  919.     scan(0,0,&i1);
  920.   else
  921.     if (strcmp(s,"Q")) {
  922.       if (strcmp(s,"N")==0) {
  923.       } else
  924.         scan(i,1,&i1);
  925.     }
  926. }
  927.  
  928.  
  929. void printmenu(int i)
  930. {
  931.   char s[81],s1[81];
  932.   int next;
  933.  
  934.   next=0;
  935.  
  936.   if ((thisuser.sysstatus & (sysstatus_color | sysstatus_ansi))
  937.       == (sysstatus_color | sysstatus_ansi)) {
  938.     sprintf(s1,"MENU%u.ANS", i);
  939.     sprintf(s,"%s%s",languagedir,s1);
  940.     if (exist(s)) {
  941.       printfile(s1);
  942.       return;
  943.     }
  944.   }
  945.   sprintf(s1,"MENU%u.MSG", i);
  946.   sprintf(s,"%s%s",languagedir,s1);
  947.   if (exist(s)) {
  948.     printfile(s1);
  949.     return;
  950.   }
  951.  
  952.   if ((thisuser.screenchars==40) && (menus2[i].stored_as)) {
  953.     sprintf(s,"%sMENUS40.MSG",languagedir);
  954.     read_message1(&menus2[i],0,0,&next,s);
  955.   } else
  956.     if ((okansi()) && (menus1[i].stored_as)) {
  957.       sprintf(s,"%sMENUSANS.MSG",languagedir);
  958.       read_message1(&menus1[i],0,0,&next,s);
  959.     } else {
  960.       sprintf(s,"%sMENUS.MSG",languagedir);
  961.       if (menus[i].stored_as)
  962.         read_message1(&menus[i],0,0,&next,s);
  963.     }
  964. }
  965.  
  966.  
  967. void delmail(int f, int loc)
  968. {
  969.   mailrec m,m1;
  970.   userrec u;
  971.   int rm,i,t,otf;
  972.  
  973.   lseek(f,((long) loc) * ((long) sizeof(mailrec)), SEEK_SET);
  974.   read(f,(void *)&m,sizeof(mailrec));
  975.  
  976.   rm=1;
  977.   if (m.status & status_multimail) {
  978.     t=filelength(f)/sizeof(mailrec);
  979.     otf=0;
  980.     for (i=0; i<t; i++)
  981.       if (i!=loc) {
  982.         lseek(f,((long)i)*((long)sizeof(mailrec)),SEEK_SET);
  983.         read(f,(void *)&m1,sizeof(mailrec));
  984.         if ((m.msg.stored_as==m1.msg.stored_as) && (m.msg.storage_type==m1.msg.storage_type) && (m1.daten!=0xffffffff))
  985.           otf=1;
  986.       }
  987.     if (otf)
  988.       rm=0;
  989.   }
  990.  
  991.   if (rm)
  992.     remove_link(&m.msg,"EMAIL");
  993.  
  994.   if (m.tosys==0) {
  995.     read_user(m.touser,&u);
  996.     if (u.waiting) {
  997.       --u.waiting;
  998.       write_user(m.touser,&u);
  999.       close_user();
  1000.     }
  1001.     if (m.touser==1)
  1002.       --fwaiting;
  1003.   }
  1004.  
  1005.   lseek(f,((long) loc) * ((long) sizeof(mailrec)), SEEK_SET);
  1006.   m.touser=0;
  1007.   m.tosys=0;
  1008.   m.daten=0xffffffff;
  1009.   m.msg.storage_type=0;
  1010.   m.msg.stored_as=0xffffffff;
  1011.   write(f,(void *)&m,sizeof(mailrec));
  1012.   mailcheck=1;
  1013. }
  1014.  
  1015. void purgemail(int f,int *mloc,int mw,int *curmail, mailrec *m1, slrec *ss)
  1016. {
  1017.   int i;
  1018.   mailrec m;
  1019.  
  1020.   if (m1->fromuser==65535)
  1021.     return;
  1022.  
  1023.   ansic(5);
  1024.   if ((m1->anony & anony_sender) && ((ss->ability & ability_read_email_anony)==0)) {
  1025.     outstr(get_string(699));
  1026.   } else {
  1027.     outstr(get_string(700));
  1028.     if (m1->fromsys) {
  1029.       npr("#%u @%u? ",m1->fromuser, m1->fromsys);
  1030.     } else {
  1031.       npr("#%u? ",m1->fromuser);
  1032.     }
  1033.   }
  1034.   if (yn()) {
  1035.     for (i=0; i<mw; i++) {
  1036.       if (mloc[i]>=0) {
  1037.         lseek(f,((long) mloc[i]) * sizeof(mailrec),SEEK_SET);
  1038.         read(f,(void *) (&m),sizeof(mailrec));
  1039.         if ((m.fromuser==m1->fromuser) && (m.fromsys==m1->fromsys)) {
  1040.           outstr(get_string(701));
  1041.           npr("%d\r\n",i+1);
  1042.           delmail(f,mloc[i]);
  1043.           mloc[i]=-1;
  1044.           if (*curmail==i)
  1045.             ++(*curmail);
  1046.         }
  1047.       } else {
  1048.         if (*curmail==i)
  1049.           ++(*curmail);
  1050.       }
  1051.     }
  1052.   }
  1053. }
  1054.  
  1055.  
  1056. void readmail(void)
  1057. {
  1058.   int i,i1,i2,i3,f,mw,mloc[256],mfl,curmail,done,abort,next,okmail,tp,nn;
  1059.   unsigned short x,xx;
  1060.   char s[81],s1[81],s2[81],fn[81],*b,*ss1;
  1061.   mailrec m;
  1062.   slrec ss;
  1063.   userrec u;
  1064.   char ch;
  1065.   long len,num_mail,num_mail1;
  1066.   unsigned short un, sy;
  1067.   net_system_list_rec *csne;
  1068.  
  1069.   ss=syscfg.sl[actsl];
  1070.   sprintf(fn,"%sEMAIL.DAT",syscfg.datadir);
  1071.   f=open(fn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  1072.   if (f<0) {
  1073.     nl();
  1074.     nl();
  1075.     pl(get_string(702));
  1076.     nl();
  1077.     return;
  1078.   }
  1079.   mfl=filelength(f)/sizeof(mailrec);
  1080.   mw=0;
  1081.   for (i=0; (i<mfl) && (mw<255); i++) {
  1082.     lseek(f,((long) (i)) * (sizeof(mailrec)), SEEK_SET);
  1083.     read(f,(void *)(&m),sizeof(mailrec));
  1084.     if ((m.tosys==0) && (m.touser==usernum))
  1085.       mloc[mw++]=i;
  1086.   }
  1087.   thisuser.waiting=mw;
  1088.   if (usernum==1)
  1089.     fwaiting=mw;
  1090.   if (mw==0) {
  1091.     nl();
  1092.     nl();
  1093.     pl(get_string(27));
  1094.     nl();
  1095.     return;
  1096.   }
  1097.   if (mw==1)
  1098.     curmail=0;
  1099.   else {
  1100.     nl();
  1101.     nl();
  1102.     pl(get_string(703));
  1103.     nl();
  1104.     for (i=0; i<mw; i++) {
  1105.       lseek(f,((long) mloc[i]) * sizeof(mailrec),SEEK_SET);
  1106.       read(f,(void *) (&m),sizeof(mailrec));
  1107.       tp=80;
  1108.       if (m.status & status_source_verified)
  1109.         tp -= 2;
  1110.       if (m.status & status_new_net) {
  1111.         tp -= 1;
  1112.         if (strlen(m.title)<=tp) {
  1113.           nn=(unsigned char) m.title[tp+1];
  1114.         } else
  1115.           nn=0;
  1116.       } else
  1117.         nn=0;
  1118.       sprintf(s,"%d. ",i+1);
  1119.       if ((m.anony & anony_sender) && ((ss.ability & ability_read_email_anony)==0)) {
  1120.         strcat(s,get_string(482));
  1121.       } else {
  1122.         if (m.fromsys==0) {
  1123.           if (m.fromuser==65535) {
  1124.             if (nn!=255)
  1125.               strcat(s,net_networks[nn].name);
  1126.           } else {
  1127.             read_user(m.fromuser,&u);
  1128.             strcat(s,nam(&u,m.fromuser));
  1129.       }
  1130.         } else {
  1131.           set_net_num(nn);
  1132.           csne=next_system(m.fromsys);
  1133.           if (csne)
  1134.             ss1=csne->name;
  1135.           else
  1136.             ss1=get_string(622);
  1137.           if (nn==255) {
  1138.             sprintf(s1,"%s #%u @%u",get_string(704), m.fromuser,m.fromsys);
  1139.           } else {
  1140.             if (net_num_max>1)
  1141.               sprintf(s1,"%s #%u @%u (%s)",
  1142.                 net_networks[nn].name,m.fromuser,m.fromsys,ss1);
  1143.             else
  1144.               sprintf(s1,"%s %u @%u (%s)",get_string(658), m.fromuser,m.fromsys,ss1);
  1145.           }
  1146.           strcat(s,s1);
  1147.         }
  1148.       }
  1149.       pl(s);
  1150.     }
  1151.     nl();
  1152.     helpl=10;
  1153.     pl(get_string(705));
  1154.     outstr(":");
  1155.     input(s,3);
  1156.     if (strcmp(s,"Q")==0) {
  1157.       close(f);
  1158.       return;
  1159.     }
  1160.     i=atoi(s);
  1161.     if (i)
  1162.       if (i<=mw)
  1163.         curmail=i-1;
  1164.       else
  1165.         curmail=0;
  1166.     else
  1167.       curmail=0;
  1168.   }
  1169.   done=0;
  1170.   do {
  1171.     sprintf(s,"(%u/%u): ",curmail+1,mw);
  1172.     abort=0;
  1173.     nl();
  1174.     nl();
  1175.     osan(s,&abort,&next);
  1176.     next=0;
  1177.     ansic(MSG_COLOR);
  1178.     s[0]=0;
  1179.     if (mloc[curmail]<0) {
  1180.       strcat(s,get_string(706));
  1181.       okmail=0;
  1182.       pl(s);
  1183.       nl();
  1184.       nl();
  1185.     } else {
  1186.       lseek(f,((long) (mloc[curmail])) * (sizeof(mailrec)), SEEK_SET);
  1187.       read(f,(void *)&m,sizeof(mailrec));
  1188.       if ((m.tosys!=0) || (m.touser!=usernum)) {
  1189.     mloc[curmail]=-1;
  1190.         strcat(s,get_string(706));
  1191.         okmail=0;
  1192.         pl(s);
  1193.         nl();
  1194.         nl();
  1195.       } else {
  1196.         strcat(s,m.title);
  1197.         strcpy(irt,m.title);
  1198.         irt_name[0]=0;
  1199.         abort=0;
  1200.         i=((ability_read_email_anony & ss.ability)!=0);
  1201.         okmail=1;
  1202.         pla(s,&abort);
  1203.         if ((m.fromsys) && (!m.fromuser))
  1204.           grab_user_name(&(m.msg),"EMAIL");
  1205.         else
  1206.           net_email_name[0]=0;
  1207.         tp=80;
  1208.         if (m.status & status_source_verified) {
  1209.           tp -= 2;
  1210.           if (strlen(m.title)<=tp) {
  1211.             xx=*(short *) (m.title+tp+1);
  1212.             strcpy(s,get_string(707));
  1213.             sprintf(s+strlen(s),"%u",xx);
  1214.             if (xx==1) {
  1215.               strcat(s,get_string(708));
  1216.             } else if ((xx>256) && (xx<512)) {
  1217.               strcpy(s2,get_string(709));
  1218.               sprintf(s2+strlen(s2),"%d)",xx-256);
  1219.               strcat(s,s2);
  1220.             }
  1221.           } else {
  1222.             strcpy(s,get_string(710));
  1223.           }
  1224.           if (!abort) {
  1225.             ansic(4);
  1226.             pla(s,&abort);
  1227.           }
  1228.         }
  1229.         if (m.status & status_new_net) {
  1230.           tp -= 1;
  1231.           if (strlen(m.title)<=tp) {
  1232.             nn=m.title[tp+1];
  1233.           } else
  1234.             nn=0;
  1235.         } else
  1236.           nn=0;
  1237.         set_net_num(nn);
  1238.         if (nn==255)
  1239.           setorigin(0,0);
  1240.         else
  1241.           setorigin(m.fromsys, m.fromuser);
  1242.         if (!abort)
  1243.           read_message1(&m.msg, (m.anony & 0x0f), i, &next, "EMAIL");
  1244.       }
  1245.     }
  1246.     do {
  1247.       set_net_num(nn);
  1248.       i2=1;
  1249.       irt_name[0]=0;
  1250.       prt(2,get_string(711));
  1251.       helpl=34;
  1252.       if (!okmail)
  1253.     ch=onek("QI?-+G");
  1254.       else
  1255.         if (so())
  1256.             ch=onek("QSRIDAF?-+GEZPVUOLC");
  1257.         else
  1258.           if (cs())
  1259.             ch=onek("QSRIDAF?-+GZPVUOC");
  1260.           else
  1261.             ch=onek("QSRIDAF?+-G");
  1262.       switch (ch) {
  1263.     case 'E':
  1264.           if ((so()) && (okmail)) {
  1265.             b=readfile(&(m.msg),"EMAIL",&len);
  1266.             extract_out(b,len,m.title);
  1267.           }
  1268.           i2=0;
  1269.       break;
  1270.         case 'Q':
  1271.           done=1;
  1272.           break;
  1273.     case 'O':
  1274.           if ((cs()) && (okmail) && (m.fromuser!=65535) && (nn!=255)) {
  1275.         nl();
  1276.         prt(2,get_string(712));
  1277.             input(s,4);
  1278.             sprintf(s1,"%sFORM%s.MSG",syscfg.gfilesdir,s);
  1279.         if (exist(s1)) {
  1280.               load_workspace(s1,1);
  1281.               close(f);
  1282.               num_mail=((long) thisuser.feedbacksent) +
  1283.                        ((long) thisuser.emailsent) +
  1284.                        ((long) thisuser.emailnet);
  1285.               grab_quotes(NULL, NULL);
  1286.               if (m.fromuser!=65535)
  1287.                 email(m.fromuser,m.fromsys,0,m.anony);
  1288.               f=open(fn,O_RDWR | O_BINARY);
  1289.               num_mail1=((long) thisuser.feedbacksent) +
  1290.                         ((long) thisuser.emailsent) +
  1291.                         ((long) thisuser.emailnet);
  1292.  
  1293.               if (num_mail != num_mail1) {
  1294.                 strcpy(s,nam1(&thisuser,usernum,net_sysnum));
  1295.                 if (m.anony & anony_receiver)
  1296.                   strcpy(s,get_string(482));
  1297.                 strcat(s,get_string(713));
  1298.                 strcat(s,date());
  1299.                 if (!(m.status & status_source_verified))
  1300.                   ssm(m.fromuser,m.fromsys,s);
  1301.         /*delmail(f,mloc[curmail]);
  1302.         mloc[curmail]=-1;
  1303.         ++curmail;
  1304.         if (curmail>=mw)*/
  1305.                   done=1;
  1306.                 if (!wfc)
  1307.                   topscreen();
  1308.               } else {
  1309.                 sprintf(s,"%sINPUT.MSG",syscfg.tempdir);
  1310.                 unlink(s);
  1311.               }
  1312.         } else {
  1313.           nl();
  1314.           pl(get_string(89));
  1315.           nl();
  1316.               i2=0;
  1317.         }
  1318.       }
  1319.       break;
  1320.     case 'G':
  1321.           ansic(2);
  1322.           outstr(get_string(714));
  1323.           npr("%u) ? ",mw);
  1324.           ansic(0);
  1325.       input(s,3);
  1326.       i2=atoi(s);
  1327.       if ((i2>0) && (i2<=mw)) {
  1328.         curmail=i2-1;
  1329.         i2=1;
  1330.       } else
  1331.         i2=0;
  1332.       break;
  1333.         case 'I':
  1334.     case '+':
  1335.           ++curmail;
  1336.           if (curmail>=mw)
  1337.             done=1;
  1338.           break;
  1339.     case '-':
  1340.       if (curmail)
  1341.             --curmail;
  1342.       break;
  1343.         case 'R':
  1344.           break;
  1345.         case '?':
  1346.           printmenu(4);
  1347.           i2=0;
  1348.           break;
  1349.         case 'D':
  1350.       if (!okmail)
  1351.         break;
  1352.           strcpy(s,nam1(&thisuser,usernum,net_sysnum));
  1353.       if (m.anony & anony_receiver)
  1354.         strcpy(s,get_string(482));
  1355.           strcat(s,get_string(713));
  1356.           strcat(s,date());
  1357.           if ((!(m.status & status_source_verified)) && (nn!=255))
  1358.             ssm(m.fromuser,m.fromsys,s);
  1359.         case 'Z':
  1360.       if (!okmail)
  1361.         break;
  1362.           delmail(f,mloc[curmail]);
  1363.           mloc[curmail]=-1;
  1364.           ++curmail;
  1365.           if (curmail>=mw)
  1366.             done=1;
  1367.           if (!wfc)
  1368.             topscreen();
  1369.           break;
  1370.         case 'P':
  1371.           if (!okmail)
  1372.             break;
  1373.           purgemail(f,mloc,mw,&curmail,&m,&ss);
  1374.           if (curmail>=mw)
  1375.             done=1;
  1376.           if (!wfc)
  1377.             topscreen();
  1378.           break;
  1379.         case 'F':
  1380.       if (!okmail)
  1381.         break;
  1382.       if (m.status & status_multimail) {
  1383.         nl();
  1384.         pl(get_string(715));
  1385.         nl();
  1386.         break;
  1387.       }
  1388.           nl();
  1389.           nl();
  1390.           prt(2,get_string(716));
  1391.           input(s,30);
  1392.           parse_email_info(s, &un, &sy);
  1393.           if (un || sy) {
  1394.             if (forwardm(&un, &sy)) {
  1395.               pl(get_string(656));
  1396.             }
  1397.             if ((un==usernum) && (sy==0) && (!cs())) {
  1398.               pl(get_string(469));
  1399.               un=0;
  1400.             }
  1401.             if (un || sy) {
  1402.               if (sy) {
  1403.                 if (net_num_max>1) {
  1404.                   if (un) {
  1405.                     sprintf(s1,"%s #%u @%u",net_name, un, sy);
  1406.                   } else {
  1407.                     sprintf(s1,"%s %s @%u",net_name, net_email_name, sy);
  1408.                   }
  1409.                 } else {
  1410.                   if (un) {
  1411.                     sprintf(s1,"#%u @%u", un, sy);
  1412.                   } else {
  1413.                     sprintf(s1,"%s @%u", net_email_name, sy);
  1414.                   }
  1415.                 }
  1416.               } else {
  1417.                 set_net_num(nn);
  1418.                 read_user(un,&u);
  1419.                 strcpy(s1,nam1(&u,un,net_sysnum));
  1420.               }
  1421.               if (ok_to_mail(un, sy, 0)) {
  1422.                 ansic(5);
  1423.                 outstr(get_string(393));
  1424.                 npr("%s? ",s1);
  1425.                 if (yn()) {
  1426.                   i=net_num;
  1427.                   sprintf(s,"\r\n%s: %s", get_string(717),
  1428.                       nam1(&thisuser,usernum,net_sysnum));
  1429.                   set_net_num(nn);
  1430.                   lineadd(&m.msg,s,"EMAIL");
  1431.                   sprintf(s,"%s %s %s",
  1432.                       nam1(&thisuser,usernum,net_sysnum),
  1433.                       get_string(718), s1);
  1434.                   if (!(m.status & status_source_verified))
  1435.                     ssm(m.fromuser,m.fromsys,s);
  1436.                   set_net_num(i);
  1437.                   sysoplog(get_stringx(1,101));
  1438.                   --thisuser.waiting;
  1439.                   if (usernum==1)
  1440.                     --fwaiting;
  1441.                   outstr(get_string(720));
  1442.                   close(f);
  1443.                   if ((nn!=255) && ((status.net_version>=32) || (nn==net_num))) {
  1444.                     sendout_email(m.title, &m.msg, m.anony, un, sy, 1, m.fromuser, m.fromsys, 1, nn);
  1445.                   } else {
  1446.                     sendout_email(m.title, &m.msg, m.anony, un, sy, 1, usernum, net_sysnum, 1, net_num);
  1447.                   }
  1448.                   f=open(fn,O_RDWR | O_BINARY);
  1449.                   m.touser=0;
  1450.                   m.tosys=0;
  1451.                   m.daten=0xffffffff;
  1452.                   m.msg.storage_type=0;
  1453.                   m.msg.stored_as=0xffffffff;
  1454.                   lseek(f,((long) (mloc[curmail])) * (sizeof(mailrec)), SEEK_SET);
  1455.                   write(f,(void *)&m,sizeof(mailrec));
  1456.                   mloc[curmail]=-1;
  1457.                   ++curmail;
  1458.                   if (curmail>=mw)
  1459.                     done=1;
  1460.                   if (!wfc)
  1461.                     topscreen();
  1462.                   mailcheck=1;
  1463.                 }
  1464.               }
  1465.             }
  1466.           }
  1467.           break;
  1468.         case 'A':
  1469.         case 'S':
  1470.       if (!okmail)
  1471.         break;
  1472.            if(okfsed()){
  1473.         prt(5,"Quote message? ");
  1474.         if(yn()) {
  1475.         b=readfile(&(m.msg),"EMAIL",&len);
  1476.         quote_out(b,len,m.title);
  1477.         nl();
  1478.         strcpy(s, "C:\\WWIV\\GFILES\\QUOTE");
  1479.         if (s[0]) {
  1480.           nl();
  1481.           load_workspace(s,0);
  1482.          }
  1483.         }
  1484.            }
  1485.  
  1486.           close(f);
  1487.           num_mail=((long) thisuser.feedbacksent) +
  1488.                    ((long) thisuser.emailsent) +
  1489.                    ((long) thisuser.emailnet);
  1490.           if (nn==255) {
  1491.             pl(get_string(679));
  1492.             i2=0;
  1493.             break;
  1494.           } else if (m.fromuser!=65535) {
  1495.             grab_quotes(&(m.msg),"EMAIL");
  1496.             email(m.fromuser,m.fromsys,0,m.anony);
  1497.             grab_quotes(NULL, NULL);
  1498.           }
  1499.           f=open(fn,O_RDWR | O_BINARY);
  1500.           num_mail1=((long) thisuser.feedbacksent) +
  1501.                     ((long) thisuser.emailsent) +
  1502.                     ((long) thisuser.emailnet);
  1503.           if (ch=='A') {
  1504.             if (num_mail!=num_mail1) {
  1505.               strcpy(s,nam1(&thisuser,usernum,net_sysnum));
  1506.               if (m.anony & anony_receiver)
  1507.                 strcpy(s,get_string(482));
  1508.               strcat(s,get_string(713));
  1509.               strcat(s,date());
  1510.               if (!(m.status & status_source_verified))
  1511.                 ssm(m.fromuser,m.fromsys,s);
  1512.               delmail(f,mloc[curmail]);
  1513.               mloc[curmail]=-1;
  1514.               ++curmail;
  1515.               if (curmail>=mw)
  1516.                 done=1;
  1517.               if (!wfc)
  1518.                 topscreen();
  1519.             } else {
  1520.               nl();
  1521.               pl(get_string(721));
  1522.               nl();
  1523.               i2=0;
  1524.             }
  1525.           } else {
  1526.             if (num_mail != num_mail1) {
  1527.               ++curmail;
  1528.               if (curmail>=mw)
  1529.                 done=1;
  1530.               if (!wfc)
  1531.                 topscreen();
  1532.             }
  1533.           }
  1534.           break;
  1535.         case 'U':
  1536.         case 'V':
  1537.         case 'C':
  1538.       if (!okmail)
  1539.         break;
  1540.           if ((m.fromsys==0) && (cs()) && (m.fromuser!=65535))
  1541.             if (ch=='V')
  1542.               valuser(m.fromuser);
  1543.             else if (ch=='U')
  1544.               uedit(m.fromuser,0);
  1545.             else
  1546.               uedit(m.fromuser,3);
  1547.       else
  1548.         if (cs()) {
  1549.           nl();
  1550.           pl(get_string(722));
  1551.           nl();
  1552.         }
  1553.           i2=0;
  1554.           break;
  1555.         case 'L':
  1556.           if (!so())
  1557.             break;
  1558.           nl();
  1559.           prt(2,get_string(7));
  1560.           input(s,50);
  1561.           if (s[0]) {
  1562.             nl();
  1563.             prt(5,get_string(17));
  1564.             if (yn()) {
  1565.               nl();
  1566.               load_workspace(s,0);
  1567.             } else {
  1568.               nl();
  1569.               load_workspace(s,1);
  1570.             }
  1571.           }
  1572.           break;
  1573.       }
  1574.     } while ((!i2) && (!hangup));
  1575.   } while ((!hangup) && (!done));
  1576.   close(f);
  1577. }
  1578.  
  1579.  
  1580. void remove_post(void)
  1581. {
  1582.   int i,i1,any,abort;
  1583.   char s[161];
  1584.  
  1585.   iscan(cursub);
  1586.   if (curlsub<0) {
  1587.     nl();
  1588.     pl(get_string(668));
  1589.     nl();
  1590.     return;
  1591.   }
  1592.   any=0;
  1593.   abort=0;
  1594.   nl();
  1595.   nl();
  1596.   outstr(get_string(723));
  1597.   pl(subboards[curlsub].name);
  1598.   nl();
  1599.   for (i=1; (i<=nummsgs) && (!abort); i++) {
  1600.     if ((msgs[i].ownersys==0) && (msgs[i].owneruser==usernum)) {
  1601.       any=1;
  1602.       sprintf(s,"%u: %s",i,msgs[i].title);
  1603.       pla(s,&abort);
  1604.     }
  1605.   }
  1606.   if (!any) {
  1607.     pl(get_string(5));
  1608.     if (!cs())
  1609.       return;
  1610.   }
  1611.   nl();
  1612.   prt(2,get_string(724));
  1613.   input(s,3);
  1614.   i=atoi(s);
  1615.   if ((i>0) && (i<=nummsgs)) {
  1616.     if (((msgs[i].ownersys==0) && (msgs[i].owneruser==usernum)) || (lcs())) {
  1617.       sprintf(s,get_stringx(1,39),msgs[i].title,subboards[curlsub].name);
  1618.       sysoplog(s);
  1619.       delete(i);
  1620.       savebase();
  1621.       nl();
  1622.       pl(get_string(725));
  1623.       --thisuser.msgpost;
  1624.       npr("\r\n1Your p/c ratio is now %-5.3f",post_ratio());
  1625.       --thisuser.gold;
  1626.       nl();
  1627.     }
  1628.   }
  1629. }
  1630.  
  1631.  
  1632.  
  1633. int external_edit(char *fn1, char *direc, int ednum, int numlines, char *dest, char *title, int flags)
  1634. {
  1635.   char s[255],s1[128],fn[128],s2[128],s3[81],sx1[21],sx2[21],sx3[21],ch;
  1636.   int i,i1,i2,r,w,filethere,mod,newtl;
  1637.   struct ftime ftimep,ftimep1;
  1638.   FILE *f;
  1639.  
  1640.   unlink("editor.inf");
  1641.   unlink("result.ed");
  1642.  
  1643.   if ((ednum>=numed) || (!okansi())) {
  1644.     nl();
  1645.     pl(get_string(726));
  1646.     nl();
  1647.     return(0);
  1648.   }
  1649.   i1=0;
  1650.   for (i2=0; i2<81; i2++) {
  1651.     i1+=editors[ednum].filename[i2];
  1652.     i1+=editors[ednum].filenamecon[i2];
  1653.   }
  1654.   if (incom)
  1655.     strcpy(s1,(editors[ednum].filename));
  1656.   else
  1657.     strcpy(s1,(editors[ednum].filenamecon));
  1658.   if (s1[0]==0) {
  1659.     nl();
  1660.     pl(get_string(726));
  1661.     nl();
  1662.     return(0);
  1663.   }
  1664.   strcpy(s3,fn1);
  1665.   stripfn1(s3);
  1666.   if (direc[0]) {
  1667.     cd_to(direc);
  1668.     get_dir(fn,1);
  1669.     cd_to(cdir);
  1670.   } else
  1671.     fn[0]=0;
  1672.   strcat(fn,s3);
  1673.   filethere=exist(fn);
  1674.   if (filethere) {
  1675.     i=open(fn,O_RDONLY | O_BINARY);
  1676.     getftime(i,&ftimep);
  1677.     close(i);
  1678.   }
  1679.   itoa(thisuser.screenchars,sx1,10);
  1680.   if (screenlinest>defscreenbottom-topline)
  1681.     newtl=0;
  1682.   else
  1683.     newtl=topline;
  1684.   if (using_modem)
  1685.     itoa(thisuser.screenlines,sx2,10);
  1686.   else
  1687.     itoa(defscreenbottom+1-newtl,sx2,10);
  1688.   itoa(numlines,sx3,10);
  1689.   stuff_in(s,s1,fn,sx1,sx2,sx3,"");
  1690.   if ((f=fopen("EDITOR.INF","wt"))!=NULL) {
  1691.     fprintf(f,"%s\n%s\n%u\n%s\n%s\n%u\n%u\n%u\n",
  1692.       title,
  1693.       dest,
  1694.       usernum,
  1695.       thisuser.name,
  1696.       thisuser.realname,
  1697.       thisuser.sl,
  1698.       flags,
  1699.       topline);
  1700.     fclose(f);
  1701.   }
  1702.   if (flags&1) {
  1703.     /* disable tag lines */
  1704.     f=fopen("disable.tag","w");
  1705.     if (f) fclose(f);
  1706.   } else {
  1707.     unlink("disable.tag");
  1708.   }
  1709.   if (!irt[0]) {
  1710.     unlink("quotes.txt");
  1711.     unlink("quotes.ind");
  1712.   }
  1713.  
  1714.   in_fsed=1;
  1715.   full_external(s,0,1);
  1716.   in_fsed=0;
  1717.   unlink("editor.inf");
  1718.   unlink("disable.tag");
  1719.   unlink("quotes.txt");
  1720.   unlink("quotes.ind");
  1721.   if (!wfc)
  1722.     topscreen();
  1723.   mod=0;
  1724.   if (!filethere) {
  1725.     mod=exist(fn);
  1726.   } else {
  1727.     i=open(fn,O_RDONLY | O_BINARY);
  1728.     getftime(i,&ftimep1);
  1729.     close(i);
  1730.     if ((ftimep.ft_year!=ftimep1.ft_year) ||
  1731.         (ftimep.ft_month!=ftimep1.ft_month) ||
  1732.         (ftimep.ft_day!=ftimep1.ft_day) ||
  1733.         (ftimep.ft_hour!=ftimep1.ft_hour) ||
  1734.         (ftimep.ft_min!=ftimep1.ft_min) ||
  1735.         (ftimep.ft_tsec!=ftimep1.ft_tsec))
  1736.       mod=1;
  1737.   }
  1738.   return(mod);
  1739. }
  1740.  
  1741. #define LINELEN 79
  1742.  
  1743. #define NL {if (!cp) fwrite(pfx,1,pfxlen,f);fwrite("\r\n",1,2,f); cp=ns=ctlc=0;}
  1744. #define FLSH {if (ss1) { if (cp && (l3+cp>=LINELEN)) NL else if (ns) cp+=fwrite(" ",1,1,f);\
  1745.               if (!cp) {if (ctld) fprintf(f,"\x4%c",ctld);ctld=0;cp=fwrite(pfx,1,pfxlen,f);}\
  1746.               fwrite(ss1,1,l2,f); cp+=l3; ss1=NULL;l2=l3=0;ns=1;}}
  1747.  
  1748. void grab_quotes(messagerec *m, char *aux)
  1749. {
  1750.   char *ss,*ss1;
  1751.   long l,l1,l2,l3;
  1752.   FILE *f;
  1753.   char *pfx;
  1754.   int cp=0,ctla=0,ctlc=0,ns=0,ctld=0,ff;
  1755.   int pfxlen;
  1756.  
  1757.   pfx=get_stringx(1,102);
  1758.   pfxlen=strlen(pfx);
  1759.  
  1760.   unlink("quotes.txt");
  1761.   unlink("quotes.ind");
  1762.   if (quotes_nrm)
  1763.     farfree(quotes_nrm);
  1764.   if (quotes_ind)
  1765.     farfree(quotes_ind);
  1766.  
  1767.   quotes_nrm=quotes_ind=NULL;
  1768.   quotes_nrm_l=quotes_ind_l=0;
  1769.  
  1770.   if (m && aux) {
  1771.  
  1772.     ss=readfile(m, aux, &l);
  1773.  
  1774.     if (ss) {
  1775.       quotes_nrm=ss;
  1776.       quotes_nrm_l=l;
  1777.  
  1778.       f=fopen("quotes.txt", "wb");
  1779.       if (f) {
  1780.         fwrite(ss, 1, l, f);
  1781.         fclose(f);
  1782.       }
  1783.  
  1784.       f=fopen("quotes.ind", "wb");
  1785.       if (f) {
  1786.         l3=l2=0;
  1787.         ss1=NULL;
  1788.         for (l1=0; l1<l; l1++) {
  1789.           if (ctld==-1)
  1790.             ctld=ss[l1];
  1791.           else switch(ss[l1]) {
  1792.             case 1:
  1793.               ctla=1;
  1794.               break;
  1795.             case 2:
  1796.               break;
  1797.             case 3:
  1798.               if (!ss1)
  1799.                 ss1=ss+l1;
  1800.               l2++;
  1801.               ctlc=1;
  1802.               break;
  1803.             case 4:
  1804.               ctld=-1;
  1805.               break;
  1806.             case '\n':
  1807.               if (ctla) {
  1808.                 ctla=0;
  1809.               } else {
  1810.                 FLSH;
  1811.                 NL;
  1812.               }
  1813.               break;
  1814.             case ' ':
  1815.             case '\r':
  1816.               if (ss1) {
  1817.                 FLSH;
  1818.               } else {
  1819.                 if (ss[l1]==' ') {
  1820.                   if (cp+1>=LINELEN)
  1821.                     NL;
  1822.                   if (!cp) {
  1823.                     if (ctld)
  1824.                       fprintf(f,"\x4%c",ctld);
  1825.                     ctld=0;
  1826.                     cp=fwrite(pfx,1,pfxlen,f);
  1827.                   }
  1828.                   cp++;
  1829.                   fwrite(" ",1,1,f);
  1830.                 }
  1831.               }
  1832.               break;
  1833.             default:
  1834.               if (!ss1)
  1835.                 ss1=ss+l1;
  1836.               l2++;
  1837.               if (ctlc)
  1838.                 ctlc=0;
  1839.               else
  1840.                 l3++;
  1841.               break;
  1842.           }
  1843.         }
  1844.         FLSH;
  1845.         if (cp)
  1846.           fwrite("\r\n",1,2,f);
  1847.         fclose(f);
  1848. #ifdef SAVE_IN_MEM
  1849.         ff=open("quotes.ind",O_RDONLY|O_BINARY);
  1850.         if (ff>0) {
  1851.           quotes_ind_l=filelength(ff);
  1852.           quotes_ind=(char *)farmalloc(quotes_ind_l);
  1853.           if (quotes_ind) {
  1854.             read(ff,quotes_ind, quotes_ind_l);
  1855.           } else
  1856.             quotes_ind_l=0;
  1857.           close(ff);
  1858.         }
  1859. #else
  1860.         farfree(quotes_nrm);
  1861.         quotes_nrm=NULL;
  1862.         quotes_nrm_l=0;
  1863. #endif
  1864.       }
  1865.     }
  1866.   }
  1867. }
  1868.