/* ======================================================================== */ /* ======================== MAILBOX ROUTINES =========================== */ /* ======================================================================== */ struct hdrstruc { unsigned char msg_no[8]; unsigned char msg_ndx[8]; unsigned char msg_len[8]; unsigned char date[20]; unsigned char flags[4]; unsigned char from[20]; unsigned char to[20]; unsigned char title[30]; }; struct hdrstruc msghdr; int cur_msgno; long cur_ndx; int hdrf,msgf; char itoastr[20]; char cr_lf[2]={13,10}; mbox() { unsigned char mstr[81]; int i,c,exists,youhavemail; textattr(MIDBARCOLOR); gotoxy(3,20); cprintf("MAILBOX MODE Sysop Cmds: B,K,L,P,R,S"); textattr(RCVCOLOR); exists=0; if((hdrf = _open("MSGS.HDR",O_RDWR|O_TEXT)) == -1) _creat("MSGS.HDR",0); else { exists=1; _close(hdrf); } if((msgf = _open("MSGS.TXT",O_RDWR|O_TEXT)) == -1) _creat("MSGS.TXT",0); else _close(msgf); hdrf = _open("MSGS.HDR",O_RDWR|O_TEXT); msgf = _open("MSGS.TXT",O_RDWR|O_TEXT); if(exists) { cur_ndx = lseek(msgf,0l,SEEK_END); if(filelength(hdrf) != 0l) { lseek(hdrf,-118l,SEEK_END); _read(hdrf,&msghdr,118); cur_msgno = atoi(msghdr.msg_no)-1; cur_msgno++; } else cur_msgno = 0; } else { cur_ndx = 0l; cur_msgno=0; } while(1) { strcpy(scanstr," "); while(! connected()) { chk_time(); if(kbhit()) { c = getch(); if(c == 0) { c = getch(); switch(c){ case 0x47: scrsav(); break; } } else { switch(toupper(c)){ case 'S': sysop_enter_msg(); break; case 'L': sysop_list_msgs(); break; case 'R': sysop_read_msg(); break; case 'K': sysop_kill_msg(); break; case 'P': purge_msgs(); break; case 'B' : goto exit_mbox; } } } } youhavemail = FALSE; lseek(hdrf,0l,SEEK_SET); for(i=0;i>>",1); send_string("",1); send_string("I'm not here at the moment, so Pse leave a message.",1); send_string("",1); send_string("Available Commands:",1); send_string("B Bye (Logout)",1); send_string("K # Kill msg number #",1); send_string("L List msgs",1); send_string("R # Read msg number #",1); send_string("S Send msg to SM5SXL",1); if(youhavemail) { send_string("",1); send_string("You have Mail!",1); } while(1) { send_string("",1); send_string("Enter Command (B,K,L,R,S) >",0); waitfor_string("S) >"); comm_send(''); if(! rcv_string(mstr)) goto abort_user; strcpy(mstr,strupr(mstr)); i=0; while(mstr[i] <= 0x20) i++; switch(mstr[i]) { case 'S': if(! enter_msg()) goto abort_user; break; case 'L': list_msgs(); break; case 'R': read_msg(mstr,i); break; case 'K': kill_msg(mstr,i); break; case 'B': goto bye; } } bye: comm_send(''); send_string("",1); send_string("Bye bye...",1); waitfor_string("..\015\012"); comm_send(0x03); delay(200); send_string("D",1); abort_user: ; } exit_mbox: _close(hdrf); _close(msgf); textattr(MIDBARCOLOR); gotoxy(3,20); cprintf(" "); dirwr(' ',50,1,MAILCOLOR); textattr(XMITCOLOR); } connected() { if((comm_in = comm_rcv()) != 0) { in = comm_in & 0xff; out_aux_char(); strcpy(scanstr, &scanstr[1]); scanstr[29] = in; if(strstr(scanstr,"*** CONNECTED to ")) { rcv_string(mbox_cs); return 1; } } return 0; } enter_msg() { int msglen; unsigned char msgstr[81]; strcpy(msghdr.msg_no,itoa(cur_msgno+1,itoastr,10)); strcpy(msghdr.msg_ndx,ltoa(cur_ndx,itoastr,10)); strcpy(msghdr.date,utcstr); strcpy(msghdr.flags,"N"); strcpy(msghdr.from,mbox_cs); strcpy(msghdr.to,"SM5SXL"); comm_send(''); send_string("",1); send_string("Title: ",0); waitfor_string("le: "); comm_send(''); if(! rcv_string(msghdr.title)) goto error; comm_send(''); send_string("Enter message text. End with /EX on a new line.",1); waitfor_string("e.\015\012"); comm_send(''); lseek(msgf,cur_ndx,SEEK_SET); msglen=0; while(1){ if(! rcv_string(msgstr)) goto error; _write(msgf,msgstr,strlen(msgstr)); _write(msgf,cr_lf,2); cur_ndx += (long)(strlen(msgstr)+2); msglen += (strlen(msgstr)+2); if(strstr(strupr(msgstr),"/EX")) break; } strcpy(msghdr.msg_len,itoa(msglen,itoastr,10)); lseek(hdrf,(long)(cur_msgno*118),SEEK_SET); _write(hdrf,&msghdr,118); cur_msgno++; comm_send(''); send_string("Message stored OK.",1); dirwr('M',50,1,MAILCOLOR); return 1; error: return 0; } list_msgs() { int i; unsigned char tmp[81]; comm_send(''); lseek(hdrf,0l,SEEK_SET); send_string("",1); send_string( "Msg No Date Time Flags From To Title",1); send_string("",1); for(i=0;i