home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / MSGBASE.C < prev    next >
Text File  |  1992-06-16  |  38KB  |  1,695 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 <mem.h>
  22.  
  23.  
  24. #define ALLOW_FULLSCREEN 1
  25. #define EMAIL_STORAGE 2
  26.  
  27. /****************************************************************************/
  28. void describe_area_code(int areacode, char *description)
  29. {
  30.   int f,done=0,i;
  31.   char s[81],*ss,*ss1;
  32.  
  33.   description[0]=0;
  34.   sprintf(s,"%sREGIONS.DAT",syscfg.datadir);
  35.   f=open(s,O_RDWR | O_TEXT);
  36.   if (f<1)
  37.     return;
  38.   ss=malloca(filelength(f));
  39.   i=read(f,ss,filelength(f));
  40.   ss[i]=0;
  41.   close(f);
  42.   ss1=strtok(ss,"\n");
  43.   while (ss1 && (!done)) {
  44.     i=atoi(ss1);
  45.     if (i) {
  46.       if (i==areacode)
  47.         done=1;
  48.     } else
  49.       strcpy(description,ss1);
  50.     ss1=strtok(NULL,"\n");
  51.   }
  52.  
  53.   farfree(ss);
  54. }
  55.  
  56.  
  57.  
  58. /****************************************************************************/
  59. static char origin_str[81];
  60.  
  61. void setorigin(int sysnum, int usernum)
  62. {
  63.   int i;
  64.   char s[81],ch;
  65.   net_system_list_rec *csne;
  66.  
  67.   origin_str[0]=0;
  68.  
  69.   if (sysnum) {
  70.     csne=next_system(sysnum);
  71.     if (csne) {
  72.       ch=' ';
  73.       if (usernum==1) {
  74.         if (csne->other & other_net_coord)
  75.           ch='&';
  76.         else if (csne->other & other_group_coord)
  77.           ch='%';
  78.         else if (csne->other & other_coordinator)
  79.           ch='^';
  80.       }
  81.  
  82.       describe_area_code(atoi(csne->phone),s);
  83.       if (s[0])
  84.         sprintf(origin_str,"%c%s (%s)",ch,csne->name,s);
  85.       else
  86.         sprintf(origin_str,"%c%s [%s]",ch,csne->name,csne->phone);
  87.  
  88.  
  89.     } else
  90.       strcpy(origin_str,"3 Dunno where it came from.");
  91.   }
  92. }
  93.  
  94.  
  95. int okfsed()
  96. {
  97.   int ok;
  98.  
  99.   ok=ALLOW_FULLSCREEN;
  100.   if (!okansi())
  101.     ok=0;
  102.   if (!thisuser.defed)
  103.     ok=0;
  104.   if (thisuser.defed>numed)
  105.     ok=0;
  106.   return(ok);
  107. }
  108.  
  109.  
  110. void remove_link(messagerec *m1, char *aux)
  111. {
  112.   messagerec m;
  113.   char s[81],s1[81];
  114.   int f;
  115.   long csec,nsec;
  116.  
  117.   m=*m1;
  118.   strcpy(s,syscfg.msgsdir);
  119.   switch(m.storage_type) {
  120.     case 0:
  121.     case 1:
  122.       ltoa(m.stored_as,s1,16);
  123.       if (m.storage_type==1) {
  124.         strcat(s,aux);
  125.         strcat(s,"\\");
  126.       }
  127.       strcat(s,s1);
  128.       unlink(s);
  129.       break;
  130.     case 2:
  131.       f=open_file(aux);
  132.       csec=m.stored_as;
  133.       while ((csec>0) && (csec<2048)) {
  134.         nsec=(long) gat[csec];
  135.     gat[csec]=0;
  136.     csec=nsec;
  137.       }
  138.       lseek(f,0L,SEEK_SET);
  139.       write(f,(void *)gat,4096);
  140.       close(f);
  141.       break;
  142.     default:
  143.       /* illegal storage type */
  144.       break;
  145.   }
  146. }
  147.  
  148.  
  149. int open_file(char *fn)
  150. {
  151.   int f,i;
  152.   char s[81];
  153.  
  154.   sprintf(s,"%s%s.DAT",syscfg.msgsdir,fn);
  155.   f=open(s,O_RDWR | O_BINARY);
  156.   if (f<0) {
  157.     f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  158.     for (i=0; i<2048; i++)
  159.       gat[i]=0;
  160.     write(f,(void *)gat,4096);
  161.     strcpy(gatfn,fn);
  162.     chsize(f,4096L + (75L * 1024L));
  163.   }
  164.   if (strcmp(gatfn,fn)) {
  165.     lseek(f,0L,SEEK_SET);
  166.     read(f,(void *)gat,4096);
  167.     strcpy(gatfn,fn);
  168.   }
  169.   return(f);
  170. }
  171.  
  172.  
  173.  
  174. void savefile(char *b, long l1, messagerec *m1, char *aux)
  175. {
  176.   int f,gatp,i5,i4,gati[128];
  177.   messagerec m;
  178.   char s[81],s1[81];
  179.  
  180.   m=*m1;
  181.   switch(m.storage_type) {
  182.     case 0:
  183.     case 1:
  184.       m.stored_as=status.qscanptr++;
  185.       save_status();
  186.       ltoa(m.stored_as,s1,16);
  187.       strcpy(s,syscfg.msgsdir);
  188.       if (m.storage_type==1) {
  189.         strcat(s,aux);
  190.         strcat(s,"\\");
  191.       }
  192.       strcat(s,s1);
  193.       f=open(s,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
  194.       write(f, (void *)b,l1);
  195.       close(f);
  196.       break;
  197.     case 2:
  198.       f=open_file(aux);
  199.       gatp=0;
  200.       i5=(int) ((l1 + 511L)/512L);
  201.       i4=1;
  202.       while ((gatp<i5) && (i4<2048)) {
  203.         if (gat[i4]==0)
  204.           gati[gatp++]=i4;
  205.         ++i4;
  206.       }
  207.       gati[gatp]=-1;
  208.       for (i4=0; i4<i5; i4++) {
  209.         lseek(f,4096L + 512L * (long)(gati[i4]),SEEK_SET);
  210.         write(f,(void *)(&b[i4*512]),512);
  211.         gat[gati[i4]]=gati[i4+1];
  212.       }
  213.       lseek(f,0L,SEEK_SET);
  214.       write(f,(void *)gat,4096);
  215.       close(f);
  216.       m.stored_as=(long) gati[0];
  217.       break;
  218.     case 255:
  219.       f=open(aux,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
  220.       write(f, (void *)b,l1);
  221.       close(f);
  222.       break;
  223.     default:
  224.       sprintf(s,"Illegal storage type of %u on save!",m.storage_type);
  225.       pl(s);
  226.       break;
  227.   }
  228.   farfree((void *)b);
  229.   *m1=m;
  230. }
  231.  
  232.  
  233. char *readfile(messagerec *m1, char *aux, long *l)
  234. {
  235.   int f,i,i1,csec;
  236.   long l1,l2;
  237.   char *b,s[81],s1[81];
  238.   messagerec m;
  239.  
  240.   *l=0L;
  241.   m=*m1;
  242.   switch(m.storage_type) {
  243.     case 0:
  244.     case 1:
  245.       strcpy(s,syscfg.msgsdir);
  246.       ltoa(m.stored_as,s1,16);
  247.       if (m.storage_type==1) {
  248.         strcat(s,aux);
  249.         strcat(s,"\\");
  250.       }
  251.       strcat(s,s1);
  252.       f=open(s,O_RDONLY | O_BINARY);
  253.       if (f==-1) {
  254.     *l=0L;
  255.         return(NULL);
  256.       }
  257.       l1=filelength(f);
  258.       if ((b=malloca(l1))==NULL) {
  259.         close(f);
  260.         return(NULL);
  261.       }
  262.       read(f,(void *)b,l1);
  263.       close(f);
  264.       *l=l1;
  265.       break;
  266.     case 2:
  267.       f=open_file(aux);
  268.       csec=m.stored_as;
  269.       l1=0;
  270.       while ((csec>0) && (csec<2048)) {
  271.     l1+=512L;
  272.     csec=gat[csec];
  273.       }
  274.       if (!l1) {
  275.         nl();
  276.         pl("No message found.");
  277.         nl();
  278.         return(NULL);
  279.       }
  280.       if ((b=malloca(l1))==NULL)
  281.         return(NULL);
  282.       csec=m.stored_as;
  283.       l1=0;
  284.       while ((csec>0) && (csec<2048)) {
  285.         lseek(f,4096L + 512L*csec,SEEK_SET);
  286.         l1+=(long)read(f,(void *)(&(b[l1])),512);
  287.     csec=gat[csec];
  288.       }
  289.       close(f);
  290.       l2=l1-512;
  291.       while ((l2<l1) && (b[l2]!=26))
  292.     ++l2;
  293.       *l=l2;
  294.       break;
  295.     case 255:
  296.       f=open(aux,O_RDONLY | O_BINARY);
  297.       if (f==-1) {
  298.     *l=0L;
  299.         return(NULL);
  300.       }
  301.       l1=filelength(f);
  302.       if ((b=malloca(l1+256L))==NULL)
  303.         return(NULL);
  304.       read(f,(void *)b,l1);
  305.       close(f);
  306.       *l=l1;
  307.       break;
  308.     default:
  309.       /* illegal storage type */
  310.       *l=0L;
  311.       b=NULL;
  312.       break;
  313.   }
  314.   return(b);
  315. }
  316.  
  317.  
  318. void change_storage(messagerec *oldm, char *olda, messagerec *newm, char *newa)
  319. {
  320.   long len;
  321.   char *b;
  322.  
  323.   b=readfile(oldm,olda,&len);
  324.   remove_link(oldm,olda);
  325.   savefile(b,len,newm,newa);
  326. }
  327.  
  328.  
  329. void load_workspace(char *fnx, int no_edit)
  330. {
  331.   int i,i5;
  332.   long l;
  333.   char *b,s[81];
  334.  
  335.   i5=open(fnx,O_RDONLY | O_BINARY);
  336.   if (i5<1) {
  337.     nl();
  338.     pl("File not found.");
  339.     nl();
  340.     return;
  341.   }
  342.   l=filelength(i5);
  343.   if ((b=malloca(l+1024))==NULL) {
  344.     close(i5);
  345.     return;
  346.   }
  347.   read(i5, (void *) b,l);
  348.   close(i5);
  349.   if (b[l-1]!=26)
  350.     b[l++]=26;
  351.   sprintf(s,"%sINPUT.MSG",syscfg.tempdir);
  352.   i5=open(s,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
  353.   write(i5, (void *)b,l);
  354.   close(i5);
  355.   farfree(b);
  356.   if ((no_edit) || (!okfsed()))
  357.     use_workspace=1;
  358.   else
  359.     use_workspace=0;
  360.   nl();
  361.   pl("1Yes, the file is loaded.");
  362.   nl();
  363.   if (!use_workspace)
  364.     pl("3Ok, you can edit.");
  365.  
  366. }
  367.  
  368.  
  369. void osan(char *s, int *abort, int *next)
  370. {
  371.   int i;
  372.  
  373.   i=0;
  374.   checkhangup();
  375.   if (hangup)
  376.     *abort=1;
  377.   checka(abort,next);
  378.   while ((s[i]) && (!(*abort))) {
  379.     outchr(s[i++]);
  380.     checka(abort,next);
  381.   }
  382. }
  383.  
  384.  
  385.  
  386. void addline(char *b, char *s, long *ll)
  387. {
  388.   strcpy(&(b[*ll]),s);
  389.   *ll +=strlen(s);
  390.   strcpy(&(b[*ll]),"\r\n");
  391.   *ll += 2;
  392. }
  393.  
  394.  
  395. #define LEN 161
  396.  
  397. void stuff(char *s, char *old, char *new)
  398. {
  399.   char s1[LEN],*ss;
  400.  
  401.   if (strlen(s)-strlen(old)+strlen(new)>=LEN)
  402.     return;
  403.   ss=strstr(s,old);
  404.   if (ss==NULL)
  405.     return;
  406.   ss[0]=0;
  407.   sprintf(s1,"%s%s%s",s,new,ss+strlen(old));
  408.   strcpy(s,s1);
  409. }
  410.  
  411.  
  412. void inmsg(messagerec *m1, char *title, int *anony, int needtitle, char *aux, int fsed)
  413. {
  414.   char s[LEN],s1[LEN],s2[LEN],ro[81],fnx[81],chx,*ss,*ss1;
  415.   int maxli,curli,done,save,savel,i,i1,i2,i3,i4,i5,f,setanon,gati[50],gatp;
  416.   messagerec m;
  417.   long ll,l1;
  418.   char *lin, *b;
  419.   int real_name=0;
  420.  
  421.   if ((fsed!=0) && (!okfsed()))
  422.     fsed=0;
  423.   sprintf(fnx,"%sINPUT.MSG",syscfg.tempdir);
  424.   if (fsed)
  425.     fsed=1;
  426.   if (use_workspace) {
  427.     if (!exist(fnx))
  428.       use_workspace=0;
  429.     else
  430.       fsed=2;
  431.   }
  432.   done=0;
  433.   setanon=0;
  434.   save=0;
  435.   curli=0;
  436.   m=*m1;
  437.   if (actsl<45)
  438.     maxli=30;
  439.   else
  440.     if (actsl<60)
  441.       maxli=50;
  442.     else
  443.       if (actsl<80)
  444.         maxli=60;
  445.       else
  446.         maxli=80;
  447.   if (!fsed) {
  448.     if ((lin=malloca((long)(maxli+10)*LEN))==NULL) {
  449.       m1->stored_as=0xffffffff;
  450.       return;
  451.     }
  452.     for (i=0; i<maxli; i++)
  453.       lin[i*LEN]=0;
  454.     ro[0]=0;
  455.   }
  456.  
  457.   nl();
  458.   helpl=6;
  459.   if (okansi()) {
  460.     prt(7,"[1Title7]3: ");
  461.     inli(title,ro,70,1);
  462.   } else {
  463.     pl("   7    ══════════════════════3The Devil's Doorknob7══════════════════");
  464.     outstr("7[1Title7]3: ");
  465.     inli(title,ro,70,1);
  466.   }
  467.   if ((title[0]==0) && (needtitle)) {
  468.     pl("6Aborted.");
  469.     m.stored_as=0xffffffff;
  470.     *m1=m;
  471.     if (!fsed)
  472.       farfree((void *)lin);
  473.     return;
  474.   }
  475.  
  476.   if (!fsed) {
  477.     sprintf(s,"7Enter message now, max %u lines.",maxli);
  478.     pl(s);
  479.     pl("5Enter '/HELP' for help.");
  480.     strcpy(s,"7══════════════════════════════3The Devil's Doorknob7══════════════════════════════");
  481.     s[thisuser.screenchars]=0;
  482.     pl(s);
  483.  
  484.     while (!done) {
  485.       helpl=27;
  486.       inli(s,ro,160,1);
  487.       if (hangup)
  488.         done=1;
  489.       savel=1;
  490.       if (s[0]=='/') {
  491.         if (stricmp(s,"/HELP")==0) {
  492.           savel=0;
  493.           printmenu(2);
  494.         }
  495.         if (stricmp(s,"/LI")==0) {
  496.           savel=0;
  497.       prt(5,"You wanna see line numbers? ");
  498.       i1=yn();
  499.       i2=0;
  500.       for (i=0; (i<curli) && (!i2); i++) {
  501.         if (i1)
  502.           npr("%d:\r\n",i+1);
  503.         strcpy(s1,&(lin[i*LEN]));
  504.         i3=strlen(s1);
  505.         if (s1[i3-1]==1)
  506.           s1[i3-1]=0;
  507.         if (s1[0]==2) {
  508.           strcpy(s1,&(s1[1]));
  509.           i5=0;
  510.           for(i4=0; i4<strlen(s1); i4++)
  511.         if ((s1[i4]==8) || (s1[i4]==3))
  512.           --i5;
  513.         else
  514.           ++i5;
  515.           for (i4=0; (i4<(thisuser.screenchars-i5)/2) && (!i2); i4++)
  516.         osan(" ",&i2,&i1);
  517.         }
  518.         pla(s1,&i2);
  519.       }
  520.       nl();
  521.       pl("1Ok, go ahead...");
  522.     }
  523.     if ((stricmp(s,"/ES")==0) || (stricmp(s,"/S")==0)) {
  524.           save=1;
  525.           done=1;
  526.       savel=0;
  527.       outstr("1Would you like a reply5?");
  528.       if (yn()) {
  529.         curli++;
  530.         strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1Answer this or die."); }
  531.       else {
  532.         curli++;
  533.         strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1No Response Needed."); }
  534.     }
  535.         if ((stricmp(s,"/ESY")==0) || (stricmp(s,"/SY")==0)) {
  536.           save=1;
  537.           done=1;
  538.           savel=0;
  539.       setanon=1;
  540.       outstr("1Would you like a reply5?");
  541.       if (yn()) {
  542.         curli++;
  543.         strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1Answer this or die."); }
  544.       else {
  545.         curli++;
  546.         strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1No Response Needed."); }
  547.     }
  548.         if ((stricmp(s,"/ESN")==0) || (stricmp(s,"/SN")==0)) {
  549.           save=1;
  550.           done=1;
  551.           savel=0;
  552.       setanon=-1;
  553.       outstr("1Would you like a reply5?");
  554.       if (yn()) {
  555.         curli++;
  556.         strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1Answer this or die."); }
  557.       else {
  558.         curli++;
  559.         strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1No Response Needed."); }
  560.     }
  561.     if (stricmp(s,"/ABT")==0) {
  562.       done=1;
  563.       savel=0;
  564.     }
  565.         if (stricmp(s,"/CLR")==0) {
  566.           savel=0;
  567.           curli=0;
  568.       pl("1Message cleared... Start over...");
  569.       nl();
  570.     }
  571.     if (stricmp(s,"/RL")==0) {
  572.       savel=0;
  573.       if (curli) {
  574.         --curli;
  575.         pl("1Replace:");
  576.       } else {
  577.         pl("1Nothing to replace.");
  578.       }
  579.         }
  580.         if (stricmp(s,"/TI")==0) {
  581.           savel=0;
  582.           helpl=26;
  583.           if (okansi()) {
  584.         prt(7,"[1Title7]3: ");
  585.         inli(title,ro,70,1);
  586.       } else {
  587.         pl("       7════════════════════════3The Devil's Doorknob7════════════════");
  588.         outstr("7[1Title7]3: ");
  589.         inli(title,ro,70,1);
  590.       }
  591.       pl("1Ok, go ahead...");
  592.       nl();
  593.     }
  594.     strcpy(s1,s);
  595.     s1[3]=0;
  596.     if (stricmp(s1,"/C:")==0) {
  597.       s1[0]=2;
  598.       strcpy((&s1[1]),&(s[3]));
  599.       strcpy(s,s1);
  600.     }
  601.     if ((stricmp(s1,"/SU")==0) && (s[3]=='/') && (curli)) {
  602.       strcpy(s1,&(s[4]));
  603.           ss=strstr(s1,"/");
  604.           if (ss) {
  605.             ss1=&(ss[1]);
  606.             ss[0]=0;
  607.             stuff(&(lin[(curli-1)*LEN]),s1,ss1);
  608.         pl("1Last line:");
  609.         pl(&(lin[(curli-1)*LEN]));
  610.         pl("1Ok, go ahead...");
  611.       }
  612.       savel=0;
  613.     }
  614.       }
  615.       if (savel) {
  616.         strcpy(&(lin[(curli++)*LEN]),s);
  617.         if (curli==maxli) {
  618.           nl();
  619.       pl("6-= No more lines =-");
  620.       pl("/ES to save");
  621.       nl();
  622.       --curli;
  623.     }
  624.       }
  625.     }
  626.     if (curli==0)
  627.       save=0;
  628. } else {
  629.     if (fsed==1) {
  630.       save=external_edit("INPUT.MSG",syscfg.tempdir,(int) (thisuser.defed)-1,maxli);
  631.     } else {
  632.       save=exist(fnx);
  633.       if (save) {
  634.     pl("3Reading in file...");
  635.       }
  636.       use_workspace=0;
  637.     }
  638.   }
  639.  
  640.  
  641.   if (save) {
  642.     switch(*anony) {
  643.       case 0: /* no anony */
  644.     *anony=0;
  645.         break;
  646.       case anony_enable_anony:
  647.         if (setanon) {
  648.           if (setanon==1)
  649.             *anony=anony_sender;
  650.           else
  651.             *anony=0;
  652.         } else {
  653.           prt(5,"Anonymous? ");
  654.           if (yn())
  655.             *anony=anony_sender;
  656.           else
  657.             *anony=0;
  658.         }
  659.         break;
  660.       case anony_enable_dear_abby:
  661.     nl();
  662.     npr("117.3 %s\r\n",nam(&thisuser,usernum));
  663.     pl("127.3 Just a lost soul swimmin' in a fish bowl");
  664.     pl("137.3 Problemed Person");
  665.     nl();
  666.     prt(5,"Which? ");
  667.     chx=onek("\r123");
  668.     switch(chx) {
  669.       case '\r':
  670.       case '1':
  671.         *anony=0;
  672.         break;
  673.       case '2':
  674.         *anony=anony_sender_da;
  675.         break;
  676.       case '3':
  677.         *anony=anony_sender_pp;
  678.     }
  679.         break;
  680.       case anony_force_anony:
  681.         *anony=anony_sender;
  682.         break;
  683.       case anony_real_name:
  684.         real_name=1;
  685.         *anony=0;
  686.         break;
  687.     }
  688.     outstr("3Saving...\r\n");
  689.     if (fsed) {
  690.       i5=open(fnx,O_RDONLY | O_BINARY);
  691.       l1=filelength(i5);
  692.     } else {
  693.       l1=0;
  694.       for (i5=0; i5<curli; i5++) {
  695.     l1 += strlen(&(lin[i5*LEN]));
  696.     l1 += 2;
  697.       }
  698.     }
  699.     l1 += 1024;
  700.     if ((b=malloca(l1))==NULL) {
  701.       farfree(lin);
  702.       pl("Out of memory.");
  703.       m1->stored_as=0xffffffff;
  704.       return;
  705.     }
  706.  
  707.     l1=0;
  708.     if (real_name){
  709.       addline(b,thisuser.realname,&l1);
  710.    } else {
  711.       /*addline(b,nam1(&thisuser,usernum,syscfg.systemnumber),&l1);*/
  712.       strcpy(s,nam1(&thisuser,usernum,syscfg.systemnumber));
  713.       if (actsl<255)
  714.         sprintf(s1," 1[5Immortal1]");
  715.       if (actsl<70)
  716.         sprintf(s1," 1[5Average Joe Schmoe1]");
  717.       if (actsl<50)
  718.         sprintf(s1," 1[5No Comment1]");
  719.       if (actsl<11)
  720.         sprintf(s1," 1[5New User1]");
  721.       if (usernum==1)
  722.         sprintf(s1," 1[5Goddess1]");
  723.       if (usernum==4)
  724.         sprintf(s1," 1[5Enzyme Boy1]");
  725.       if (usernum==2)
  726.         sprintf(s1," 1[5God1]");
  727.       if (usernum==7)
  728.         sprintf(s1," 1[5Net Coordinator1]");
  729.       if (usernum==56)
  730.         sprintf(s1," 1[5Oh Baby!1]");
  731.       strcat(s,s1);
  732.       addline(b,s,&l1);}
  733.     time(&ll);
  734.     strcpy(s,ctime(&ll));
  735.     s[strlen(s)-1]=0;
  736.     addline(b,s,&l1);
  737.     sprintf(s,"7──────────────────────────────────────────────────────────────────────────────");
  738.     addline(b,s,&l1);
  739.     if (irt[0]) {
  740.       sprintf(s,"7[1RE7]7:3 %s",irt);
  741.       addline(b,s,&l1);
  742.       if (irt_name[0]) {
  743.     sprintf(s,"7[1BY7]7:3 %s",irt_name);
  744.     addline(b,s,&l1);
  745.       }
  746.       addline(b,"",&l1);
  747.     }
  748.     if (fsed) {
  749.       ll=filelength(i5);
  750.       read(i5, (void *) (& (b[l1]) ),ll);
  751.       l1 += ll;
  752.       close(i5);
  753.     } else {
  754.       for (i5=0; i5<curli; i5++)
  755.     addline(b,&(lin[i5*LEN]),&l1);
  756.     }
  757.     if (thisuser.ass_pts>0) {
  758.     sprintf(s,"\r\n7[1Comment7]3:cI have %d ass points!",thisuser.ass_pts);
  759.     addline(b,s,&l1);
  760.       }
  761.     if ((subboards[curlsub].type) && (syscfg.systemnumber))
  762.       {
  763.     addline(b,"",&l1);
  764.     addline(b,"         ┌────────────────────────────────────────────────────────┐",&l1);
  765.     addline(b,"         │ The Devil's Doorknob·(410)442-1601·BamaNet≡ Node 1002 │",&l1);
  766.     addline(b,"         └────────────────────────────────────────────────────────┘",&l1);
  767.       }
  768.        prt(5,"Do you want your Personal Tag displayed? ");
  769.        if (yn())
  770.        {
  771.     addline(b," ",&l1);
  772.     sprintf(s,"7[1Personal Tag7]7:3 %s",thisuser.note);
  773.     addline(b,s,&l1);
  774.        }
  775.     if (b[l1-1]!=26)
  776.       b[l1++]=26;
  777.     savefile(b,l1,&m,aux);
  778.     if (fsed)
  779.       unlink(fnx);
  780.   } else {
  781.     if (fsed)
  782.       unlink(fnx);
  783.     pl("6Aborted.");
  784.     m.stored_as=0xffffffff;
  785.   }
  786.   *m1=m;
  787.   if (!fsed) {
  788.     farfree((void *)lin);
  789.   }
  790.   charbufferpointer=0;
  791.   charbuffer[0]=0;
  792. }
  793.  
  794.  
  795.  
  796. int forwardm(unsigned short *u, unsigned short *s)
  797. {
  798.   userrec ur;
  799.   char *ss;
  800.   int i,i1,cu;
  801.  
  802.   if (*s)
  803.     return(0);
  804.   read_user(*u,&ur);
  805.   if (ur.inact & inact_deleted)
  806.     return(0);
  807.   if ((ur.forwardusr==0) && (ur.forwardsys==0))
  808.     return(0);
  809.   if (ur.forwardsys) {
  810.     if ((ur.forwardusr>0) && (ur.forwardusr<32767)) {
  811.       if (!next_system(ur.forwardsys))
  812.         return(0);
  813.       *u=ur.forwardusr;
  814.       *s=ur.forwardsys;
  815.       return(1);
  816.     } else {
  817.       *u=0;
  818.       *s=0;
  819.       return(0);
  820.     }
  821.   }
  822.   cu=ur.forwardusr;
  823.   if ((ss=malloca((long) syscfg.maxusers+ 300L))==NULL)
  824.     return(0);
  825.   for (i=0; i<syscfg.maxusers+300; i++)
  826.     ss[i]=0;
  827.   ss[*u]=1;
  828.   read_user(cu,&ur);
  829.   while ((ur.forwardusr) || (ur.forwardsys)) {
  830.     if (ur.forwardsys) {
  831.       if (!next_system(ur.forwardsys))
  832.         return(0);
  833.       *u=ur.forwardusr;
  834.       *s=ur.forwardsys;
  835.       farfree(ss);
  836.       return(1);
  837.     }
  838.     if (ss[cu]) {
  839.       farfree(ss);
  840.       return(0);
  841.     }
  842.     ss[cu]=1;
  843.     cu=ur.forwardusr;
  844.     read_user(cu,&ur);
  845.   }
  846.   farfree(ss);
  847.   *s=0;
  848.   *u=cu;
  849.   return(1);
  850. }
  851.  
  852.  
  853. void sendout_email(char *title, messagerec *msg, int anony, unsigned un, unsigned sy, int an)
  854. {
  855.   mailrec m,m1;
  856.   net_header_rec nh;
  857.   int f,len,i,i1;
  858.   char *b,*b1,s[129],s2[129],s1[129];
  859.   long len1;
  860.   userrec ur;
  861.  
  862.   strcpy(m.title, title);
  863.   m.msg=*msg;
  864.   m.anony=anony;
  865.   m.fromsys=0;
  866.   m.fromuser=usernum;
  867.   m.tosys=sy;
  868.   m.touser=un;
  869.   m.status=0;
  870.   time((long *)&(m.daten));
  871.   sprintf(s,"%sEMAIL.DAT",syscfg.datadir);
  872.   if (sy==0) {
  873.     f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  874.     if (!f) {
  875.       return;
  876.     }
  877.     len=(int) filelength(f)/sizeof(mailrec);
  878.     if (len==0)
  879.       i=0;
  880.     else {
  881.       i=len-1;
  882.       lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
  883.       read(f,(void *)&m1,sizeof(mailrec));
  884.       while ((i>0) && (m1.tosys==0) && (m1.touser==0)) {
  885.         --i;
  886.         lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
  887.         i1=read(f,(void *)&m1,sizeof(mailrec));
  888.         if (i1==-1)
  889.           pl("DIDN'T READ RIGHT.");
  890.       }
  891.       if ((m1.tosys) || (m1.touser))
  892.         ++i;
  893.     }
  894.     lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
  895.     i1=write(f,(void *)&m,sizeof(mailrec));
  896.     if (i1==-1) {
  897.       pl("DIDN'T SAVE RIGHT!");
  898.     }
  899.     close(f);
  900.   } else {
  901.     if ((b=readfile(&(m.msg),"EMAIL",&len1))==NULL)
  902.       return;
  903.     remove_link(&(m.msg),"EMAIL");
  904.     nh.tosys=sy;
  905.     nh.touser=un;
  906.     nh.fromsys=syscfg.systemnumber;
  907.     nh.fromuser=usernum;
  908.     nh.main_type=main_type_email;
  909.     nh.minor_type=0;
  910.     nh.list_len=0;
  911.     nh.daten=m.daten;
  912.     nh.method=0;
  913.     if ((b1=malloca(len1+300))==NULL) {
  914.       farfree(b);
  915.       return;
  916.     }
  917.     i=0;
  918.     if (un==0) {
  919.       nh.main_type=main_type_email_name;
  920.       strcpy(&(b1[i]),net_email_name);
  921.       i+= strlen(net_email_name)+1;
  922.     }
  923.     strcpy(&(b1[i]),m.title);
  924.     i += strlen(m.title)+1;
  925.     memmove(&(b1[i]),b,(unsigned int) len1);
  926.     nh.length=len1+(long)i;
  927.     if (nh.length > 32760) {
  928.       nh.length = 32760;
  929.       npr("Message truncated by %lu bytes for the network.\r\n",nh.length-32760L);
  930.     }
  931.     sprintf(s,"%sP0.NET",syscfg.datadir);
  932.     f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  933.     lseek(f,0L,SEEK_END);
  934.     write(f,(void *)&nh,sizeof(net_header_rec));
  935.     write(f,(void *)b1,nh.length);
  936.     close(f);
  937.     farfree(b);
  938.     farfree(b1);
  939.   }
  940.   s2[0]=0;
  941.   strcpy(s,"7Mail sent to ");
  942.   if (sy==0) {
  943.     read_user(un,&ur);
  944.     ++ur.waiting;
  945.     write_user(un,&ur);
  946.     close_user();
  947.     if (un==1)
  948.       ++fwaiting;
  949.     if (an) {
  950.       strcat(s,nam(&ur,un));
  951.       sysoplog(s);
  952.     } else {
  953.       strcpy(s1,s);
  954.       strcat(s1,nam(&ur,un));
  955.       sysoplog(s1);
  956.       strcat(s,"1>7UNKNOWN1<");
  957.     }
  958.   } else {
  959.     if (un==0)
  960.       sprintf(s1,"%s @%u",net_email_name,sy);
  961.     else
  962.       sprintf(s1,"User %u @%u",un,sy);
  963.     strcat(s,s1);
  964.     sysoplog(s);
  965.   }
  966.   if ((un==1) && (sy==0)) {
  967.     ++status.fbacktoday;
  968.     ++thisuser.feedbacksent;
  969.     ++thisuser.fsenttoday1;
  970.     ++fsenttoday;
  971.   } else {
  972.     ++status.emailtoday;
  973.     ++thisuser.etoday;
  974.     if (sy==0) {
  975.       ++thisuser.emailsent;
  976.     } else {
  977.       ++thisuser.emailnet;
  978.       /* len1=nh.length+sizeof(net_header_rec); */
  979.       /* fl = (csne->cost) * ((float)len1) / 1024.0; */
  980.       /* sprintf(s2,"Total cost: $%6.2f",fl); */
  981.     }
  982.   }
  983.   save_status();
  984.   if (!wfc)
  985.     topscreen();
  986.   pl(s);
  987.   if (s2[0])
  988.     pl(s2);
  989. }
  990.  
  991.  
  992.  
  993. void email(unsigned short un, unsigned short sy, int forceit, int anony)
  994. {
  995.   int i,i1,f,len,an;
  996.   messagerec msg;
  997.   char s[81],s1[81],s2[81],t[81],*b,*b1;
  998.   userrec ur;
  999.   slrec ss;
  1000.   long len1;
  1001.   float fl;
  1002.   unsigned int ui;
  1003.   net_system_list_rec *csne;
  1004.  
  1005.  
  1006.   if (freek1(syscfg.msgsdir)<10.0) {
  1007.     nl();
  1008.     pl("Sorry, not enough disk space left.");
  1009.     nl();
  1010.     return;
  1011.   }
  1012.   nl();
  1013.   sprintf(s,"%sEMAIL.DAT",syscfg.datadir);
  1014.   ss=syscfg.sl[actsl];
  1015.   if (forwardm(&un,&sy)) {
  1016.     nl();
  1017.     pl("7Mail Forwarded.");
  1018.     nl();
  1019.     if ((un==0) && (sy==0)) {
  1020.       pl("Forwarded to unknown user.");
  1021.       return;
  1022.     }
  1023.   }
  1024.   if ((sy!=0) && (syscfg.systemnumber==0)) {
  1025.     nl();
  1026.     pl("Sorry, this system is not a part of WWIVnet.");
  1027.     nl();
  1028.     return;
  1029.   }
  1030.   if (sy==0) {
  1031.     read_user(un,&ur);
  1032.     if (((ur.sl==255) && (ur.waiting>(syscfg.maxwaiting * 5))) ||
  1033.         ((ur.sl!=255) && (ur.waiting>syscfg.maxwaiting)) ||
  1034.         (ur.waiting>200)) {
  1035.       if (!forceit) {
  1036.         nl();
  1037.         pl("Mailbox full.");
  1038.         nl();
  1039.         return;
  1040.       }
  1041.     }
  1042.     if (ur.inact & inact_deleted) {
  1043.       nl();
  1044.       pl("Deleted user.");
  1045.       nl();
  1046.       return;
  1047.     }
  1048.   } else {
  1049.     if ((csne=next_system(sy))==NULL) {
  1050.       nl();
  1051.       pl("Unknown system number.");
  1052.       nl();
  1053.       return;
  1054.     }
  1055.     if (thisuser.restrict & restrict_net) {
  1056.       nl();
  1057.       pl("You can't send mail off the system.");
  1058.       return;
  1059.     }
  1060.   }
  1061.   if (forceit==0) {
  1062.     if ((((un==1) && (sy==0) && ((fsenttoday>=5) || (thisuser.fsenttoday1>=10))) ||
  1063.      ((un!=1) && (thisuser.etoday>=ss.emails))) && (!cs())) {
  1064.       nl();
  1065.       pl("Too much mail sent today.");
  1066.       nl();
  1067.       return;
  1068.     }
  1069.     if ((restrict_email & thisuser.restrict) && (un!=1)) {
  1070.       nl();
  1071.       pl("You can't send mail.");
  1072.       nl();
  1073.       return;
  1074.     }
  1075.   }
  1076.   if (ss.ability & ability_read_email_anony)
  1077.     an=1;
  1078.   else
  1079.     if (anony & (anony_sender | anony_sender_da | anony_sender_pp))
  1080.       an=0;
  1081.     else
  1082.       an=1;
  1083.   if (sy==0) {
  1084.     if (an) {
  1085.       read_user(un,&ur);
  1086.       strcpy(s2,nam(&ur,un));
  1087.     } else
  1088.       strcpy(s2,"1>7UNKNOWN1<");
  1089.   } else {
  1090.     if (un==0)
  1091.       sprintf(s2,"%s @%u",net_email_name,sy);
  1092.     else
  1093.       sprintf(s2,"User %u @%u",un,sy);
  1094.   }
  1095.   npr("1E-mailing %s\r\n",s2);
  1096.   if (ss.ability & ability_email_anony)
  1097.     i=anony_enable_anony;
  1098.   else
  1099.     i=0;
  1100.   if (anony & (anony_receiver_pp | anony_receiver_da))
  1101.     i=anony_enable_dear_abby;
  1102.   if (anony & anony_receiver)
  1103.     i=anony_enable_anony;
  1104.   if ((i==anony_enable_anony) && (thisuser.restrict & restrict_anony))
  1105.     i=0;
  1106.   if (sy!=0) {
  1107.     i=0;
  1108.     anony=0;
  1109.     nl();
  1110.     sprintf(s,"3Name of system: '%s'",csne -> name);
  1111.     pl(s);
  1112.     sprintf(s,"3Number of hops: %u",csne->numhops);
  1113.     pl(s);
  1114.     nl();
  1115.   }
  1116.   msg.storage_type=EMAIL_STORAGE;
  1117.   inmsg(&msg,t,&i,!forceit,"EMAIL",ALLOW_FULLSCREEN);
  1118.   if (msg.stored_as==0xffffffff)
  1119.     return;
  1120.   if (anony & anony_sender)
  1121.     i|=anony_receiver;
  1122.   if (anony & anony_sender_da)
  1123.     i|=anony_receiver_da;
  1124.   if (anony & anony_sender_pp)
  1125.     i|=anony_receiver_pp;
  1126.  
  1127.   sendout_email(t, &msg, i, un, sy, an);
  1128. }
  1129.  
  1130.  
  1131. void imail(unsigned short u, unsigned short s)
  1132. {
  1133.   char s1[81],s2[81];
  1134.   int i;
  1135.   userrec ur;
  1136.  
  1137.   if (forwardm(&u,&s))
  1138.     pl("Mail forwarded.");
  1139.  
  1140.   i=1;
  1141.   helpl=0;
  1142.   if (s==0) {
  1143.     read_user(u,&ur);
  1144.     if ((ur.inact & inact_deleted)==0) {
  1145.       sprintf(s1,"E-mail %s? ",nam(&ur,u));
  1146.       prt(5,s1);
  1147.       if (yn()==0)
  1148.         i=0;
  1149.     } else
  1150.       i=0;
  1151.   } else {
  1152.     sprintf(s1,"1E-mail User3 %u @%u ? ",u,s);
  1153.     prt(5,s1);
  1154.     if (yn()==0)
  1155.       i=0;
  1156.   }
  1157.   if (i)
  1158.     email(u,s,0,0);
  1159. }
  1160.  
  1161.  
  1162. void iscan(int b)
  1163. {
  1164.   int f;
  1165.   char s[81];
  1166.  
  1167.   if (usub[b].subnum==curlsub)
  1168.     return;
  1169.   curlsub=usub[b].subnum;
  1170.   bchanged=0;
  1171.   nummsgs=0;
  1172.   if (curlsub<0)
  1173.     return;
  1174.  
  1175.   sprintf(s,"%s%s.SUB",syscfg.datadir,subboards[curlsub].filename);
  1176.   f=open(s,O_BINARY | O_RDWR);
  1177.   if (f==-1) {
  1178.     f=open(s,O_BINARY | O_RDWR | O_CREAT,S_IREAD | S_IWRITE);
  1179.     msgs[0].owneruser=0;
  1180.     write(f,(void *) (&msgs[0]),sizeof(postrec));
  1181.   }
  1182.   lseek(f,0L,SEEK_SET);
  1183.   nummsgs=(read(f,(void *) (&msgs[0]),255*sizeof(postrec)) / sizeof(postrec))-1;
  1184.   nummsgs=msgs[0].owneruser;
  1185.   if (nummsgs) {
  1186.     sub_dates[curlsub]=msgs[nummsgs].qscan;
  1187.   } else {
  1188.     sub_dates[curlsub]=1;
  1189.   }
  1190.   close(f);
  1191. }
  1192.  
  1193. void iscan_hash(int b)
  1194. {
  1195.   int f,nm;
  1196.   char s[81];
  1197.   postrec msg;
  1198.  
  1199.   if ((b>=num_subs) || (sub_dates[b]))
  1200.     return;
  1201.  
  1202.   sprintf(s,"%s%s.SUB",syscfg.datadir,subboards[b].filename);
  1203.   f=open(s,O_BINARY | O_RDWR);
  1204.   if (f==-1) {
  1205.     sub_dates[b]=1;
  1206.     return;
  1207.   }
  1208.   lseek(f,0L,SEEK_SET);
  1209.   read(f,&msg,sizeof(postrec));
  1210.   nm=msg.owneruser;
  1211.   if (nm>0) {
  1212.     lseek(f,nm*sizeof(postrec),SEEK_SET);
  1213.     read(f,&msg,sizeof(postrec));
  1214.     sub_dates[b]=msg.qscan;
  1215.   } else {
  1216.     sub_dates[b]=1;
  1217.   }
  1218.   close(f);
  1219. }
  1220.  
  1221.  
  1222. void savebase()
  1223. {
  1224.   int f;
  1225.   char s[81];
  1226.  
  1227.   if (bchanged==0)
  1228.     return;
  1229.  
  1230.  
  1231.   sprintf(s,"%s%s.SUB",syscfg.datadir,subboards[curlsub].filename);
  1232.   f=open(s,O_BINARY | O_RDWR);
  1233.   lseek(f,0L,SEEK_SET);
  1234.   msgs[0].owneruser=nummsgs;
  1235.   write(f,(void *) (&msgs[0]), ((nummsgs+1) * sizeof(postrec)));
  1236.   close(f);
  1237.   bchanged=0;
  1238.   if (nummsgs) {
  1239.     sub_dates[curlsub]=msgs[nummsgs].qscan;
  1240.   } else {
  1241.     sub_dates[curlsub]=1;
  1242.   }
  1243. }
  1244.  
  1245.  
  1246. void plan(char *s, int *abort, int *next)
  1247. {
  1248.   int i;
  1249.  
  1250.   i=0;
  1251.   checkhangup();
  1252.   if (hangup)
  1253.     *abort=1;
  1254.   checka(abort,next);
  1255.   while ((s[i]) && (!(*abort))) {
  1256.     outchr(s[i++]);
  1257.     checka(abort,next);
  1258.   }
  1259.   if (!(*abort))
  1260.     nl();
  1261. }
  1262.  
  1263.  
  1264. #define buf_size 512
  1265.  
  1266. void read_message1(messagerec *m1, char an, int readit, int *next, char *fn)
  1267. {
  1268.   char n[81],d[81],s[161],s1[81],s2[81],*sss,*ss,ch;
  1269.   int f,abort,done,end,cur,p,p1,printit,ctrla,centre,i,i1,ansi,ctrld;
  1270.   messagerec m;
  1271.   char *buf;
  1272.   long csec,len,l1,l2;
  1273.  
  1274.   if ((buf=malloca(buf_size))==NULL)
  1275.     return;
  1276.   ss=NULL;
  1277.   ansi=0;
  1278.   m=*m1;
  1279.   *next=0;
  1280.   f=-1;
  1281.   done=0;
  1282.   cur=0;
  1283.   end=0;
  1284.   abort=0;
  1285.   ctrld=0;
  1286.   switch(m.storage_type) {
  1287.     case 0:
  1288.     case 1:
  1289.     case 2:
  1290.       ss=readfile(&m,fn,&len);
  1291.       if (m.storage_type!=2) {
  1292.         strcpy(s,syscfg.msgsdir);
  1293.         ltoa(m.stored_as,s1,16);
  1294.         if (m.storage_type==1) {
  1295.           strcat(s,fn);
  1296.           strcat(s,"\\");
  1297.         }
  1298.         strcat(s,s1);
  1299.         strcpy(s2,"FN  : ");
  1300.         strcat(s2,s1);
  1301.         if (so())
  1302.           pl(s2);
  1303.         else {
  1304.           strcat(s2,"\r\n");
  1305.           outs(s2);
  1306.         }
  1307.       }
  1308.       if (ss==NULL) {
  1309.         plan("File not found.",&abort,next);
  1310.         nl();
  1311.     farfree(buf);
  1312.         return;
  1313.       }
  1314.       p=0;
  1315.       while ((ss[p]!=13) && ((long)p<len) && (p<60))
  1316.         n[p]=ss[p++];
  1317.       n[p]=0;
  1318.       ++p;
  1319.       p1=0;
  1320.       if (ss[p]==10)
  1321.         ++p;
  1322.       while ((ss[p+p1]!=13) && ((long)p+p1<len) && (p<60))
  1323.         d[p1]=ss[(p1++)+p];
  1324.       d[p1]=0;
  1325.       cur=p+p1+1;
  1326.       break;
  1327.     case 255:
  1328.       strcpy(s,fn);
  1329.       f=open(s,O_RDONLY | O_BINARY);
  1330.       if (f==-1) {
  1331.         plan("File not found.",&abort,next);
  1332.         nl();
  1333.     farfree(buf);
  1334.         return;
  1335.       }
  1336.       lseek(f,m.stored_as,SEEK_SET);
  1337.       end=read(f,(void *)buf,buf_size);
  1338.       break;
  1339.     default:
  1340.       /* illegal storage type */
  1341.       nl();
  1342.       pl("->ILLEGAL STORAGE TYPE<-");
  1343.       nl();
  1344.       farfree(buf);
  1345.       return;
  1346.   }
  1347.  
  1348.   irt_name[0]=0;
  1349.   if (m.storage_type!=255) switch(an) {
  1350.     default:
  1351.     case 0:
  1352.       osan("7[1Name7]3: ",&abort,next);
  1353.       ansic(MSG_COLOR);
  1354.       plan(n,&abort,next);
  1355.       strcpy(irt_name,n);
  1356.       osan("7[1Date7]3: ",&abort,next);
  1357.       ansic(MSG_COLOR);
  1358.       plan(d,&abort,next);
  1359.       if (origin_str[0]) {
  1360.     osan("7[1From7]3:",&abort,next);
  1361.     plan(origin_str,&abort,next);
  1362.       }
  1363.       break;
  1364.     case anony_sender:
  1365.       if (readit) {
  1366.     osan("7[1Name7]3: ",&abort,next);
  1367.     ansic(MSG_COLOR);
  1368.     sprintf(s,"1<<< 3%s 1>>>",n);
  1369.     plan(s,&abort,next);
  1370.     osan("7[1Date7]3: ",&abort,next);
  1371.     ansic(MSG_COLOR);
  1372.     plan(d,&abort,next);
  1373.       } else {
  1374.     osan("7[1Name7]3: ",&abort,next);
  1375.     ansic(MSG_COLOR);
  1376.     plan("1>7UNKNOWN1<",&abort,next);
  1377.     osan("7[1Date7]3: ",&abort,next);
  1378.     ansic(MSG_COLOR);
  1379.     plan("1>7UNKNOWN1<",&abort,next);
  1380.       }
  1381.       break;
  1382.     case anony_sender_da:
  1383.     case anony_sender_pp:
  1384.       if (an==anony_sender_da) {
  1385.     osan("7[1Name7]3: ",&abort,next);
  1386.     ansic(MSG_COLOR);
  1387.     plan("7Just a lost soul swimmin' in a fish bowl",&abort,next);
  1388.       } else {
  1389.     osan("7[1Name7]3: ",&abort,next);
  1390.     ansic(MSG_COLOR);
  1391.     plan("3Problemed Person",&abort,next);
  1392.       }
  1393.       if (readit) {
  1394.     osan("7[1Name7]3: ",&abort,next);
  1395.     ansic(MSG_COLOR);
  1396.         plan(n,&abort,next);
  1397.     osan("7[1Date7]3: ",&abort,next);
  1398.     plan(d,&abort,next);
  1399.       } else {
  1400.     osan("7[1Date7]3: ",&abort,next);
  1401.     ansic(MSG_COLOR);
  1402.     plan("1>7UNKNOWN1<",&abort,next);
  1403.       }
  1404.       break;
  1405.   }
  1406.   nl();
  1407.   p=0;
  1408.   p1=0;
  1409.   done=0;
  1410.   printit=0;
  1411.   ctrla=0;
  1412.   centre=0;
  1413.   l1=(long) cur;
  1414.  
  1415.   while ((!done) && (!abort) && (!hangup)) {
  1416.     switch(m.storage_type) {
  1417.       case 0:
  1418.       case 1:
  1419.       case 2:
  1420.     ch=ss[l1];
  1421.     if (l1>=len)
  1422.           ch=26;
  1423.         break;
  1424.       case 255:
  1425.         if (cur>=end) {
  1426.           cur=0;
  1427.           end=read(f,(void *)buf,buf_size);
  1428.           if (end==0)
  1429.             buf[0]=26;
  1430.         }
  1431.         if ((buf[cur]=='`') && (m.stored_as))
  1432.           buf[cur]=26;
  1433.     ch=buf[cur];
  1434.         break;
  1435.     }
  1436.     if (ch==26)
  1437.       done=1;
  1438.     else
  1439.       if (ch!=10) {
  1440.         if ((ch==13) || (!ch)) {
  1441.           if (ch==13)
  1442.             ctrld=0;
  1443.           printit=1;
  1444.         } else if (ch==1)
  1445.           ctrla=1;
  1446.         else if (ch==2)
  1447.           centre=1;
  1448.         else if (ch==4)
  1449.           ctrld=1;
  1450.         else if (ctrld==1) {
  1451.           if ((ch>='0') && (ch<='9')) {
  1452.         if (thisuser.optional_val<(ch-'0'))
  1453.               ctrld=0;
  1454.             else
  1455.               ctrld=-1;
  1456.           } else
  1457.             ctrld=0;
  1458.         } else {
  1459.           if (ch==27) {
  1460.             if ((topline) && (screenbottom==24) && (!ansi))
  1461.               set_protect(0);
  1462.             ansi=1;
  1463.             lines_listed=0;
  1464.           }
  1465.           s[p++]=ch;
  1466.           if ((ch==3) || (ch==8))
  1467.             --p1;
  1468.           else
  1469.             ++p1;
  1470.           if ((ch==32) && (!centre))
  1471.             printit=1;
  1472.         }
  1473.  
  1474.         if ((printit) || (ansi) || (p>=80)) {
  1475.           printit=0;
  1476.           if (centre && (ctrld!=-1)) {
  1477.             i1=(thisuser.screenchars-wherex()-p1)/2;
  1478.             for (i=0; (i<i1) && (!abort) && (!hangup); i++)
  1479.               osan(" ",&abort,next);
  1480.           }
  1481.           if (p) {
  1482.             if (ctrld!=-1) {
  1483.               if ((wherex() + p1 >= thisuser.screenchars) && (!centre) && (!ansi))
  1484.                 nl();
  1485.               s[p]=0;
  1486.               osan(s,&abort,next);
  1487.               if ((ctrla) && (s[p-1]!=32) && (!ansi))
  1488.                 outchr(32);
  1489.             }
  1490.             p1=0;
  1491.             p=0;
  1492.           }
  1493.           centre=0;
  1494.         }
  1495.         checka(&abort,next);
  1496.         if (ch==13)
  1497.           if (ctrla==0) {
  1498.             if (ctrld!=-1)
  1499.               nl();
  1500.           } else
  1501.             ctrla=0;
  1502.       } else
  1503.         ctrld=0;
  1504.     ++cur;
  1505.     ++l1;
  1506.   }
  1507.   if ((!abort) && (p)) {
  1508.     s[p]=0;
  1509.     pl(s);
  1510.   }
  1511.   ansic(0);
  1512.   nl();
  1513.   if (f!=-1)
  1514.     close(f);
  1515.   if ((m.storage_type==255) && (abort))
  1516.     *next=1;
  1517.   if ((express) && (abort) && (!(*next)))
  1518.     expressabort=1;
  1519.   farfree(buf);
  1520.   if (ss!=NULL)
  1521.     farfree(ss);
  1522.   if ((ansi) && (topdata) && (useron))
  1523.     topscreen();
  1524. }
  1525.  
  1526.  
  1527.  
  1528. int printfile(char *fn)
  1529. {
  1530.   char s[81],s1[81];
  1531.   messagerec m;
  1532.   int next;
  1533.  
  1534.   m.stored_as=0L;
  1535.   m.storage_type=255;
  1536.   strcpy(s,syscfg.gfilesdir);
  1537.   strcat(s,fn);
  1538.   if (strchr(s,'.')==NULL) {
  1539.     if (thisuser.sysstatus & sysstatus_ansi) {
  1540.       if (thisuser.sysstatus & sysstatus_color) {
  1541.     strcpy(s1,s);
  1542.     strcat(s1,".ANS");
  1543.     if (exist(s1))
  1544.       strcat(s,".ANS");
  1545.       }
  1546.       if (strchr(s,'.')==NULL) {
  1547.     strcpy(s1,s);
  1548.     strcat(s1,".B&W");
  1549.     if (exist(s1))
  1550.       strcat(s,".B&W");
  1551.     else
  1552.       strcat(s,".MSG");
  1553.       }
  1554.     } else
  1555.       strcat(s,".MSG");
  1556.   }
  1557.   next=0;
  1558.   read_message1(&m,0,0,&next,s);
  1559.   return(next);
  1560. }
  1561.  
  1562.  
  1563. void read_message(int n, int *next, int *val)
  1564. {
  1565.   char s[100],s1[80];
  1566.   postrec p;
  1567.   int abort,a;
  1568.   slrec ss;
  1569.  
  1570.   nl();
  1571.   abort=0;
  1572.   *next=0;
  1573.   sprintf(s,"7[1%u/%u7]3:7 ",n,nummsgs);
  1574.   osan(s,&abort,next);
  1575.   ansic(MSG_COLOR);
  1576.   p=msgs[n];
  1577.   if (p.status & (status_unvalidated | status_delete)) {
  1578.     plan("1<<<7 NOT VALIDATED YET1 >>>",&abort,next);
  1579.     if (!lcs())
  1580.       return;
  1581.     *val |= 1;
  1582.     osan(s,&abort,next);
  1583.     ansic(MSG_COLOR);
  1584.   }
  1585.   strcpy(irt,p.title);
  1586.   irt_name[0]=0;
  1587.   plan(p.title,&abort,next);
  1588.   if ((p.status & status_no_delete) && (lcs())) {
  1589.     plan("||||> Permanent Message",&abort,next);
  1590.   }
  1591.   if (p.status & status_pending_net) {
  1592.     plan("1---->7 Not Network Validated",&abort,next);
  1593.     *val |= 2;
  1594.   }
  1595.   if (!abort) {
  1596.     ss=syscfg.sl[actsl];
  1597.     if ((lcs()) || (ss.ability & ability_read_post_anony))
  1598.       a=1;
  1599.     else
  1600.       a=0;
  1601.     setorigin(p.ownersys, p.owneruser);
  1602.     read_message1(&(p.msg),(p.anony & 0x0f),a,next,(subboards[curlsub].filename));
  1603.     ++thisuser.msgread;
  1604.     ++msgreadlogon;
  1605.   } else
  1606.     if ((express) && (!(*next)))
  1607.       expressabort=1;
  1608.   if (p.qscan>QSCN(curlsub))
  1609.     QSCN(curlsub)=p.qscan;
  1610. }
  1611.  
  1612.  
  1613. void lineadd(messagerec *m1, char *sx, char *aux)
  1614. {
  1615.   messagerec m;
  1616.   char s1[81],s[81],s2[81],*b;
  1617.   int f,i,j,new;
  1618.  
  1619.   strcpy(s2,sx);
  1620.   strcat(s2,"\r\n\0x1a");
  1621.   m=*m1;
  1622.   strcpy(s,syscfg.msgsdir);
  1623.   switch(m.storage_type) {
  1624.     case 0:
  1625.     case 1:
  1626.       ltoa(m.stored_as,s1,16);
  1627.       if (m.storage_type==1) {
  1628.         strcat(s,aux);
  1629.         strcat(s,"\\");
  1630.       }
  1631.       strcat(s,s1);
  1632.       f=open(s,O_RDWR | O_BINARY);
  1633.       if (f>0) {
  1634.         lseek(f,-1L,SEEK_END);
  1635.         write(f,(void *)s2,strlen(s2));
  1636.         close(f);
  1637.       }
  1638.       break;
  1639.     case 2:
  1640.       strcpy(s,sx);
  1641.       strcat(s,"\x1a");
  1642.       f=open_file(aux);
  1643.       new=1;
  1644.       while ((new<2048) && (gat[new]!=0))
  1645.     ++new;
  1646.       i=(int)m.stored_as;
  1647.       while (gat[i]!=-1)
  1648.     i=gat[i];
  1649.       if ((b=malloca(2048))==NULL)
  1650.         return;
  1651.       lseek(f,4096L+((long)i)*512L,SEEK_SET);
  1652.       read(f,(void *)b,512);
  1653.       j=0;
  1654.       while ((j<512) && (b[j]!=26))
  1655.     ++j;
  1656.       strcpy(&(b[j]),s);
  1657.       lseek(f,4096L+((long)i)*512L,SEEK_SET);
  1658.       write(f,(void *)b,512);
  1659.       if ((j+strlen(s))>512) {
  1660.     strcpy(b,&(s[512-j]));
  1661.     lseek(f,4096L+((long)new)*512L,SEEK_SET);
  1662.     write(f,(void *)b,512);
  1663.     gat[new]=-1;
  1664.     gat[i]=new;
  1665.     lseek(f,0L,SEEK_SET);
  1666.     write(f,(void *)gat,4096);
  1667.       }
  1668.       farfree((void *)b);
  1669.       close(f);
  1670.       break;
  1671.     default:
  1672.       /* illegal storage type */
  1673.       break;
  1674.   }
  1675. }
  1676.  
  1677.  
  1678. void delete(int mn)
  1679. {
  1680.   postrec p1;
  1681.   int i;
  1682.  
  1683.   iscan(cursub);
  1684.   if ((mn>0) && (mn<=nummsgs)) {
  1685.     p1=msgs[mn];
  1686.     remove_link(&p1.msg,(subboards[curlsub].filename));
  1687.     for (i=mn; i<nummsgs; i++)
  1688.       msgs[i]=msgs[i+1];
  1689.     nummsgs--;
  1690.     bchanged=1;
  1691.   }
  1692. }
  1693.  
  1694.  
  1695.