home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / WWIVSOR.ZIP / READMAIL.C < prev    next >
Text File  |  1995-04-25  |  25KB  |  912 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1995 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.  
  22.  
  23. int same_email(tmpmailrec *tm, mailrec *m)
  24. {
  25.   if ((tm->fromsys!=m->fromsys) ||
  26.       (tm->fromuser!=m->fromuser) ||
  27.       (m->tosys!=0) ||
  28.       (m->touser!=usernum) ||
  29.       (tm->daten!=m->daten) ||
  30.       (tm->index==-1) ||
  31.       (memcmp(&tm->msg, &m->msg, sizeof(messagerec)!=0)))
  32.     return(0);
  33.   else
  34.     return(1);
  35. }
  36.  
  37.  
  38. void purgemail(tmpmailrec *mloc,int mw,int *curmail, mailrec *m1, slrec *ss)
  39. {
  40.   int i, f;
  41.   mailrec m;
  42.  
  43.   if (m1->fromuser==65535)
  44.     return;
  45.  
  46.   ansic(5);
  47.   if ((m1->anony & anony_sender) && ((ss->ability & ability_read_email_anony)==0)) {
  48.     outstr(get_string(699));
  49.   } else {
  50.     outstr(get_string(700));
  51.     if (m1->fromsys) {
  52.       npr("#%u @%u? ",m1->fromuser, m1->fromsys);
  53.     } else {
  54.       npr("#%u? ",m1->fromuser);
  55.     }
  56.   }
  57.   if (yn()) {
  58.     f=open_email(1);
  59.     if (f<0)
  60.       return;
  61.     for (i=0; i<mw; i++) {
  62.       if (mloc[i].index>=0) {
  63.         sh_lseek(f,((long) mloc[i].index) * sizeof(mailrec),SEEK_SET);
  64.         sh_read(f,(void *) (&m),sizeof(mailrec));
  65.         if (same_email(mloc+i, &m)) {
  66.           if ((m.fromuser==m1->fromuser) && (m.fromsys==m1->fromsys)) {
  67.             outstr(get_string(701));
  68.             npr("%d\r\n",i+1);
  69.             delmail(f,mloc[i].index);
  70.             mloc[i].index=-1;
  71.             if (*curmail==i)
  72.               ++(*curmail);
  73.           }
  74.         }
  75.       } else {
  76.         if (*curmail==i)
  77.           ++(*curmail);
  78.       }
  79.     }
  80.     f=sh_close(f);
  81.   }
  82. }
  83.  
  84.  
  85. #define MAXMAIL 255
  86.  
  87.  
  88. void resynch_email(tmpmailrec *mloc, int mw, int rec, mailrec *m, int del, unsigned short stat)
  89. {
  90.   int f, i, i1, mp, mfl;
  91.   mailrec m1;
  92.  
  93.   f=open_email(del || stat);
  94.   if (f>0) {
  95.     mfl=filelength(f)/sizeof(mailrec);
  96.  
  97.     for (i=0; i<mw; i++) {
  98.       if (mloc[i].index>=0)
  99.         mloc[i].index=-2;
  100.     }
  101.  
  102.     mp=0;
  103.  
  104.     for (i=0; i<mfl; i++) {
  105.       sh_lseek(f,((long) i) * sizeof(mailrec),SEEK_SET);
  106.       sh_read(f,(void *) (&m1),sizeof(mailrec));
  107.  
  108.       if ((m1.tosys==0) && (m1.touser==usernum)) {
  109.         for (i1=mp; i1<mw; i1++) {
  110.           if (same_email(mloc+i1, &m1)) {
  111.             mloc[i1].index=i;
  112.             mp=i1+1;
  113.             if (i1==rec)
  114.               *m=m1;
  115.             break;
  116.           }
  117.         }
  118.       }
  119.     }
  120.  
  121.     for (i=0; i<mw; i++) {
  122.       if (mloc[i].index==-2)
  123.         mloc[i].index=-1;
  124.     }
  125.  
  126.     if (stat && !del && (mloc[rec].index>=0)) {
  127.       m->status |= stat;
  128.       sh_lseek(f,((long) mloc[rec].index) * sizeof(mailrec),SEEK_SET);
  129.       sh_write(f,(void *) (m),sizeof(mailrec));
  130.     }
  131.     if (del && (mloc[rec].index>=0)) {
  132.       if (del==2) {
  133.         m->touser=0;
  134.         m->tosys=0;
  135.         m->daten=0xffffffff;
  136.         m->msg.storage_type=0;
  137.         m->msg.stored_as=0xffffffff;
  138.         sh_lseek(f,((long) mloc[rec].index) * sizeof(mailrec),SEEK_SET);
  139.         sh_write(f,(void *) (m),sizeof(mailrec));
  140.       } else {
  141.         delmail(f, mloc[rec].index);
  142.       }
  143.       mloc[rec].index=-1;
  144.     }
  145.  
  146.     f=sh_close(f);
  147.  
  148.   } else {
  149.     mloc[rec].index=-1;
  150.   }
  151. }
  152.  
  153.  
  154. int read_same_email(tmpmailrec *mloc, int mw, int rec, mailrec *m, int del, unsigned short stat)
  155. {
  156.   int f;
  157.  
  158.   if (mloc[rec].index<0)
  159.     return(0);
  160.  
  161.   f=open_email(del || stat);
  162.   sh_lseek(f,((long) mloc[rec].index) * sizeof(mailrec),SEEK_SET);
  163.   sh_read(f,(void *) (m),sizeof(mailrec));
  164.  
  165.   if (!same_email(mloc+rec,m)) {
  166.     f=sh_close(f);
  167.     read_status();
  168.     if (emchg) {
  169.       resynch_email(mloc, mw, rec, m, del, stat);
  170.     } else {
  171.       mloc[rec].index=-1;
  172.     }
  173.   } else {
  174.  
  175.     if (stat && !del && (mloc[rec].index>=0)) {
  176.       m->status |= stat;
  177.       sh_lseek(f,((long) mloc[rec].index) * sizeof(mailrec),SEEK_SET);
  178.       sh_write(f,(void *) (m),sizeof(mailrec));
  179.     }
  180.     if (del) {
  181.       if (del==2) {
  182.         m->touser=0;
  183.         m->tosys=0;
  184.         m->daten=0xffffffff;
  185.         m->msg.storage_type=0;
  186.         m->msg.stored_as=0xffffffff;
  187.         sh_lseek(f,((long) mloc[rec].index) * sizeof(mailrec),SEEK_SET);
  188.         sh_write(f,(void *) (m),sizeof(mailrec));
  189.       } else {
  190.         delmail(f, mloc[rec].index);
  191.       }
  192.       mloc[rec].index=-1;
  193.     }
  194.  
  195.     f=sh_close(f);
  196.   }
  197.  
  198.   if (mloc[rec].index!=-1)
  199.     return(1);
  200.   else
  201.     return(0);
  202. }
  203.  
  204. void add_netsubscriber(unsigned short sn)
  205. {
  206.   char s[10], s1[10],ns1[80];
  207.   FILE *host;
  208.  
  209.   if (!valid_system(sn))
  210.     sn=0;
  211.  
  212.   nl();
  213.   prt(1,get_string(1265));
  214.   nln(2);
  215.   prt(2,get_string(1266));
  216.   mpl(7);
  217.   input(s,7);
  218.   if (s[0]==0)
  219.     return;
  220.   strcpy(s1,s);
  221.   sprintf(ns1,"%sN%s.NET",net_data,s);
  222.   if (!exist(ns1)) {
  223.     nl();
  224.     ansic(6);
  225.     npr("%s%s",get_string(1267),ns1);
  226.     nl();
  227.     return;
  228.   }
  229.   nl();
  230.   if (sn) {
  231.     outstr(get_string(1268));
  232.     npr("%u.%s",sn,net_name);
  233.     outstr(get_string(1269));
  234.     npr("%s? ",s);
  235.   }
  236.   if (!sn || !ny()) {
  237.     prt(2,get_string(1270));
  238.     mpl(5);
  239.     input(s,5);
  240.     if (!s[0])
  241.       return;
  242.     sn=atoi(s);
  243.     if (!valid_system(sn)) {
  244.       npr("@%u%s%s.", sn, get_string(1271), net_name);
  245.       nl();
  246.       return;
  247.     }
  248.   }
  249.   sprintf(s,"%u\n",sn);
  250.   host=fsh_open(ns1,"a+t");
  251.   if (host) {
  252.     fprintf(host,s);
  253.     fsh_close(host);
  254.  
  255.     if (exist("AUTOSEND.EXE")) {
  256.       outstr(get_string(1525));
  257.       if (yn()) {
  258.         sprintf(ns1,"AUTOSEND.EXE %s %u .%d",s1,sn,net_num);
  259.         extern_prog(ns1,EFLAG_SHRINK);
  260.       }
  261.     }
  262.   }
  263. }
  264.  
  265. void readmail(void)
  266. {
  267.   int i,i2,f,mw,mfl,curmail,done,abort=0,next,okmail,tp,nn;
  268.   unsigned short xx;
  269.   char s[201],s1[205],s2[81],*b,*ss1;
  270.   mailrec m, m1;
  271.   slrec ss;
  272.   userrec u;
  273.   char ch;
  274.   long len,num_mail,num_mail1;
  275.   unsigned short un, sy;
  276.   net_system_list_rec *csne;
  277.   tmpmailrec *mloc;
  278.  
  279.   emchg=0;
  280.  
  281.   mloc=malloca(MAXMAIL*sizeof(tmpmailrec));
  282.   if (!mloc) {
  283.     pl(get_string(1272));
  284.     return;
  285.   }
  286.  
  287.   if (menu_on())
  288.     printmenu(4);
  289.  
  290.   if (rip_on()) {
  291.     cleared = NEEDCLEAR;
  292.     setmsgview(11);
  293.   }
  294.  
  295.   write_inst(INST_LOC_RMAIL,0,INST_FLAGS_NONE);
  296.   ss=syscfg.sl[actsl];
  297.   f=open_email(0);
  298.   if (f<0) {
  299.     nln(2);
  300.     pl(get_string(702));
  301.     nl();
  302.     bbsfree(mloc);
  303.     return;
  304.   }
  305.   mfl=filelength(f)/sizeof(mailrec);
  306.   mw=0;
  307.   for (i=0; (i<mfl) && (mw<MAXMAIL); i++) {
  308.     sh_lseek(f,((long) (i)) * (sizeof(mailrec)), SEEK_SET);
  309.     sh_read(f,(void *)(&m),sizeof(mailrec));
  310.     if ((m.tosys==0) && (m.touser==usernum)) {
  311.       mloc[mw].index=i;
  312.       mloc[mw].fromsys=m.fromsys;
  313.       mloc[mw].fromuser=m.fromuser;
  314.       mloc[mw].daten=m.daten;
  315.       mloc[mw].msg=m.msg;
  316.       mw++;
  317.     }
  318.   }
  319.   f=sh_close(f);
  320.   thisuser.waiting=mw;
  321.   if (usernum==1)
  322.     fwaiting=mw;
  323.   if (mw==0) {
  324.     nln(2);
  325.     pl(get_string(27));
  326.     nl();
  327.     bbsfree(mloc);
  328.     return;
  329.   }
  330. #ifdef RIPDRIVE
  331.   rd_coff();
  332. #endif
  333.   if (mw==1)
  334.     curmail=0;
  335.   else {
  336.     nln(2);
  337.     ansic(0);
  338.     pl(get_string(703));
  339.     nl();
  340.  
  341.     if ((thisuser.screenchars>=80) && (sysinfo.mail_who_field_len)) {
  342.       (okansi())?strcpy(s1,"┴┬─"):strcpy(s1,"++-");
  343.       sprintf(s,"7%s%c",charstr(4,s1[2]),s1[1]);
  344.       strcat(s,charstr(sysinfo.mail_who_field_len-4,s1[2]));
  345.       strcat(s,charstr(1,s1[1]));
  346.       strcat(s,charstr(thisuser.screenchars-sysinfo.mail_who_field_len-3,s1[2]));
  347.       pla(s,&abort);
  348.     }
  349.  
  350.     for (i=0; ((i<mw) && (!abort)); i++) {
  351.       if (!read_same_email(mloc, mw, i, &m, 0, 0))
  352.         continue;
  353.  
  354.       tp=80;
  355.       if (m.status & status_source_verified)
  356.         tp -= 2;
  357.       if (m.status & status_new_net) {
  358.         tp -= 1;
  359.         if (strlen(m.title)<=tp) {
  360.           nn=(unsigned char) m.title[tp+1];
  361.         } else
  362.           nn=0;
  363.       } else
  364.         nn=0;
  365.       sprintf(s,"2%3d%s7%c1 ",
  366.               i+1,
  367.               m.status&status_seen?" ":"3*",
  368.               okansi()?'│':'|');
  369.  
  370.       if ((m.anony & anony_sender) && ((ss.ability & ability_read_email_anony)==0)) {
  371.         strcat(s,get_string(482));
  372.       } else {
  373.         if (m.fromsys==0) {
  374.           if (m.fromuser==65535) {
  375.             if (nn!=255)
  376.               strcat(s,net_networks[nn].name);
  377.           } else {
  378.             read_user(m.fromuser,&u);
  379.             strcat(s,nam(&u,m.fromuser));
  380.           }
  381.         } else {
  382.           set_net_num(nn);
  383.           csne=next_system(m.fromsys);
  384.           if (csne)
  385.             ss1=csne->name;
  386.           else
  387.             ss1=get_string(622);
  388.           if (nn==255) {
  389.             sprintf(s1,"%s #%u @%u",get_string(704), m.fromuser,m.fromsys);
  390.           } else {
  391.             if (net_num_max>1)
  392.               sprintf(s1,"%s #%u @%u (%s)",
  393.                 net_networks[nn].name,m.fromuser,m.fromsys,ss1);
  394.             else
  395.               sprintf(s1,"%s %u @%u (%s)",get_string(658), m.fromuser,m.fromsys,ss1);
  396.           }
  397.           strcat(s,s1);
  398.         }
  399.       }
  400.  
  401.       if ((thisuser.screenchars >= 80) && (sysinfo.mail_who_field_len)) {
  402.         if (strlen(stripcolors(s))>sysinfo.mail_who_field_len)
  403.           while (strlen(stripcolors(s))>sysinfo.mail_who_field_len)
  404.             s[strlen(s)-1]=0;
  405.         strcat(s,charstr((sysinfo.mail_who_field_len+1)-strlen(stripcolors(s)),' '));
  406.         if (okansi())
  407.           strcat(s,"7│1");
  408.         else
  409.           strcat(s,"|");
  410.         strcat(s," ");
  411.         strcat(s,stripcolors(m.title));
  412.         while (strlen(stripcolors(s))>thisuser.screenchars-1)
  413.           s[strlen(s)-1]=0;
  414.       }
  415.       pla(s,&abort);
  416.       if ((i==(mw-1)) && (thisuser.screenchars>=80) && (!abort) && (sysinfo.mail_who_field_len)) {
  417.         (okansi())?strcpy(s1,"┴┬─"):strcpy(s1,"++-");
  418.         sprintf(s,"7%s%c",charstr(4,s1[2]),s1[0]);
  419.         strcat(s,charstr(sysinfo.mail_who_field_len-4,s1[2]));
  420.         strcat(s,charstr(1,s1[0]));
  421.         strcat(s,charstr(thisuser.screenchars-sysinfo.mail_who_field_len-3,s1[2]));
  422.         pla(s,&abort);
  423.       }
  424.     }
  425.     nl();
  426. #ifdef RIPDRIVE
  427.     rd_con();
  428. #endif
  429.     helpl=10;
  430.     pl(get_string(705));
  431.     outstr(":");
  432.     input(s,3);
  433.     if (strchr(s,'Q')!=NULL) {
  434.       bbsfree(mloc);
  435.       return;
  436.     }
  437.     i=atoi(s);
  438.     if (i)
  439.       if (i<=mw)
  440.         curmail=i-1;
  441.       else
  442.         curmail=0;
  443.     else
  444.       curmail=0;
  445.   }
  446.   done=0;
  447.   do {
  448.     if (E_C) {
  449.       sprintf(s,"1%u/%u0",curmail+1,mw);
  450.       strcat(s,charstr(12-strlen(stripcolors(s)),'.'));
  451.       strcat(s," 2");
  452.     } else {
  453.       sprintf(s,"(%u/%u): ",curmail+1,mw);
  454.     }
  455.     abort=0;
  456.     nln(2);
  457.     if (rip_on())
  458.       msgheader(1);
  459.     osan(s,&abort,&next);
  460.     next=0;
  461.     ansic_x(sysinfo.msg_color);
  462.     s[0]=0;
  463.  
  464.     if (!read_same_email(mloc, mw, curmail, &m, 0, 0)) {
  465.       strcat(s,get_string(706));
  466.       okmail=0;
  467.       pl(s);
  468.       nln(2);
  469.     } else {
  470.       strcat(s,m.title);
  471.       strcpy(irt,m.title);
  472.       irt_name[0]=0;
  473.       abort=0;
  474.       i=((ability_read_email_anony & ss.ability)!=0);
  475.       okmail=1;
  476. #ifdef RIPDRIVE
  477.       rd_coff();
  478. #endif
  479.       pla(s,&abort);
  480.       if ((m.fromsys) && (!m.fromuser))
  481.         grab_user_name(&(m.msg),"EMAIL");
  482.       else
  483.         net_email_name[0]=0;
  484.       tp=80;
  485.       if (m.status & status_source_verified) {
  486.         tp -= 2;
  487.         if (strlen(m.title)<=tp) {
  488.           xx=*(short *) (m.title+tp+1);
  489.           strcpy(s,get_string(707));
  490.           sprintf(s+strlen(s),"%u",xx);
  491.           if (xx==1) {
  492.             strcat(s,get_string(708));
  493.           } else if ((xx>256) && (xx<512)) {
  494.             strcpy(s2,get_string(709));
  495.             sprintf(s2+strlen(s2),"%d)",xx-256);
  496.             strcat(s,s2);
  497.           }
  498.         } else {
  499.           strcpy(s,get_string(710));
  500.         }
  501.         if (!abort) {
  502.           ansic(4);
  503.           pla(s,&abort);
  504.         }
  505.       }
  506.       if (m.status & status_new_net) {
  507.         tp -= 1;
  508.         if (strlen(m.title)<=tp) {
  509.           nn=m.title[tp+1];
  510.         } else
  511.           nn=0;
  512.       } else
  513.         nn=0;
  514.       set_net_num(nn);
  515.       if (nn==255)
  516.         setorigin(0,0);
  517.       else
  518.         setorigin(m.fromsys, m.fromuser);
  519.       if (!abort) {
  520.         read_message1(&m.msg, (m.anony & 0x0f), i, &next, "EMAIL");
  521.         if (!(m.status & status_seen)) {
  522.           read_same_email(mloc, mw, curmail, &m, 0, status_seen);
  523.         }
  524.       }
  525. #ifdef RIPDRIVE
  526.       rd_con();
  527. #endif
  528.     }
  529.     do {
  530.       write_inst(INST_LOC_RMAIL,0,INST_FLAGS_NONE);
  531.       set_net_num(nn);
  532.       i2=1;
  533.       irt_name[0]=0;
  534.       if (!(sysinfo.flags & OP_FLAGS_MAIL_PROMPT))
  535.         prt(2,get_string(711));
  536.       helpl=34;
  537.       if (so()) {
  538.         if (sysinfo.flags & OP_FLAGS_MAIL_PROMPT)
  539.           npr(get_string(1365));
  540.         ch=onek("QSRIDAMF?-+GEZPVUOLCN");
  541.       } else {
  542.         if (cs()) {
  543.           if (sysinfo.flags & OP_FLAGS_MAIL_PROMPT)
  544.             npr(get_string(1366));
  545.           ch=onek("QSRIDAMF?-+GZPVUOC");
  546.         } else {
  547.           if (!okmail) {
  548.             if (sysinfo.flags & OP_FLAGS_MAIL_PROMPT)
  549.               npr(get_string(1367));
  550.             ch=onek("QI?-+G");
  551.           } else {
  552.             if (sysinfo.flags & OP_FLAGS_MAIL_PROMPT)
  553.               npr(get_string(1368));
  554.             ch=onek("QSRIDAMF?+-G");
  555.           }
  556.         }
  557.       }
  558.       if (okmail && !read_same_email(mloc, mw, curmail, &m, 0, 0)) {
  559.         nl();
  560.         pl(get_string(1273));
  561.         nl();
  562.         ch='R';
  563.       }
  564.       switch (ch) {
  565.         case 'N':
  566.           if (m.fromuser==1)
  567.             add_netsubscriber(m.fromsys);
  568.           else
  569.             add_netsubscriber(0);
  570.           break;
  571.         case 'E':
  572.           if ((so()) && (okmail)) {
  573.             b=readfile(&(m.msg),"EMAIL",&len);
  574.             extract_out(b,len,m.title);
  575.           }
  576.           i2=0;
  577.           break;
  578.         case 'Q':
  579.           done=1;
  580.           break;
  581.         case 'O':
  582.           if ((cs()) && (okmail) && (m.fromuser!=65535) && (nn!=255)) {
  583.             show_files("*.FRM",syscfg.gfilesdir);
  584.             prt(2,get_string(712));
  585.             mpl(8);
  586.             input(s,8);
  587.             if (!s[0])
  588.               break;
  589.             sprintf(s1,"%s%s.FRM",syscfg.gfilesdir,s);
  590.             if (!exist(s1))
  591.               sprintf(s1,"%sFORM%s.MSG",syscfg.gfilesdir,s);
  592.             if (exist(s1)) {
  593.               load_workspace(s1,1);
  594.               num_mail=((long) thisuser.feedbacksent) +
  595.                        ((long) thisuser.emailsent) +
  596.                        ((long) thisuser.emailnet);
  597.               grab_quotes(NULL, NULL);
  598.               if (m.fromuser!=65535)
  599.                 email(m.fromuser,m.fromsys,0,m.anony);
  600.               num_mail1=((long) thisuser.feedbacksent) +
  601.                         ((long) thisuser.emailsent) +
  602.                         ((long) thisuser.emailnet);
  603.               if (num_mail != num_mail1) {
  604.                 if (m.fromsys!=0)
  605.                   sprintf(s,"%s: %s",net_name,nam1(&thisuser,usernum,net_sysnum));
  606.                 else
  607.                   strcpy(s,nam1(&thisuser,usernum,net_sysnum));
  608.                 if (m.anony & anony_receiver)
  609.                   strcpy(s,get_string(482));
  610.                 strcat(s,get_string(713));
  611.                 strcat(s,date());
  612.                 if (!(m.status & status_source_verified))
  613.                   ssm(m.fromuser,m.fromsys,s);
  614.                 read_same_email(mloc, mw, curmail, &m, 1, 0);
  615.                 ++curmail;
  616.                 if (curmail>=mw)
  617.                   done=1;
  618.                 if (!wfc)
  619.                   topscreen();
  620.               } else {
  621.                 sprintf(s,"%sINPUT.MSG",syscfgovr.tempdir);/* need instance */
  622.                 unlink(s);
  623.               }
  624.             } else {
  625.               nl();
  626.               pl(get_string(89));
  627.               nl();
  628.               i2=0;
  629.             }
  630.           }
  631.           break;
  632.         case 'G':
  633.           ansic(2);
  634.           outstr(get_string(714));
  635.           npr("%u) ? ",mw);
  636.           ansic(0);
  637.           input(s,3);
  638.           i2=atoi(s);
  639.           if ((i2>0) && (i2<=mw)) {
  640.             curmail=i2-1;
  641.             i2=1;
  642.           } else
  643.             i2=0;
  644.           break;
  645.         case 'I':
  646.         case '+':
  647.           ++curmail;
  648.           if (curmail>=mw)
  649.             done=1;
  650.           break;
  651.         case '-':
  652.           if (curmail)
  653.             --curmail;
  654.            break;
  655.         case 'R':
  656.           break;
  657.         case '?':
  658.           printmenu(4);
  659.           i2=0;
  660.           break;
  661.         case 'D':
  662.           if (!okmail)
  663.             break;
  664.           if (m.fromsys!=0)
  665.             sprintf(s,"%s: %s",net_name,nam1(&thisuser,usernum,net_sysnum));
  666.           else
  667.             strcpy(s,nam1(&thisuser,usernum,net_sysnum));
  668.           if (m.anony & anony_receiver)
  669.             strcpy(s,get_string(482));
  670.           strcat(s,get_string(713));
  671.           strcat(s,date());
  672.           if ((!(m.status & status_source_verified)) && (nn!=255))
  673.             ssm(m.fromuser,m.fromsys,s);
  674.         case 'Z':
  675.           if (!okmail)
  676.             break;
  677.           read_same_email(mloc, mw, curmail, &m, 1, 0);
  678.           ++curmail;
  679.           if (curmail>=mw)
  680.             done=1;
  681.           if (!wfc)
  682.             topscreen();
  683.           break;
  684.         case 'P':
  685.           if (!okmail)
  686.             break;
  687.           purgemail(mloc,mw,&curmail,&m,&ss);
  688.           if (curmail>=mw)
  689.             done=1;
  690.           if (!wfc)
  691.             topscreen();
  692.           break;
  693.         case 'F':
  694.           if (!okmail)
  695.             break;
  696.           if (m.status & status_multimail) {
  697.             nl();
  698.             pl(get_string(715));
  699.             nl();
  700.             break;
  701.           }
  702.           nln(2);
  703.           prt(2,get_string(716));
  704.           input(s,75);
  705.           parse_email_info(s, &un, &sy);
  706.           if (un || sy) {
  707.             if (forwardm(&un, &sy)) {
  708.               pl(get_string(656));
  709.             }
  710.             if ((un==usernum) && (sy==0) && (!cs())) {
  711.               pl(get_string(469));
  712.               un=0;
  713.             }
  714.             if (un || sy) {
  715.               if (sy) {
  716.                 if (net_num_max>1) {
  717.                   if (un) {
  718.                     sprintf(s1,"%s #%u @%u",net_name, un, sy);
  719.                   } else {
  720.                     sprintf(s1,"%s %s @%u",net_name, net_email_name, sy);
  721.                   }
  722.                 } else {
  723.                   if (un) {
  724.                     sprintf(s1,"#%u @%u", un, sy);
  725.                   } else {
  726.                     sprintf(s1,"%s @%u", net_email_name, sy);
  727.                   }
  728.                 }
  729.               } else {
  730.                 set_net_num(nn);
  731.                 read_user(un,&u);
  732.                 strcpy(s1,nam1(&u,un,net_sysnum));
  733.               }
  734.               if (ok_to_mail(un, sy, 0)) {
  735.                 ansic(5);
  736.                 outstr(get_string(393));
  737.                 npr("%s? ",s1);
  738.                 if (yn()) {
  739.                   f=open_email(1);
  740.                   if (f<0)
  741.                     break;
  742.                   sh_lseek(f,((long) mloc[curmail].index) * sizeof(mailrec),SEEK_SET);
  743.                   sh_read(f,(void *) (&m),sizeof(mailrec));
  744.                   if (!same_email(mloc+curmail, &m)) {
  745.                     pl(get_string(1274));
  746.                     break;
  747.                   }
  748.  
  749.                   m1.touser=0;
  750.                   m1.tosys=0;
  751.                   m1.daten=0xffffffff;
  752.                   m1.msg.storage_type=0;
  753.                   m1.msg.stored_as=0xffffffff;
  754.                   sh_lseek(f,((long) mloc[curmail].index) * sizeof(mailrec),SEEK_SET);
  755.                   sh_write(f,(void *) (&m1),sizeof(mailrec));
  756.  
  757.                   f=sh_close(f);
  758.  
  759.                   i=net_num;
  760.                   sprintf(s,"\r\n%s: %s", get_string(717),
  761.                       nam1(&thisuser,usernum,net_sysnum));
  762.                   set_net_num(nn);
  763.                   lineadd(&m.msg,s,"EMAIL");
  764.                   sprintf(s,"%s %s %s",
  765.                       nam1(&thisuser,usernum,net_sysnum),
  766.                       get_string(718), s1);
  767.                   if (!(m.status & status_source_verified))
  768.                     ssm(m.fromuser,m.fromsys,s);
  769.                   set_net_num(i);
  770.                   sprintf(s,get_stringx(1,101), s1);
  771.                   --thisuser.waiting;
  772.                   if (usernum==1)
  773.                     --fwaiting;
  774.                   outstr(get_string(720));
  775.                   if ((nn!=255) && ((status.net_version>=32) || (nn==net_num))) {
  776.                     sendout_email(m.title, &m.msg, m.anony, un, sy, 1,
  777.                                   m.fromuser, m.fromsys?m.fromsys:net_networks[nn].sysnum, 1, nn);
  778.                   } else {
  779.                     sendout_email(m.title, &m.msg, m.anony, un, sy, 1,
  780.                                   usernum, net_sysnum, 1, net_num);
  781.                   }
  782.                   ++curmail;
  783.                   if (curmail>=mw)
  784.                     done=1;
  785.                   if (!wfc)
  786.                     topscreen();
  787.                   mailcheck=1;
  788.                 }
  789.               }
  790.             }
  791.           }
  792.           break;
  793.         case 'A':
  794.         case 'S':
  795.         case 'M':
  796.           if (rip_on()) {
  797.             sprintf(s,"\n!|w000%c271610|e|#\r ", formery);
  798.             comstr(s);
  799.           }
  800.           if (!okmail)
  801.             break;
  802.           if (menu_on())
  803.             printmenu(321);
  804.           num_mail=((long) thisuser.feedbacksent) +
  805.                    ((long) thisuser.emailsent) +
  806.                    ((long) thisuser.emailnet);
  807.           if (nn==255) {
  808.             pl(get_string(679));
  809.             i2=0;
  810.             break;
  811.           } else if (m.fromuser!=65535) {
  812.             grab_quotes(&(m.msg),"EMAIL");
  813.             if (ch=='M') {
  814.               nl();
  815.               pl(get_string(15));
  816.               outstr(":");
  817.               input(s,75);
  818.               parse_email_info(s, &un, &sy);
  819.               if (un || sy) {
  820.                 email(un, sy, 0, 0);
  821.               }
  822.             } else {
  823.               email(m.fromuser,m.fromsys,0,m.anony);
  824.             }
  825.             grab_quotes(NULL, NULL);
  826.           }
  827.           num_mail1=((long) thisuser.feedbacksent) +
  828.                     ((long) thisuser.emailsent) +
  829.                     ((long) thisuser.emailnet);
  830.           if ((ch=='A') || (ch=='M')) {
  831.             if (num_mail!=num_mail1) {
  832.               if (m.fromsys!=0)
  833.                 sprintf(s,"%s: %s",net_name,nam1(&thisuser,usernum,net_sysnum));
  834.               else
  835.                 strcpy(s,nam1(&thisuser,usernum,net_sysnum));
  836.               if (m.anony & anony_receiver)
  837.                 strcpy(s,get_string(482));
  838.               strcat(s,get_string(713));
  839.               strcat(s,date());
  840.               if (!(m.status & status_source_verified))
  841.                 ssm(m.fromuser,m.fromsys,s);
  842.               read_same_email(mloc, mw, curmail, &m, 1, 0);
  843.               ++curmail;
  844.               if (curmail>=mw)
  845.                 done=1;
  846.               if (!wfc)
  847.                 topscreen();
  848.             } else {
  849.               nl();
  850.               pl(get_string(721));
  851.               nl();
  852.               i2=0;
  853.             }
  854.           } else {
  855.             if (num_mail != num_mail1) {
  856.               if (!(m.status & status_replied)) {
  857.                 read_same_email(mloc, mw, curmail, &m, 0, status_replied);
  858.               }
  859.               ++curmail;
  860.               if (curmail>=mw)
  861.                 done=1;
  862.               if (!wfc)
  863.                 topscreen();
  864.             }
  865.           }
  866.           if (menu_on())
  867.             printmenu(4);
  868.           break;
  869.         case 'U':
  870.         case 'V':
  871.         case 'C':
  872.           if (!okmail)
  873.             break;
  874.           if ((m.fromsys==0) && (cs()) && (m.fromuser!=65535))
  875.             if (ch=='V')
  876.               valuser(m.fromuser);
  877.             else if (ch=='U')
  878.               uedit(m.fromuser,0);
  879.             else
  880.               uedit(m.fromuser,3);
  881.           else if (cs()) {
  882.             nl();
  883.             pl(get_string(722));
  884.             nl();
  885.           }
  886.           i2=0;
  887.           break;
  888.         case 'L':
  889.           if (!so())
  890.             break;
  891.           nl();
  892.           prt(2,get_string(7));
  893.           input(s,50);
  894.           if (s[0]) {
  895.             nl();
  896.             prt(5,get_string(17));
  897.             if (yn()) {
  898.               nl();
  899.               load_workspace(s,0);
  900.             } else {
  901.               nl();
  902.               load_workspace(s,1);
  903.             }
  904.           }
  905.           break;
  906.       }
  907.     } while ((!i2) && (!hangup));
  908.   } while ((!hangup) && (!done));
  909.  
  910.   bbsfree(mloc);
  911. }
  912.