home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
WWIV2.ZIP
/
MSGBASE.C
< prev
next >
Wrap
Text File
|
1995-12-11
|
41KB
|
1,858 lines
#include "vars.h"
#pragma hdrstop
#include <mem.h>
#include "subxtr.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_BINARY);
if (f<1)
return;
ss=malloca(filelength(f));
i=read(f,ss,filelength(f));
ss[i]=0;
close(f);
ss1=strtok(ss,"\r\n");
while (ss1 && (!done)) {
i=atoi(ss1);
if (i) {
if (i==areacode)
done=1;
} else
strcpy(description,ss1);
ss1=strtok(NULL,"\r\n");
}
farfree(ss);
}
/****************************************************************************/
static char origin_str[128];
void setorigin(int sysnum, int usernum)
{
int i;
char s[81],s1[81],ch;
net_system_list_rec *csne;
if (net_num_max>1)
sprintf(s1,"1%s 7- 1",net_networks[net_num].name);
else
s1[0]=0;
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,"1%c%s%s 7(1%s7) [1%s7]",ch,s1,csne->name,s, csne->phone);
else
sprintf(origin_str,"1%c%s%s 7[1%s7]",ch,s1,csne->name,csne->phone);
} else {
strcpy(origin_str," ");
strcat(origin_str,s1);
strcat(origin_str,"1Unknown System");
}
}
}
int okfsed(void)
{
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);
set_gat_section(f,m.stored_as/2048);
csec=m.stored_as % 2048;
while ((csec>0) && (csec<2048)) {
nsec=(long) gat[csec];
gat[csec]=0;
csec=nsec;
}
save_gat(f);
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));
gat_section=0;
}
if (strcmp(gatfn,fn)) {
lseek(f,0L,SEEK_SET);
read(f,(void *)gat,4096);
strcpy(gatfn,fn);
gat_section=0;
}
return(f);
}
#define GATSECLEN (4096L+2048L*512L)
#define MSG_STARTING (((long)gat_section)*GATSECLEN + 4096)
void set_gat_section(int f, int section)
{
long l,l1;
int i;
if (gat_section!=section) {
l=filelength(f);
l1=((long)section)*GATSECLEN;
if (l<l1) {
chsize(f,l1);
l=l1;
}
lseek(f,l1,SEEK_SET);
if (l<(l1+4096)) {
for (i=0; i<2048; i++)
gat[i]=0;
write(f,(void *)gat, 4096);
} else {
read(f,(void *)gat, 4096);
}
gat_section=section;
}
}
void save_gat(int f)
{
long l;
l=((long)gat_section)*GATSECLEN;
lseek(f,l,SEEK_SET);
write(f,(void *)gat,4096);
}
void savefile(char *b, long l1, messagerec *m1, char *aux)
{
int f,gatp,i5,i4,gati[128],section;
messagerec m;
char s[81],s1[81];
long l2;
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);
for (section=0; section<100; section++) {
set_gat_section(f,section);
gatp=0;
i5=(int) ((l1 + 511L)/512L);
i4=1;
while ((gatp<i5) && (i4<2048)) {
if (gat[i4]==0)
gati[gatp++]=i4;
++i4;
}
if (gatp>=i5) {
l2=MSG_STARTING;
gati[gatp]=-1;
for (i4=0; i4<i5; i4++) {
lseek(f,l2 + 512L * (long)(gati[i4]),SEEK_SET);
write(f,(void *)(&b[i4*512]),512);
gat[gati[i4]]=gati[i4+1];
}
save_gat(f);
break;
}
}
close(f);
m.stored_as=(long) gati[0] + gat_section*2048;
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:
npr(get_stringx(1,36),m.storage_type);
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);
set_gat_section(f,m.stored_as/2048);
csec=m.stored_as % 2048;
l1=0;
while ((csec>0) && (csec<2048)) {
l1+=512L;
csec=gat[csec];
}
if (!l1) {
nl();
pl(get_string(623));
nl();
close(f);
return(NULL);
}
if ((b=malloca(l1))==NULL) {
close(f);
return(NULL);
}
csec=m.stored_as % 2048;
l1=0;
l2=MSG_STARTING;
while ((csec>0) && (csec<2048)) {
lseek(f,l2 + 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) {
close(f);
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(get_string(89));
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("1File loaded into workspace.");
nl();
if (!use_workspace)
pl("1Editing will be allowed.");
}
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 *dest, int flags)
{
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;
messagerec m;
long ll,l1;
char *lin, *b;
int real_name=0;
FILE *result;
struct {char tlen, ttl[81], anon; } fedit_data;
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(1,"7[1Title7]5: ");
mpl(60);
inputl(title,60);
} else {
pl(get_string(626));
outstr(get_string(326));
inputl(title,60);
}
if ((title[0]==0) && (needtitle)) {
pl("6Aborted.");
m.stored_as=0xffffffff;
*m1=m;
if (!fsed)
farfree((void *)lin);
return;
}
if (!fsed) {
outstr(get_string(627));
pln(maxli);
pl(get_string(628));
strcpy(s,get_string(629));
s[thisuser.screenchars]=0;
pl(s);
while (!done && !hangup) {
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,get_string(630));
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(get_string(631));
}
if ((stricmp(s,"/ES")==0) || (stricmp(s,"/S")==0)) {
save=1;
done=1;
savel=0;
}
if ((stricmp(s,"/ESY")==0) || (stricmp(s,"/SY")==0)) {
save=1;
done=1;
savel=0;
setanon=1;
}
if ((stricmp(s,"/ESN")==0) || (stricmp(s,"/SN")==0)) {
save=1;
done=1;
savel=0;
setanon=-1;
}
if (stricmp(s,"/ABT")==0) {
done=1;
savel=0;
}
if (stricmp(s,"/CLR")==0) {
savel=0;
curli=0;
pl(get_string(632));
nl();
}
if (stricmp(s,"/RL")==0) {
savel=0;
if (curli) {
--curli;
pl(get_string(633));
} else {
pl(get_string(634));
}
}
if (stricmp(s,"/TI")==0) {
savel=0;
helpl=26;
if (okansi()) {
prt(2,"7[1Title7]5: ");
mpl(60);
inputl(title,60);
} else {
pl(get_string(626));
outstr(get_string(326));
inputl(title,60);
}
pl(get_string(631));
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(get_string(635));
pl(&(lin[(curli-1)*LEN]));
pl("1Continue5...");
}
savel=0;
}
}
if (savel) {
strcpy(&(lin[(curli++)*LEN]),s);
if (curli==(maxli+1)) {
nl();
pl(get_string(636));
pl("5/1ES to save");
nl();
--curli;
} else if (curli==maxli) {
pl(get_string(637));
} else if ((curli+5)==maxli) {
pl(get_string(638));
}
}
}
if (curli==0)
save=0;
} else {
if (fsed==1) {
fedit_data.tlen=60;
strcpy(fedit_data.ttl,title);
fedit_data.anon=0;
result=fopen("fedit.inf","wb");
if (result) {
fwrite(&fedit_data, sizeof(fedit_data), 1, result);
fclose(result);
}
save=external_edit("INPUT.MSG",syscfg.tempdir,(int) (thisuser.defed)-1,
maxli, dest, title, flags);
if (save) {
if ((result=fopen("result.ed","rt"))!=NULL) {
if (fgets(s,80,result)) {
ss=strchr(s,'\n');
if (ss) *ss=0;
setanon=atoi(s);
if (fgets(title,80,result)) {
ss=strchr(title,'\n');
if (ss) *ss=0;
fclose(result);
}
}
} else if ((result=fopen("fedit.inf","rb"))!=NULL) {
if (fread(&fedit_data, sizeof(fedit_data), 1, result)==1) {
strcpy(title,fedit_data.ttl);
setanon=fedit_data.anon;
}
fclose(result);
}
}
unlink("result.ed");
unlink("fedit.inf");
} else {
save=exist(fnx);
if (save) {
pl("1Reading in file5...");
}
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,"7Anonymous1? ");
if (yn())
*anony=anony_sender;
else
*anony=0;
}
break;
case anony_enable_dear_abby:
nl();
npr("1. %s\r\n",nam(&thisuser,usernum));
pl(get_string(640));
pl(get_string(641));
nl();
prt(5,"7Which1? ");
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("1Saving5...");
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(get_string(642));
m1->stored_as=0xffffffff;
return;
}
l1=0;
if (real_name)
addline(b,thisuser.realname,&l1);
else
addline(b,nam1(&thisuser,usernum,net_sysnum),&l1);
time(&ll);
strcpy(s,ctime(&ll));
s[strlen(s)-1]=0;
addline(b,s,&l1);
if (irt[0]) {
sprintf(s,"7[1RE7]5:1 %s",irt);
addline(b,s,&l1);
if (irt_name[0]) {
sprintf(s,"7[1BY7]5:1 %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);
}
prt(5,"\r\n1Do you want your Personal Tag displayed5? ");
if (ny())
{
addline(b," ",&l1);
sprintf(s,"7[1Personal Tag7]7:3 %s",thisuser.ptag);
addline(b,s,&l1);
}
if (thisuser.ass_pts>0)
{
sprintf(s,"\r\n7[1Comment7]5:1I have 6%d 1ass points5!",thisuser.ass_pts);
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,nn;
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)) {
nn=net_num;
set_net_num(ur.net_num);
if (!valid_system(ur.forwardsys)) {
set_net_num(nn);
return(0);
}
*u=ur.forwardusr;
*s=ur.forwardsys;
return(1);
} else {
*u=0;
*s=0;
return(0);
}
}
cu=ur.forwardusr;
if (cu==-1) {
pl(get_string(643));
if (so()) {
pl(get_string(644));
} else {
*u=0;
*s=0;
}
return(0);
}
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 (!valid_system(ur.forwardsys))
return(0);
*u=ur.forwardusr;
*s=ur.forwardsys;
farfree(ss);
set_net_num(ur.net_num);
return(1);
}
if (ss[cu]) {
farfree(ss);
return(0);
}
ss[cu]=1;
if (ur.forwardusr==65535) {
pl(get_string(643));
if (so()) {
pl(get_string(644));
*u=cu;
*s=0;
} else {
*u=0;
*s=0;
}
farfree(ss);
return(0);
}
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, unsigned uf, unsigned sf, int fwd, int fnn)
{
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;
if (sf == net_sysnum)
m.fromsys=0;
else
m.fromsys=sf;
m.fromuser=uf;
m.tosys=sy;
m.touser=un;
m.status=0;
time((long *)&(m.daten));
if (m.fromsys && (net_num_max>1)) {
m.status|=status_new_net;
m.title[79]=0;
m.title[80]=fnn;
}
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;
if (sf)
nh.fromsys=sf;
else
nh.fromsys=net_sysnum;
nh.fromuser=uf;
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) && (fnn==net_num)) {
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) {
outstr(get_string(645));
npr("%lu",nh.length-32760L);
outstr(get_string(646));
nh.length = 32760;
}
if (fnn!=net_num) {
gate_msg(&nh, b1,net_num, net_email_name, NULL, fnn);
} else {
if (fwd)
sprintf(s,"%sP1.NET",net_data);
else
sprintf(s,"%sP0.NET",net_data);
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,"1Mail 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 (net_num_max>1) {
if (un==0)
sprintf(s1,"%s %s @%u",net_name, net_email_name,sy);
else
sprintf(s1,"%s %u @%u",net_name, un,sy);
} else {
if (un==0)
sprintf(s1,"%s @%u",net_email_name,sy);
else
sprintf(s1,"%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;
}
}
save_status();
if (!wfc)
topscreen();
pl(s);
if (s2[0])
pl(s2);
}
int ok_to_mail(unsigned un, unsigned sy, int forceit)
{
userrec ur;
slrec ss;
ss=syscfg.sl[actsl];
if ((sy!=0) && (net_sysnum==0)) {
nl();
pl(get_string(648));
nl();
return(0);
}
if (sy==0) {
if (un==0)
return(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("1Mailbox full5.");
nl();
return(0);
}
}
if (ur.inact & inact_deleted) {
nl();
pl(get_string(341));
nl();
return(0);
}
} else {
if (!valid_system(sy)) {
nl();
pl("1Unknown system number5.");
nl();
return(0);
}
if (thisuser.restrict & restrict_net) {
nl();
pl(get_string(650));
return(0);
}
}
if (forceit==0) {
if ((((un==1) && (sy==0) && ((fsenttoday>=5) || (thisuser.fsenttoday1>=10))) ||
(((un!=1) || (sy!=0)) && (thisuser.etoday>=ss.emails))) && (!cs())) {
nl();
pl("1Too much mail sent today5.");
nl();
return(0);
}
if ((restrict_email & thisuser.restrict) && (un!=1)) {
nl();
pl(get_string(345));
nl();
return(0);
}
}
return(1);
}
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(get_string(332));
nl();
return;
}
nl();
ss=syscfg.sl[actsl];
if (forwardm(&un,&sy)) {
nl();
pl("1Mail forwarded5.");
nl();
if ((un==0) && (sy==0)) {
pl(get_string(652));
return;
}
}
if (!un && !sy)
return;
if (!ok_to_mail(un, sy, forceit))
return;
if (sy)
csne=next_system(sy);
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) {
set_net_num(0);
if (an) {
read_user(un,&ur);
strcpy(s2,nam(&ur,un));
} else
strcpy(s2,"1>7UNKNOWN1<");
} else {
if (net_num_max>1) {
if (un==0)
sprintf(s2,"%s %s @%u",net_name, net_email_name,sy);
else
sprintf(s2,"%s %u @%u",net_name, un,sy);
} else {
if (un==0)
sprintf(s2,"%s @%u",net_email_name,sy);
else
sprintf(s2,"%u @%u",un,sy);
}
}
outstr("1E7-1mailing ");
pl(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();
outstr("1Name of system5: ");
pl(csne -> name);
outstr("1Number of hops5: ");
pln(csne->numhops);
nl();
}
msg.storage_type=EMAIL_STORAGE;
inmsg(&msg,t,&i,!forceit,"EMAIL",ALLOW_FULLSCREEN, s2, 0);
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, usernum, net_sysnum, 0, net_num);
}
void imail(unsigned short u, unsigned short s)
{
char s1[81],s2[81];
int i;
userrec ur;
if (forwardm(&u,&s))
pl("1Mail forwarded5.");
if (!u && !s)
return;
i=1;
helpl=0;
if (s==0) {
read_user(u,&ur);
if ((ur.inact & inact_deleted)==0) {
sprintf(s1,"1%s %s5? ",get_string(657), nam(&ur,u));
prt(5,s1);
if (yn()==0)
i=0;
} else
i=0;
} else {
sprintf(s1,"1%s %s %u 7@1%u 7? ",get_string(657), get_string(658), u,s);
prt(5,s1);
if (yn()==0)
i=0;
}
grab_quotes(NULL, NULL);
if (i)
email(u,s,0,0);
}
void iscan(int b)
{
int f;
char s[81];
if (xsubs[usub[b].subnum].num_nets)
set_net_num(xsubs[usub[b].subnum].nets[0].net_num);
else
set_net_num(0);
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(void)
{
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,get_string(659));
strcat(s2,s1);
if (so())
pl(s2);
else {
strcat(s2,"\r\n");
outs(s2);
}
}
if (ss==NULL) {
plan(get_string(89),&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(get_string(89),&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(get_string(660));
nl();
farfree(buf);
return;
}
irt_name[0]=0;
if (m.storage_type!=255) switch(an) {
default:
case 0:
sprintf(s,"3│7[1Name7]5: "); /*here*/
osan(s,&abort,next);
ansic(1);
plan(n,&abort,next);
strcpy(irt_name,n);
sprintf(s,"3│7[1Date7]5: ");
osan(s,&abort,next);
ansic(1);
plan(d,&abort,next);
if (origin_str[0]) {
sprintf(s,"3│7[1From7]5:");
osan(s,&abort,next);
plan(origin_str,&abort,next);
}
npr("3└──────────────────────────────────────────∙∙∙ ∙ ∙ ∙ ∙ ∙\r\n");
break;
case anony_sender:
if (readit) {
sprintf(s,"3│7[1Name7]5: ");
osan(s,&abort,next);
ansic(MSG_COLOR);
sprintf(s,"7<<< 6%s 7>>>",n);
plan(s,&abort,next);
sprintf(s,"3│7[1Date7]5: ");
osan(s,&abort,next);
ansic(MSG_COLOR);
plan(d,&abort,next);
npr("3└──────────────────────────────────────────∙∙∙ ∙ ∙ ∙ ∙ ∙\r\n");
} else {
sprintf(s,"3│7[1Name7]5: ");
osan(s,&abort,next);
ansic(MSG_COLOR);
sprintf(s,"7>1UNKNOWN7<");
plan(s,&abort,next);
sprintf(s,"3│7[1Date7]5: ");
osan(s,&abort,next);
ansic(MSG_COLOR);
sprintf(s,"7>1UNKNOWN7<");
plan(s,&abort,next);
npr("3└──────────────────────────────────────────∙∙∙ ∙ ∙ ∙ ∙ ∙\r\n");
}
break;
case anony_sender_da:
case anony_sender_pp:
if (an==anony_sender_da) {
sprintf(s,"3│7[1Name7]5: ");
osan(s,&abort,next);
ansic(MSG_COLOR);
plan(get_string(663),&abort,next);
npr("3└──────────────────────────────────────────∙∙∙ ∙ ∙ ∙ ∙ ∙\r\n");
} else {
sprintf(s,"3│7[1Name7]5: ");
osan(s,&abort,next);
ansic(MSG_COLOR);
plan(get_string(664),&abort,next);
npr("3└──────────────────────────────────────────∙∙∙ ∙ ∙ ∙ ∙ ∙\r\n");
}
if (readit) {
sprintf(s,"3│7[1Name7]5: ");
osan(s,&abort,next);
ansic(MSG_COLOR);
plan(n,&abort,next);
sprintf(s,"3│7[1Date7]5: ");
osan(s,&abort,next);
plan(d,&abort,next);
npr("3└──────────────────────────────────────────∙∙∙ ∙ ∙ ∙ ∙ ∙\r\n");
} else {
sprintf(s,"3│7[1Date7]5: ");
osan(s,&abort,next);
ansic(MSG_COLOR);
sprintf(s,"7>1UNKNOWN7<");
plan(s,&abort,next);
npr("3└──────────────────────────────────────────∙∙∙ ∙ ∙ ∙ ∙ ∙\r\n");
}
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)) {
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)) {
if (wherex()<(thisuser.screenchars)-1)
outchr(32);
else
nl();
}
}
p1=0;
p=0;
}
centre=0;
}
checka(&abort,next);
if (ch==13) {
if (ctrla==0) {
if (ctrld!=-1)
nl();
} else
ctrla=0;
ctrld=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,i;
for (i=0; i<2; i++) {
if (i==0)
strcpy(s,languagedir);
else
strcpy(s,syscfg.gfilesdir);
m.stored_as=0L;
m.storage_type=255;
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");
}
if (exist(s))
break;
}
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,nn;
slrec ss;
nl();
abort=0;
*next=0;
outchr(12);
npr("3┌──────────────────────────────────────────∙∙∙ ∙ ∙ ∙ ∙ ∙\r\n");
sprintf(s,"3│7[1%u7/1%u7]5: ",n,nummsgs); /*here*/
osan(s,&abort,next);
ansic(1);
p=msgs[n];
if (p.status & (status_unvalidated | status_delete)) {
plan(get_string(665),&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())) {
sprintf(s,"3│7||||5>1Permanent Message");
plan(s,&abort,next);
}
if (p.status & status_pending_net) {
sprintf(s,"3│7----5>1Not Network Validated");
plan(s,&abort,next);
*val |= 2;
}
if (!abort) {
ss=syscfg.sl[actsl];
if ((lcs()) || (ss.ability & ability_read_post_anony))
a=1;
else
a=0;
nn=net_num;
if (p.status & status_post_new_net)
set_net_num(p.title[80]);
setorigin(p.ownersys, p.owneruser);
read_message1(&(p.msg),(p.anony & 0x0f),a,next,(subboards[curlsub].filename));
if (nn!=net_num)
set_net_num(nn);
++thisuser.msgread;
++msgreadlogon;
} else
if ((express) && (!(*next)))
expressabort=1;
if (p.qscan>qsc_p[curlsub])
qsc_p[curlsub]=p.qscan;
}
void lineadd(messagerec *m1, char *sx, char *aux)
{
messagerec m;
char s1[81],s[81],s2[181],*b;
int f,i,j,new;
strcpy(s2,sx);
strcat(s2,"\r\n\x1a");
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:
f=open_file(aux);
set_gat_section(f,m.stored_as/2048);
new=1;
while ((new<2048) && (gat[new]!=0))
++new;
i=(int)(m.stored_as % 2048);
while (gat[i]!=65535)
i=gat[i];
if ((b=malloca(2048))==NULL) {
close(f);
return;
}
lseek(f,MSG_STARTING + ((long)i)*512L,SEEK_SET);
read(f,(void *)b,512);
j=0;
while ((j<512) && (b[j]!=26))
++j;
strcpy(&(b[j]),s2);
lseek(f,MSG_STARTING + ((long)i)*512L,SEEK_SET);
write(f,(void *)b,512);
if (((j+strlen(s2))>512) && (new!=2048)) {
lseek(f,MSG_STARTING + ((long)new)*512L,SEEK_SET);
write(f,(char *)b+512,512);
gat[new]=65535;
gat[i]=new;
save_gat(f);
}
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;
}
}