home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
MSGBASE.C
< prev
next >
Wrap
Text File
|
1992-06-16
|
38KB
|
1,695 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988-1991 by Wayne Bell
Distribution of the source code for WWIV, in any form, modified or unmodified,
without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
Distribution of compiled versions of WWIV is limited to copies compiled BY
THE AUTHOR. Distribution of any copies of WWIV not compiled by the author
is expressly prohibited.
*****************************************************************************/
#include "vars.h"
#pragma hdrstop
#include <mem.h>
#define ALLOW_FULLSCREEN 1
#define EMAIL_STORAGE 2
/****************************************************************************/
void describe_area_code(int areacode, char *description)
{
int f,done=0,i;
char s[81],*ss,*ss1;
description[0]=0;
sprintf(s,"%sREGIONS.DAT",syscfg.datadir);
f=open(s,O_RDWR | O_TEXT);
if (f<1)
return;
ss=malloca(filelength(f));
i=read(f,ss,filelength(f));
ss[i]=0;
close(f);
ss1=strtok(ss,"\n");
while (ss1 && (!done)) {
i=atoi(ss1);
if (i) {
if (i==areacode)
done=1;
} else
strcpy(description,ss1);
ss1=strtok(NULL,"\n");
}
farfree(ss);
}
/****************************************************************************/
static char origin_str[81];
void setorigin(int sysnum, int usernum)
{
int i;
char s[81],ch;
net_system_list_rec *csne;
origin_str[0]=0;
if (sysnum) {
csne=next_system(sysnum);
if (csne) {
ch=' ';
if (usernum==1) {
if (csne->other & other_net_coord)
ch='&';
else if (csne->other & other_group_coord)
ch='%';
else if (csne->other & other_coordinator)
ch='^';
}
describe_area_code(atoi(csne->phone),s);
if (s[0])
sprintf(origin_str,"%c%s (%s)",ch,csne->name,s);
else
sprintf(origin_str,"%c%s [%s]",ch,csne->name,csne->phone);
} else
strcpy(origin_str,"3 Dunno where it came from.");
}
}
int okfsed()
{
int ok;
ok=ALLOW_FULLSCREEN;
if (!okansi())
ok=0;
if (!thisuser.defed)
ok=0;
if (thisuser.defed>numed)
ok=0;
return(ok);
}
void remove_link(messagerec *m1, char *aux)
{
messagerec m;
char s[81],s1[81];
int f;
long csec,nsec;
m=*m1;
strcpy(s,syscfg.msgsdir);
switch(m.storage_type) {
case 0:
case 1:
ltoa(m.stored_as,s1,16);
if (m.storage_type==1) {
strcat(s,aux);
strcat(s,"\\");
}
strcat(s,s1);
unlink(s);
break;
case 2:
f=open_file(aux);
csec=m.stored_as;
while ((csec>0) && (csec<2048)) {
nsec=(long) gat[csec];
gat[csec]=0;
csec=nsec;
}
lseek(f,0L,SEEK_SET);
write(f,(void *)gat,4096);
close(f);
break;
default:
/* illegal storage type */
break;
}
}
int open_file(char *fn)
{
int f,i;
char s[81];
sprintf(s,"%s%s.DAT",syscfg.msgsdir,fn);
f=open(s,O_RDWR | O_BINARY);
if (f<0) {
f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
for (i=0; i<2048; i++)
gat[i]=0;
write(f,(void *)gat,4096);
strcpy(gatfn,fn);
chsize(f,4096L + (75L * 1024L));
}
if (strcmp(gatfn,fn)) {
lseek(f,0L,SEEK_SET);
read(f,(void *)gat,4096);
strcpy(gatfn,fn);
}
return(f);
}
void savefile(char *b, long l1, messagerec *m1, char *aux)
{
int f,gatp,i5,i4,gati[128];
messagerec m;
char s[81],s1[81];
m=*m1;
switch(m.storage_type) {
case 0:
case 1:
m.stored_as=status.qscanptr++;
save_status();
ltoa(m.stored_as,s1,16);
strcpy(s,syscfg.msgsdir);
if (m.storage_type==1) {
strcat(s,aux);
strcat(s,"\\");
}
strcat(s,s1);
f=open(s,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
write(f, (void *)b,l1);
close(f);
break;
case 2:
f=open_file(aux);
gatp=0;
i5=(int) ((l1 + 511L)/512L);
i4=1;
while ((gatp<i5) && (i4<2048)) {
if (gat[i4]==0)
gati[gatp++]=i4;
++i4;
}
gati[gatp]=-1;
for (i4=0; i4<i5; i4++) {
lseek(f,4096L + 512L * (long)(gati[i4]),SEEK_SET);
write(f,(void *)(&b[i4*512]),512);
gat[gati[i4]]=gati[i4+1];
}
lseek(f,0L,SEEK_SET);
write(f,(void *)gat,4096);
close(f);
m.stored_as=(long) gati[0];
break;
case 255:
f=open(aux,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
write(f, (void *)b,l1);
close(f);
break;
default:
sprintf(s,"Illegal storage type of %u on save!",m.storage_type);
pl(s);
break;
}
farfree((void *)b);
*m1=m;
}
char *readfile(messagerec *m1, char *aux, long *l)
{
int f,i,i1,csec;
long l1,l2;
char *b,s[81],s1[81];
messagerec m;
*l=0L;
m=*m1;
switch(m.storage_type) {
case 0:
case 1:
strcpy(s,syscfg.msgsdir);
ltoa(m.stored_as,s1,16);
if (m.storage_type==1) {
strcat(s,aux);
strcat(s,"\\");
}
strcat(s,s1);
f=open(s,O_RDONLY | O_BINARY);
if (f==-1) {
*l=0L;
return(NULL);
}
l1=filelength(f);
if ((b=malloca(l1))==NULL) {
close(f);
return(NULL);
}
read(f,(void *)b,l1);
close(f);
*l=l1;
break;
case 2:
f=open_file(aux);
csec=m.stored_as;
l1=0;
while ((csec>0) && (csec<2048)) {
l1+=512L;
csec=gat[csec];
}
if (!l1) {
nl();
pl("No message found.");
nl();
return(NULL);
}
if ((b=malloca(l1))==NULL)
return(NULL);
csec=m.stored_as;
l1=0;
while ((csec>0) && (csec<2048)) {
lseek(f,4096L + 512L*csec,SEEK_SET);
l1+=(long)read(f,(void *)(&(b[l1])),512);
csec=gat[csec];
}
close(f);
l2=l1-512;
while ((l2<l1) && (b[l2]!=26))
++l2;
*l=l2;
break;
case 255:
f=open(aux,O_RDONLY | O_BINARY);
if (f==-1) {
*l=0L;
return(NULL);
}
l1=filelength(f);
if ((b=malloca(l1+256L))==NULL)
return(NULL);
read(f,(void *)b,l1);
close(f);
*l=l1;
break;
default:
/* illegal storage type */
*l=0L;
b=NULL;
break;
}
return(b);
}
void change_storage(messagerec *oldm, char *olda, messagerec *newm, char *newa)
{
long len;
char *b;
b=readfile(oldm,olda,&len);
remove_link(oldm,olda);
savefile(b,len,newm,newa);
}
void load_workspace(char *fnx, int no_edit)
{
int i,i5;
long l;
char *b,s[81];
i5=open(fnx,O_RDONLY | O_BINARY);
if (i5<1) {
nl();
pl("File not found.");
nl();
return;
}
l=filelength(i5);
if ((b=malloca(l+1024))==NULL) {
close(i5);
return;
}
read(i5, (void *) b,l);
close(i5);
if (b[l-1]!=26)
b[l++]=26;
sprintf(s,"%sINPUT.MSG",syscfg.tempdir);
i5=open(s,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
write(i5, (void *)b,l);
close(i5);
farfree(b);
if ((no_edit) || (!okfsed()))
use_workspace=1;
else
use_workspace=0;
nl();
pl("1Yes, the file is loaded.");
nl();
if (!use_workspace)
pl("3Ok, you can edit.");
}
void osan(char *s, int *abort, int *next)
{
int i;
i=0;
checkhangup();
if (hangup)
*abort=1;
checka(abort,next);
while ((s[i]) && (!(*abort))) {
outchr(s[i++]);
checka(abort,next);
}
}
void addline(char *b, char *s, long *ll)
{
strcpy(&(b[*ll]),s);
*ll +=strlen(s);
strcpy(&(b[*ll]),"\r\n");
*ll += 2;
}
#define LEN 161
void stuff(char *s, char *old, char *new)
{
char s1[LEN],*ss;
if (strlen(s)-strlen(old)+strlen(new)>=LEN)
return;
ss=strstr(s,old);
if (ss==NULL)
return;
ss[0]=0;
sprintf(s1,"%s%s%s",s,new,ss+strlen(old));
strcpy(s,s1);
}
void inmsg(messagerec *m1, char *title, int *anony, int needtitle, char *aux, int fsed)
{
char s[LEN],s1[LEN],s2[LEN],ro[81],fnx[81],chx,*ss,*ss1;
int maxli,curli,done,save,savel,i,i1,i2,i3,i4,i5,f,setanon,gati[50],gatp;
messagerec m;
long ll,l1;
char *lin, *b;
int real_name=0;
if ((fsed!=0) && (!okfsed()))
fsed=0;
sprintf(fnx,"%sINPUT.MSG",syscfg.tempdir);
if (fsed)
fsed=1;
if (use_workspace) {
if (!exist(fnx))
use_workspace=0;
else
fsed=2;
}
done=0;
setanon=0;
save=0;
curli=0;
m=*m1;
if (actsl<45)
maxli=30;
else
if (actsl<60)
maxli=50;
else
if (actsl<80)
maxli=60;
else
maxli=80;
if (!fsed) {
if ((lin=malloca((long)(maxli+10)*LEN))==NULL) {
m1->stored_as=0xffffffff;
return;
}
for (i=0; i<maxli; i++)
lin[i*LEN]=0;
ro[0]=0;
}
nl();
helpl=6;
if (okansi()) {
prt(7,"[1Title7]3: ");
inli(title,ro,70,1);
} else {
pl(" 7 ══════════════════════3The Devil's Doorknob7══════════════════");
outstr("7[1Title7]3: ");
inli(title,ro,70,1);
}
if ((title[0]==0) && (needtitle)) {
pl("6Aborted.");
m.stored_as=0xffffffff;
*m1=m;
if (!fsed)
farfree((void *)lin);
return;
}
if (!fsed) {
sprintf(s,"7Enter message now, max %u lines.",maxli);
pl(s);
pl("5Enter '/HELP' for help.");
strcpy(s,"7══════════════════════════════3The Devil's Doorknob7══════════════════════════════");
s[thisuser.screenchars]=0;
pl(s);
while (!done) {
helpl=27;
inli(s,ro,160,1);
if (hangup)
done=1;
savel=1;
if (s[0]=='/') {
if (stricmp(s,"/HELP")==0) {
savel=0;
printmenu(2);
}
if (stricmp(s,"/LI")==0) {
savel=0;
prt(5,"You wanna see line numbers? ");
i1=yn();
i2=0;
for (i=0; (i<curli) && (!i2); i++) {
if (i1)
npr("%d:\r\n",i+1);
strcpy(s1,&(lin[i*LEN]));
i3=strlen(s1);
if (s1[i3-1]==1)
s1[i3-1]=0;
if (s1[0]==2) {
strcpy(s1,&(s1[1]));
i5=0;
for(i4=0; i4<strlen(s1); i4++)
if ((s1[i4]==8) || (s1[i4]==3))
--i5;
else
++i5;
for (i4=0; (i4<(thisuser.screenchars-i5)/2) && (!i2); i4++)
osan(" ",&i2,&i1);
}
pla(s1,&i2);
}
nl();
pl("1Ok, go ahead...");
}
if ((stricmp(s,"/ES")==0) || (stricmp(s,"/S")==0)) {
save=1;
done=1;
savel=0;
outstr("1Would you like a reply5?");
if (yn()) {
curli++;
strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1Answer this or die."); }
else {
curli++;
strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1No Response Needed."); }
}
if ((stricmp(s,"/ESY")==0) || (stricmp(s,"/SY")==0)) {
save=1;
done=1;
savel=0;
setanon=1;
outstr("1Would you like a reply5?");
if (yn()) {
curli++;
strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1Answer this or die."); }
else {
curli++;
strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1No Response Needed."); }
}
if ((stricmp(s,"/ESN")==0) || (stricmp(s,"/SN")==0)) {
save=1;
done=1;
savel=0;
setanon=-1;
outstr("1Would you like a reply5?");
if (yn()) {
curli++;
strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1Answer this or die."); }
else {
curli++;
strcpy(&(lin[(curli++) *LEN]), "7[1MSG5. 1STATUS7]5: 1No Response Needed."); }
}
if (stricmp(s,"/ABT")==0) {
done=1;
savel=0;
}
if (stricmp(s,"/CLR")==0) {
savel=0;
curli=0;
pl("1Message cleared... Start over...");
nl();
}
if (stricmp(s,"/RL")==0) {
savel=0;
if (curli) {
--curli;
pl("1Replace:");
} else {
pl("1Nothing to replace.");
}
}
if (stricmp(s,"/TI")==0) {
savel=0;
helpl=26;
if (okansi()) {
prt(7,"[1Title7]3: ");
inli(title,ro,70,1);
} else {
pl(" 7════════════════════════3The Devil's Doorknob7════════════════");
outstr("7[1Title7]3: ");
inli(title,ro,70,1);
}
pl("1Ok, go ahead...");
nl();
}
strcpy(s1,s);
s1[3]=0;
if (stricmp(s1,"/C:")==0) {
s1[0]=2;
strcpy((&s1[1]),&(s[3]));
strcpy(s,s1);
}
if ((stricmp(s1,"/SU")==0) && (s[3]=='/') && (curli)) {
strcpy(s1,&(s[4]));
ss=strstr(s1,"/");
if (ss) {
ss1=&(ss[1]);
ss[0]=0;
stuff(&(lin[(curli-1)*LEN]),s1,ss1);
pl("1Last line:");
pl(&(lin[(curli-1)*LEN]));
pl("1Ok, go ahead...");
}
savel=0;
}
}
if (savel) {
strcpy(&(lin[(curli++)*LEN]),s);
if (curli==maxli) {
nl();
pl("6-= No more lines =-");
pl("/ES to save");
nl();
--curli;
}
}
}
if (curli==0)
save=0;
} else {
if (fsed==1) {
save=external_edit("INPUT.MSG",syscfg.tempdir,(int) (thisuser.defed)-1,maxli);
} else {
save=exist(fnx);
if (save) {
pl("3Reading in file...");
}
use_workspace=0;
}
}
if (save) {
switch(*anony) {
case 0: /* no anony */
*anony=0;
break;
case anony_enable_anony:
if (setanon) {
if (setanon==1)
*anony=anony_sender;
else
*anony=0;
} else {
prt(5,"Anonymous? ");
if (yn())
*anony=anony_sender;
else
*anony=0;
}
break;
case anony_enable_dear_abby:
nl();
npr("117.3 %s\r\n",nam(&thisuser,usernum));
pl("127.3 Just a lost soul swimmin' in a fish bowl");
pl("137.3 Problemed Person");
nl();
prt(5,"Which? ");
chx=onek("\r123");
switch(chx) {
case '\r':
case '1':
*anony=0;
break;
case '2':
*anony=anony_sender_da;
break;
case '3':
*anony=anony_sender_pp;
}
break;
case anony_force_anony:
*anony=anony_sender;
break;
case anony_real_name:
real_name=1;
*anony=0;
break;
}
outstr("3Saving...\r\n");
if (fsed) {
i5=open(fnx,O_RDONLY | O_BINARY);
l1=filelength(i5);
} else {
l1=0;
for (i5=0; i5<curli; i5++) {
l1 += strlen(&(lin[i5*LEN]));
l1 += 2;
}
}
l1 += 1024;
if ((b=malloca(l1))==NULL) {
farfree(lin);
pl("Out of memory.");
m1->stored_as=0xffffffff;
return;
}
l1=0;
if (real_name){
addline(b,thisuser.realname,&l1);
} else {
/*addline(b,nam1(&thisuser,usernum,syscfg.systemnumber),&l1);*/
strcpy(s,nam1(&thisuser,usernum,syscfg.systemnumber));
if (actsl<255)
sprintf(s1," 1[5Immortal1]");
if (actsl<70)
sprintf(s1," 1[5Average Joe Schmoe1]");
if (actsl<50)
sprintf(s1," 1[5No Comment1]");
if (actsl<11)
sprintf(s1," 1[5New User1]");
if (usernum==1)
sprintf(s1," 1[5Goddess1]");
if (usernum==4)
sprintf(s1," 1[5Enzyme Boy1]");
if (usernum==2)
sprintf(s1," 1[5God1]");
if (usernum==7)
sprintf(s1," 1[5Net Coordinator1]");
if (usernum==56)
sprintf(s1," 1[5Oh Baby!1]");
strcat(s,s1);
addline(b,s,&l1);}
time(&ll);
strcpy(s,ctime(&ll));
s[strlen(s)-1]=0;
addline(b,s,&l1);
sprintf(s,"7──────────────────────────────────────────────────────────────────────────────");
addline(b,s,&l1);
if (irt[0]) {
sprintf(s,"7[1RE7]7:3 %s",irt);
addline(b,s,&l1);
if (irt_name[0]) {
sprintf(s,"7[1BY7]7:3 %s",irt_name);
addline(b,s,&l1);
}
addline(b,"",&l1);
}
if (fsed) {
ll=filelength(i5);
read(i5, (void *) (& (b[l1]) ),ll);
l1 += ll;
close(i5);
} else {
for (i5=0; i5<curli; i5++)
addline(b,&(lin[i5*LEN]),&l1);
}
if (thisuser.ass_pts>0) {
sprintf(s,"\r\n7[1Comment7]3:cI have %d ass points!",thisuser.ass_pts);
addline(b,s,&l1);
}
if ((subboards[curlsub].type) && (syscfg.systemnumber))
{
addline(b,"",&l1);
addline(b,"
┌────────────────────────────────────────────────────────┐",&l1);
addline(b,"
│
The Devil's Doorknob
·
(
410
)
442
-
1601
·
≡
BamaNet
≡
Node 1002
│",&l1);
addline(b,"
└────────────────────────────────────────────────────────┘",&l1);
}
prt(5,"Do you want your Personal Tag displayed? ");
if (yn())
{
addline(b," ",&l1);
sprintf(s,"7[1Personal Tag7]7:3 %s",thisuser.note);
addline(b,s,&l1);
}
if (b[l1-1]!=26)
b[l1++]=26;
savefile(b,l1,&m,aux);
if (fsed)
unlink(fnx);
} else {
if (fsed)
unlink(fnx);
pl("6Aborted.");
m.stored_as=0xffffffff;
}
*m1=m;
if (!fsed) {
farfree((void *)lin);
}
charbufferpointer=0;
charbuffer[0]=0;
}
int forwardm(unsigned short *u, unsigned short *s)
{
userrec ur;
char *ss;
int i,i1,cu;
if (*s)
return(0);
read_user(*u,&ur);
if (ur.inact & inact_deleted)
return(0);
if ((ur.forwardusr==0) && (ur.forwardsys==0))
return(0);
if (ur.forwardsys) {
if ((ur.forwardusr>0) && (ur.forwardusr<32767)) {
if (!next_system(ur.forwardsys))
return(0);
*u=ur.forwardusr;
*s=ur.forwardsys;
return(1);
} else {
*u=0;
*s=0;
return(0);
}
}
cu=ur.forwardusr;
if ((ss=malloca((long) syscfg.maxusers+ 300L))==NULL)
return(0);
for (i=0; i<syscfg.maxusers+300; i++)
ss[i]=0;
ss[*u]=1;
read_user(cu,&ur);
while ((ur.forwardusr) || (ur.forwardsys)) {
if (ur.forwardsys) {
if (!next_system(ur.forwardsys))
return(0);
*u=ur.forwardusr;
*s=ur.forwardsys;
farfree(ss);
return(1);
}
if (ss[cu]) {
farfree(ss);
return(0);
}
ss[cu]=1;
cu=ur.forwardusr;
read_user(cu,&ur);
}
farfree(ss);
*s=0;
*u=cu;
return(1);
}
void sendout_email(char *title, messagerec *msg, int anony, unsigned un, unsigned sy, int an)
{
mailrec m,m1;
net_header_rec nh;
int f,len,i,i1;
char *b,*b1,s[129],s2[129],s1[129];
long len1;
userrec ur;
strcpy(m.title, title);
m.msg=*msg;
m.anony=anony;
m.fromsys=0;
m.fromuser=usernum;
m.tosys=sy;
m.touser=un;
m.status=0;
time((long *)&(m.daten));
sprintf(s,"%sEMAIL.DAT",syscfg.datadir);
if (sy==0) {
f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
if (!f) {
return;
}
len=(int) filelength(f)/sizeof(mailrec);
if (len==0)
i=0;
else {
i=len-1;
lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
read(f,(void *)&m1,sizeof(mailrec));
while ((i>0) && (m1.tosys==0) && (m1.touser==0)) {
--i;
lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
i1=read(f,(void *)&m1,sizeof(mailrec));
if (i1==-1)
pl("DIDN'T READ RIGHT.");
}
if ((m1.tosys) || (m1.touser))
++i;
}
lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
i1=write(f,(void *)&m,sizeof(mailrec));
if (i1==-1) {
pl("DIDN'T SAVE RIGHT!");
}
close(f);
} else {
if ((b=readfile(&(m.msg),"EMAIL",&len1))==NULL)
return;
remove_link(&(m.msg),"EMAIL");
nh.tosys=sy;
nh.touser=un;
nh.fromsys=syscfg.systemnumber;
nh.fromuser=usernum;
nh.main_type=main_type_email;
nh.minor_type=0;
nh.list_len=0;
nh.daten=m.daten;
nh.method=0;
if ((b1=malloca(len1+300))==NULL) {
farfree(b);
return;
}
i=0;
if (un==0) {
nh.main_type=main_type_email_name;
strcpy(&(b1[i]),net_email_name);
i+= strlen(net_email_name)+1;
}
strcpy(&(b1[i]),m.title);
i += strlen(m.title)+1;
memmove(&(b1[i]),b,(unsigned int) len1);
nh.length=len1+(long)i;
if (nh.length > 32760) {
nh.length = 32760;
npr("Message truncated by %lu bytes for the network.\r\n",nh.length-32760L);
}
sprintf(s,"%sP0.NET",syscfg.datadir);
f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
lseek(f,0L,SEEK_END);
write(f,(void *)&nh,sizeof(net_header_rec));
write(f,(void *)b1,nh.length);
close(f);
farfree(b);
farfree(b1);
}
s2[0]=0;
strcpy(s,"7Mail sent to ");
if (sy==0) {
read_user(un,&ur);
++ur.waiting;
write_user(un,&ur);
close_user();
if (un==1)
++fwaiting;
if (an) {
strcat(s,nam(&ur,un));
sysoplog(s);
} else {
strcpy(s1,s);
strcat(s1,nam(&ur,un));
sysoplog(s1);
strcat(s,"1>7UNKNOWN1<");
}
} else {
if (un==0)
sprintf(s1,"%s @%u",net_email_name,sy);
else
sprintf(s1,"User %u @%u",un,sy);
strcat(s,s1);
sysoplog(s);
}
if ((un==1) && (sy==0)) {
++status.fbacktoday;
++thisuser.feedbacksent;
++thisuser.fsenttoday1;
++fsenttoday;
} else {
++status.emailtoday;
++thisuser.etoday;
if (sy==0) {
++thisuser.emailsent;
} else {
++thisuser.emailnet;
/* len1=nh.length+sizeof(net_header_rec); */
/* fl = (csne->cost) * ((float)len1) / 1024.0; */
/* sprintf(s2,"Total cost: $%6.2f",fl); */
}
}
save_status();
if (!wfc)
topscreen();
pl(s);
if (s2[0])
pl(s2);
}
void email(unsigned short un, unsigned short sy, int forceit, int anony)
{
int i,i1,f,len,an;
messagerec msg;
char s[81],s1[81],s2[81],t[81],*b,*b1;
userrec ur;
slrec ss;
long len1;
float fl;
unsigned int ui;
net_system_list_rec *csne;
if (freek1(syscfg.msgsdir)<10.0) {
nl();
pl("Sorry, not enough disk space left.");
nl();
return;
}
nl();
sprintf(s,"%sEMAIL.DAT",syscfg.datadir);
ss=syscfg.sl[actsl];
if (forwardm(&un,&sy)) {
nl();
pl("7Mail Forwarded.");
nl();
if ((un==0) && (sy==0)) {
pl("Forwarded to unknown user.");
return;
}
}
if ((sy!=0) && (syscfg.systemnumber==0)) {
nl();
pl("Sorry, this system is not a part of WWIVnet.");
nl();
return;
}
if (sy==0) {
read_user(un,&ur);
if (((ur.sl==255) && (ur.waiting>(syscfg.maxwaiting * 5))) ||
((ur.sl!=255) && (ur.waiting>syscfg.maxwaiting)) ||
(ur.waiting>200)) {
if (!forceit) {
nl();
pl("Mailbox full.");
nl();
return;
}
}
if (ur.inact & inact_deleted) {
nl();
pl("Deleted user.");
nl();
return;
}
} else {
if ((csne=next_system(sy))==NULL) {
nl();
pl("Unknown system number.");
nl();
return;
}
if (thisuser.restrict & restrict_net) {
nl();
pl("You can't send mail off the system.");
return;
}
}
if (forceit==0) {
if ((((un==1) && (sy==0) && ((fsenttoday>=5) || (thisuser.fsenttoday1>=10))) ||
((un!=1) && (thisuser.etoday>=ss.emails))) && (!cs())) {
nl();
pl("Too much mail sent today.");
nl();
return;
}
if ((restrict_email & thisuser.restrict) && (un!=1)) {
nl();
pl("You can't send mail.");
nl();
return;
}
}
if (ss.ability & ability_read_email_anony)
an=1;
else
if (anony & (anony_sender | anony_sender_da | anony_sender_pp))
an=0;
else
an=1;
if (sy==0) {
if (an) {
read_user(un,&ur);
strcpy(s2,nam(&ur,un));
} else
strcpy(s2,"1>7UNKNOWN1<");
} else {
if (un==0)
sprintf(s2,"%s @%u",net_email_name,sy);
else
sprintf(s2,"User %u @%u",un,sy);
}
npr("1E-mailing %s\r\n",s2);
if (ss.ability & ability_email_anony)
i=anony_enable_anony;
else
i=0;
if (anony & (anony_receiver_pp | anony_receiver_da))
i=anony_enable_dear_abby;
if (anony & anony_receiver)
i=anony_enable_anony;
if ((i==anony_enable_anony) && (thisuser.restrict & restrict_anony))
i=0;
if (sy!=0) {
i=0;
anony=0;
nl();
sprintf(s,"3Name of system: '%s'",csne -> name);
pl(s);
sprintf(s,"3Number of hops: %u",csne->numhops);
pl(s);
nl();
}
msg.storage_type=EMAIL_STORAGE;
inmsg(&msg,t,&i,!forceit,"EMAIL",ALLOW_FULLSCREEN);
if (msg.stored_as==0xffffffff)
return;
if (anony & anony_sender)
i|=anony_receiver;
if (anony & anony_sender_da)
i|=anony_receiver_da;
if (anony & anony_sender_pp)
i|=anony_receiver_pp;
sendout_email(t, &msg, i, un, sy, an);
}
void imail(unsigned short u, unsigned short s)
{
char s1[81],s2[81];
int i;
userrec ur;
if (forwardm(&u,&s))
pl("Mail forwarded.");
i=1;
helpl=0;
if (s==0) {
read_user(u,&ur);
if ((ur.inact & inact_deleted)==0) {
sprintf(s1,"E-mail %s? ",nam(&ur,u));
prt(5,s1);
if (yn()==0)
i=0;
} else
i=0;
} else {
sprintf(s1,"1E-mail User3 %u @%u ? ",u,s);
prt(5,s1);
if (yn()==0)
i=0;
}
if (i)
email(u,s,0,0);
}
void iscan(int b)
{
int f;
char s[81];
if (usub[b].subnum==curlsub)
return;
curlsub=usub[b].subnum;
bchanged=0;
nummsgs=0;
if (curlsub<0)
return;
sprintf(s,"%s%s.SUB",syscfg.datadir,subboards[curlsub].filename);
f=open(s,O_BINARY | O_RDWR);
if (f==-1) {
f=open(s,O_BINARY | O_RDWR | O_CREAT,S_IREAD | S_IWRITE);
msgs[0].owneruser=0;
write(f,(void *) (&msgs[0]),sizeof(postrec));
}
lseek(f,0L,SEEK_SET);
nummsgs=(read(f,(void *) (&msgs[0]),255*sizeof(postrec)) / sizeof(postrec))-1;
nummsgs=msgs[0].owneruser;
if (nummsgs) {
sub_dates[curlsub]=msgs[nummsgs].qscan;
} else {
sub_dates[curlsub]=1;
}
close(f);
}
void iscan_hash(int b)
{
int f,nm;
char s[81];
postrec msg;
if ((b>=num_subs) || (sub_dates[b]))
return;
sprintf(s,"%s%s.SUB",syscfg.datadir,subboards[b].filename);
f=open(s,O_BINARY | O_RDWR);
if (f==-1) {
sub_dates[b]=1;
return;
}
lseek(f,0L,SEEK_SET);
read(f,&msg,sizeof(postrec));
nm=msg.owneruser;
if (nm>0) {
lseek(f,nm*sizeof(postrec),SEEK_SET);
read(f,&msg,sizeof(postrec));
sub_dates[b]=msg.qscan;
} else {
sub_dates[b]=1;
}
close(f);
}
void savebase()
{
int f;
char s[81];
if (bchanged==0)
return;
sprintf(s,"%s%s.SUB",syscfg.datadir,subboards[curlsub].filename);
f=open(s,O_BINARY | O_RDWR);
lseek(f,0L,SEEK_SET);
msgs[0].owneruser=nummsgs;
write(f,(void *) (&msgs[0]), ((nummsgs+1) * sizeof(postrec)));
close(f);
bchanged=0;
if (nummsgs) {
sub_dates[curlsub]=msgs[nummsgs].qscan;
} else {
sub_dates[curlsub]=1;
}
}
void plan(char *s, int *abort, int *next)
{
int i;
i=0;
checkhangup();
if (hangup)
*abort=1;
checka(abort,next);
while ((s[i]) && (!(*abort))) {
outchr(s[i++]);
checka(abort,next);
}
if (!(*abort))
nl();
}
#define buf_size 512
void read_message1(messagerec *m1, char an, int readit, int *next, char *fn)
{
char n[81],d[81],s[161],s1[81],s2[81],*sss,*ss,ch;
int f,abort,done,end,cur,p,p1,printit,ctrla,centre,i,i1,ansi,ctrld;
messagerec m;
char *buf;
long csec,len,l1,l2;
if ((buf=malloca(buf_size))==NULL)
return;
ss=NULL;
ansi=0;
m=*m1;
*next=0;
f=-1;
done=0;
cur=0;
end=0;
abort=0;
ctrld=0;
switch(m.storage_type) {
case 0:
case 1:
case 2:
ss=readfile(&m,fn,&len);
if (m.storage_type!=2) {
strcpy(s,syscfg.msgsdir);
ltoa(m.stored_as,s1,16);
if (m.storage_type==1) {
strcat(s,fn);
strcat(s,"\\");
}
strcat(s,s1);
strcpy(s2,"FN : ");
strcat(s2,s1);
if (so())
pl(s2);
else {
strcat(s2,"\r\n");
outs(s2);
}
}
if (ss==NULL) {
plan("File not found.",&abort,next);
nl();
farfree(buf);
return;
}
p=0;
while ((ss[p]!=13) && ((long)p<len) && (p<60))
n[p]=ss[p++];
n[p]=0;
++p;
p1=0;
if (ss[p]==10)
++p;
while ((ss[p+p1]!=13) && ((long)p+p1<len) && (p<60))
d[p1]=ss[(p1++)+p];
d[p1]=0;
cur=p+p1+1;
break;
case 255:
strcpy(s,fn);
f=open(s,O_RDONLY | O_BINARY);
if (f==-1) {
plan("File not found.",&abort,next);
nl();
farfree(buf);
return;
}
lseek(f,m.stored_as,SEEK_SET);
end=read(f,(void *)buf,buf_size);
break;
default:
/* illegal storage type */
nl();
pl("->ILLEGAL STORAGE TYPE<-");
nl();
farfree(buf);
return;
}
irt_name[0]=0;
if (m.storage_type!=255) switch(an) {
default:
case 0:
osan("7[1Name7]3: ",&abort,next);
ansic(MSG_COLOR);
plan(n,&abort,next);
strcpy(irt_name,n);
osan("7[1Date7]3: ",&abort,next);
ansic(MSG_COLOR);
plan(d,&abort,next);
if (origin_str[0]) {
osan("7[1From7]3:",&abort,next);
plan(origin_str,&abort,next);
}
break;
case anony_sender:
if (readit) {
osan("7[1Name7]3: ",&abort,next);
ansic(MSG_COLOR);
sprintf(s,"1<<< 3%s 1>>>",n);
plan(s,&abort,next);
osan("7[1Date7]3: ",&abort,next);
ansic(MSG_COLOR);
plan(d,&abort,next);
} else {
osan("7[1Name7]3: ",&abort,next);
ansic(MSG_COLOR);
plan("1>7UNKNOWN1<",&abort,next);
osan("7[1Date7]3: ",&abort,next);
ansic(MSG_COLOR);
plan("1>7UNKNOWN1<",&abort,next);
}
break;
case anony_sender_da:
case anony_sender_pp:
if (an==anony_sender_da) {
osan("7[1Name7]3: ",&abort,next);
ansic(MSG_COLOR);
plan("7Just a lost soul swimmin' in a fish bowl",&abort,next);
} else {
osan("7[1Name7]3: ",&abort,next);
ansic(MSG_COLOR);
plan("3Problemed Person",&abort,next);
}
if (readit) {
osan("7[1Name7]3: ",&abort,next);
ansic(MSG_COLOR);
plan(n,&abort,next);
osan("7[1Date7]3: ",&abort,next);
plan(d,&abort,next);
} else {
osan("7[1Date7]3: ",&abort,next);
ansic(MSG_COLOR);
plan("1>7UNKNOWN1<",&abort,next);
}
break;
}
nl();
p=0;
p1=0;
done=0;
printit=0;
ctrla=0;
centre=0;
l1=(long) cur;
while ((!done) && (!abort) && (!hangup)) {
switch(m.storage_type) {
case 0:
case 1:
case 2:
ch=ss[l1];
if (l1>=len)
ch=26;
break;
case 255:
if (cur>=end) {
cur=0;
end=read(f,(void *)buf,buf_size);
if (end==0)
buf[0]=26;
}
if ((buf[cur]=='`') && (m.stored_as))
buf[cur]=26;
ch=buf[cur];
break;
}
if (ch==26)
done=1;
else
if (ch!=10) {
if ((ch==13) || (!ch)) {
if (ch==13)
ctrld=0;
printit=1;
} else if (ch==1)
ctrla=1;
else if (ch==2)
centre=1;
else if (ch==4)
ctrld=1;
else if (ctrld==1) {
if ((ch>='0') && (ch<='9')) {
if (thisuser.optional_val<(ch-'0'))
ctrld=0;
else
ctrld=-1;
} else
ctrld=0;
} else {
if (ch==27) {
if ((topline) && (screenbottom==24) && (!ansi))
set_protect(0);
ansi=1;
lines_listed=0;
}
s[p++]=ch;
if ((ch==3) || (ch==8))
--p1;
else
++p1;
if ((ch==32) && (!centre))
printit=1;
}
if ((printit) || (ansi) || (p>=80)) {
printit=0;
if (centre && (ctrld!=-1)) {
i1=(thisuser.screenchars-wherex()-p1)/2;
for (i=0; (i<i1) && (!abort) && (!hangup); i++)
osan(" ",&abort,next);
}
if (p) {
if (ctrld!=-1) {
if ((wherex() + p1 >= thisuser.screenchars) && (!centre) && (!ansi))
nl();
s[p]=0;
osan(s,&abort,next);
if ((ctrla) && (s[p-1]!=32) && (!ansi))
outchr(32);
}
p1=0;
p=0;
}
centre=0;
}
checka(&abort,next);
if (ch==13)
if (ctrla==0) {
if (ctrld!=-1)
nl();
} else
ctrla=0;
} else
ctrld=0;
++cur;
++l1;
}
if ((!abort) && (p)) {
s[p]=0;
pl(s);
}
ansic(0);
nl();
if (f!=-1)
close(f);
if ((m.storage_type==255) && (abort))
*next=1;
if ((express) && (abort) && (!(*next)))
expressabort=1;
farfree(buf);
if (ss!=NULL)
farfree(ss);
if ((ansi) && (topdata) && (useron))
topscreen();
}
int printfile(char *fn)
{
char s[81],s1[81];
messagerec m;
int next;
m.stored_as=0L;
m.storage_type=255;
strcpy(s,syscfg.gfilesdir);
strcat(s,fn);
if (strchr(s,'.')==NULL) {
if (thisuser.sysstatus & sysstatus_ansi) {
if (thisuser.sysstatus & sysstatus_color) {
strcpy(s1,s);
strcat(s1,".ANS");
if (exist(s1))
strcat(s,".ANS");
}
if (strchr(s,'.')==NULL) {
strcpy(s1,s);
strcat(s1,".B&W");
if (exist(s1))
strcat(s,".B&W");
else
strcat(s,".MSG");
}
} else
strcat(s,".MSG");
}
next=0;
read_message1(&m,0,0,&next,s);
return(next);
}
void read_message(int n, int *next, int *val)
{
char s[100],s1[80];
postrec p;
int abort,a;
slrec ss;
nl();
abort=0;
*next=0;
sprintf(s,"7[1%u/%u7]3:7 ",n,nummsgs);
osan(s,&abort,next);
ansic(MSG_COLOR);
p=msgs[n];
if (p.status & (status_unvalidated | status_delete)) {
plan("1<<<7 NOT VALIDATED YET1 >>>",&abort,next);
if (!lcs())
return;
*val |= 1;
osan(s,&abort,next);
ansic(MSG_COLOR);
}
strcpy(irt,p.title);
irt_name[0]=0;
plan(p.title,&abort,next);
if ((p.status & status_no_delete) && (lcs())) {
plan("||||> Permanent Message",&abort,next);
}
if (p.status & status_pending_net) {
plan("1---->7 Not Network Validated",&abort,next);
*val |= 2;
}
if (!abort) {
ss=syscfg.sl[actsl];
if ((lcs()) || (ss.ability & ability_read_post_anony))
a=1;
else
a=0;
setorigin(p.ownersys, p.owneruser);
read_message1(&(p.msg),(p.anony & 0x0f),a,next,(subboards[curlsub].filename));
++thisuser.msgread;
++msgreadlogon;
} else
if ((express) && (!(*next)))
expressabort=1;
if (p.qscan>QSCN(curlsub))
QSCN(curlsub)=p.qscan;
}
void lineadd(messagerec *m1, char *sx, char *aux)
{
messagerec m;
char s1[81],s[81],s2[81],*b;
int f,i,j,new;
strcpy(s2,sx);
strcat(s2,"\r\n\0x1a");
m=*m1;
strcpy(s,syscfg.msgsdir);
switch(m.storage_type) {
case 0:
case 1:
ltoa(m.stored_as,s1,16);
if (m.storage_type==1) {
strcat(s,aux);
strcat(s,"\\");
}
strcat(s,s1);
f=open(s,O_RDWR | O_BINARY);
if (f>0) {
lseek(f,-1L,SEEK_END);
write(f,(void *)s2,strlen(s2));
close(f);
}
break;
case 2:
strcpy(s,sx);
strcat(s,"\x1a");
f=open_file(aux);
new=1;
while ((new<2048) && (gat[new]!=0))
++new;
i=(int)m.stored_as;
while (gat[i]!=-1)
i=gat[i];
if ((b=malloca(2048))==NULL)
return;
lseek(f,4096L+((long)i)*512L,SEEK_SET);
read(f,(void *)b,512);
j=0;
while ((j<512) && (b[j]!=26))
++j;
strcpy(&(b[j]),s);
lseek(f,4096L+((long)i)*512L,SEEK_SET);
write(f,(void *)b,512);
if ((j+strlen(s))>512) {
strcpy(b,&(s[512-j]));
lseek(f,4096L+((long)new)*512L,SEEK_SET);
write(f,(void *)b,512);
gat[new]=-1;
gat[i]=new;
lseek(f,0L,SEEK_SET);
write(f,(void *)gat,4096);
}
farfree((void *)b);
close(f);
break;
default:
/* illegal storage type */
break;
}
}
void delete(int mn)
{
postrec p1;
int i;
iscan(cursub);
if ((mn>0) && (mn<=nummsgs)) {
p1=msgs[mn];
remove_link(&p1.msg,(subboards[curlsub].filename));
for (i=mn; i<nummsgs; i++)
msgs[i]=msgs[i+1];
nummsgs--;
bchanged=1;
}
}