home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
MSGBASE1.C
< prev
next >
Wrap
Text File
|
1992-06-15
|
37KB
|
1,467 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 <dir.h>
#define ALLOW_FULLSCREEN 1
#define EMAIL_STORAGE 2
int deleted_flag;
/****************************************************************************/
void send_net_post(postrec *p, unsigned int type, char *extra)
{
net_header_rec nh;
char *b, *b1;
long len1, len2;
char s[81];
int f,i;
unsigned int *list;
b=readfile(&(p -> msg),extra,&len1);
if (b==NULL)
return;
nh.tosys=0;
nh.touser=0;
if (p -> ownersys)
nh.fromsys=p -> ownersys;
else
nh.fromsys =syscfg.systemnumber;
nh.fromuser=p -> owneruser;
nh.main_type=main_type_post;
nh.minor_type=type;
nh.list_len=0;
nh.daten=p -> daten;
nh.length=len1+1+strlen(p -> title);
if (nh.length > 32760) {
nh.length = 32760;
npr("Message truncated by %lu bytes for the network.\r\n",nh.length-32760L);
}
nh.method=0;
if ((b1=malloca(nh.length+100))==NULL) {
farfree(b);
return;
}
strcpy(b1,p -> title);
memmove(&(b1[strlen(p -> title)+1]),b,(unsigned int) len1);
farfree(b);
if ((list=malloca(2*(num_sys_list+2)))==NULL) {
farfree(b1);
return;
}
sprintf(s,"%sN%u.NET",syscfg.datadir,type);
f=open(s,O_RDONLY | O_BINARY);
if (f>0) {
len1=filelength(f);
if ((b=malloca(len1+100L))==NULL) {
farfree(list);
farfree(b1);
return;
}
lseek(f,0L,SEEK_SET);
read(f,(void *)b,len1);
b[len1]=0;
close(f);
len2=0;
while (len2<len1) {
while ((len2<len1) && ((b[len2]<'0') || (b[len2]>'9')))
++len2;
if ((b[len2]>='0') && (b[len2]<='9') && (len2<len1)) {
i=atoi(&(b[len2]));
if ((i!=syscfg.systemnumber) && (i != p -> ownersys))
list[nh.list_len++]=i;
while ((len2<len1) && (b[len2]>='0') && (b[len2]<='9'))
++len2;
}
}
farfree(b);
}
if (nh.list_len) {
strcpy(s,syscfg.datadir);
strcat(s,"P1.NET");
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 *)list,2*nh.list_len);
write(f,(void *)b1,nh.length);
close(f);
}
sprintf(s,"%sNN%u.NET",syscfg.datadir,subboards[curlsub].type);
f=open(s,O_RDONLY | O_BINARY);
nh.list_len=0;
nh.main_type=main_type_pre_post;
if (f>0) {
len1=filelength(f);
if ((b=malloca(len1+100L))==NULL) {
farfree(b1);
farfree(list);
return;
}
lseek(f,0L,SEEK_SET);
read(f,(void *)b,len1);
b[len1]=0;
close(f);
len2=0;
while (len2<len1) {
while ((len2<len1) && ((b[len2]<'0') || (b[len2]>'9')))
++len2;
if ((b[len2]>='0') && (b[len2]<='9') && (len2<len1)) {
i=atoi(&(b[len2]));
if ((i!=syscfg.systemnumber) && (i != p -> ownersys))
list[nh.list_len++]=i;
while ((len2<len1) && (b[len2]>='0') && (b[len2]<='9'))
++len2;
}
}
farfree(b);
}
if (nh.list_len) {
strcpy(s,syscfg.datadir);
strcat(s,"P1.NET");
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 *)list,2*nh.list_len);
write(f,(void *)b1,nh.length);
close(f);
}
farfree(list);
farfree(b1);
}
/****************************************************************************/
void post()
{
messagerec m;
postrec p;
char s[121],*b,*b1;
int i,dm,a,f;
slrec ss;
long len1,len2;
unsigned int *list;
iscan(cursub);
if (curlsub<0) {
nl();
pl("6No subs available.");
nl();
return;
}
ss=syscfg.sl[actsl];
if (freek1(syscfg.msgsdir)<10.0) {
nl();
pl("Sorry, not enough disk space left.");
nl();
return;
}
if ((restrict_post & thisuser.restrict) || (thisuser.posttoday>=ss.posts)) {
nl();
pl("7Too many messages posted today.");
nl();
return;
}
if (actsl<subboards[curlsub].postsl) {
nl();
pl("3You can't post here.");
nl();
return;
}
m.storage_type=subboards[curlsub].storage_type;
a=subboards[curlsub].anony & 0x0f;
if ((a==0) && (ss.ability & ability_post_anony))
a=anony_enable_anony;
if ((a==anony_enable_anony) && (thisuser.restrict & restrict_anony))
a=0;
if (subboards[curlsub].type) {
a &= (anony_real_name);
if (thisuser.restrict & restrict_net) {
nl();
pl("1You can't post on networked sub-boards.");
nl();
return;
}
if (thisuser.restrict & (restrict_validate | restrict_auto_msg_delete)) {
nl();
pl("1You can't post on networked sub-boards.");
nl();
return;
}
if (syscfg.systemnumber) {
nl();
pl("1Careful! This message base is Networked!.");
nl();
}
}
inmsg(&m,p.title,&a,1,(subboards[curlsub].filename),ALLOW_FULLSCREEN);
if (m.stored_as!=0xffffffff) {
p.anony=a;
p.msg=m;
p.ownersys=0;
p.owneruser=usernum;
p.qscan=status.qscanptr++;
time((long *)(&p.daten));
if (thisuser.restrict & restrict_auto_msg_delete)
p.status=status_delete;
else
if (thisuser.restrict & restrict_validate)
p.status=status_unvalidated;
else
p.status=0;
if ((subboards[curlsub].type) && (syscfg.systemnumber) &&
(subboards[curlsub].anony & anony_val_net) && (!lcs())) {
p.status |= status_pending_net;
dm=1;
for (i=1; i<=nummsgs; i++)
if (msgs[i].status & status_pending_net)
dm=0;
if (dm) {
sprintf(s,"1Unvalidated net posts on 3%s.",subboards[curlsub].name);
ssm(1,0,s);
}
}
if (nummsgs>=subboards[curlsub].maxmsgs) {
i=1;
dm=0;
while ((dm==0) && (i<=nummsgs)) {
if ((msgs[i].status & status_no_delete)==0)
dm=i;
++i;
}
if (dm==0)
dm=1;
delete(dm);
deleted_flag=dm;
}
msgs[++nummsgs]=p;
sub_dates[curlsub]=p.qscan;
bchanged=1;
savebase();
++thisuser.msgpost;
++thisuser.posttoday;
++status.msgposttoday;
save_status();
topscreen();
sprintf(s,"+%s posted on %s",p.title,subboards[curlsub].name);
sysoplog(s);
sprintf(s,"1Posted on 5%s",subboards[curlsub].name);
save_status();
pl(s);
npr("3Post5/3Call Ratio is now 5: 1%-5.3f",post_ratio(),syscfg.post_call_ratio);
nl();
if ((subboards[curlsub].type) && (syscfg.systemnumber)) {
++thisuser.postnet;
if (((subboards[curlsub].anony & anony_val_net)==0) || (lcs()))
send_net_post(&p, subboards[curlsub].type, subboards[curlsub].filename);
}
}
}
void extract_out(char *b, long len, char *title)
{
char s1[81],s2[81],ch=26,ch1;
int i;
do {
prt(2,"1Save under what filename? ");
input(s1,12);
if (s1[0]) {
sprintf(s2,"%s%s",syscfg.gfilesdir,s1);
if (exist(s2)) {
nl();
pl("Filename already in use.");
nl();
prt(2,"O)verwrite, A)ppend, N)ew name, Q)uit? ");
ch1=onek("QOAN");
switch(ch1) {
case 'Q':
s2[0]=0;
s1[0]=0;
break;
case 'N':
s1[0]=0;
break;
case 'A':
break;
case 'O':
unlink(s2);
break;
}
nl();
}
} else
s2[0]=0;
} while ((!hangup) && (s2[0]!=0) && (s1[0]==0));
if ((s1[0]) && (!hangup)) {
i=open(s2,O_RDWR | O_BINARY | O_CREAT , S_IREAD | S_IWRITE);
if (filelength(i)) {
lseek(i, -1L, SEEK_END);
read(i, ((void *)&ch1), 1);
if (ch1 == 26)
lseek(i, -1L, SEEK_END);
}
write(i,title,strlen(title));
write(i,"\r\n",2);
write(i,(void *)b,len);
write(i,&ch,1);
close(i);
npr("Message written to: %s.\r\n",s2);
}
farfree(b);
}
void grab_user_name(messagerec *m, char *fn)
{
char *ss,*ss1;
long len;
ss=readfile(m,fn,&len);
if (ss) {
ss1=strchr(ss,'\r');
if (ss1) {
*ss1=0;
strcpy(net_email_name,ss);
} else
net_email_name[0]=0;
farfree(ss);
} else
net_email_name[0]=0;
}
void scan(int msgnum, int optype, int *nextsub)
{
char s[81],s1[81],s2[81],*b,*ss1;
int i,i1,i2,done,quit,abort,next,val,realexpress;
slrec ss;
userrec u;
unsigned short usr;
long l,len;
postrec p,p1;
irt[0]=0;
irt_name[0]=0;
done=0;
quit=0;
val=0;
realexpress=express;
iscan(cursub);
if (curlsub<0) {
nl();
pl("7No subs available.");
nl();
return;
}
do {
tleft(1);
switch(optype) {
case 0: /* Read Prompt */
npr("7[1Sub7]3:5 %s",subboards[curlsub].name);
sprintf(s,"7[1Read7]3:1(1-%u,^%u),? :",nummsgs,msgnum);
nl();
if (express) {
s[0]=0;
nl();
nl();
} else {
prt(2,s);
helpl=16;
input(s,3);
while (s[0]==32) {
strcpy(s1,&(s[1]));
strcpy(s,s1);
}
}
optype=0;
i=atoi(s);
if (s[0]==0) {
i=msgnum+1;
if (i>=nummsgs+1)
done=1;
}
if ((i!=0) && (i<=nummsgs) && (i>=1)) {
optype=2;
msgnum=i;
} else
if (s[1]==0) {
switch(s[0]) {
case 'Q':
quit=1;
done=1;
*nextsub=0;
break;
case 'B':
if (*nextsub!=0) {
*nextsub=1;
done=1;
quit=1;
}
break;
case 'T':
optype=1;
break;
case 'R':
optype=2;
break;
case 'A':
if ((msgs[msgnum].ownersys) && (!msgs[msgnum].owneruser))
grab_user_name(&(msgs[msgnum].msg),subboards[curlsub].filename);
ss=syscfg.sl[actsl];
if ((lcs()) || (ss.ability & ability_read_post_anony) || (msgs[msgnum].anony==0))
email(msgs[msgnum].owneruser,msgs[msgnum].ownersys,0,0);
else
email(msgs[msgnum].owneruser,msgs[msgnum].ownersys,0,msgs[msgnum].anony);
break;
case 'P':
irt[0]=0;
irt_name[0]=0;
case 'W':
deleted_flag=0;
post();
if (deleted_flag && (deleted_flag<=msgnum))
--msgnum;
break;
case '?':
if (lcs())
printmenu(13);
else
printmenu(1);
break;
case '-':
if ((msgnum>1) && (msgnum-1<nummsgs)) {
--msgnum;
optype=2;
}
break;
case 'C':
express=1;
break;
/*************/
case 'V':
if ((cs()) && (msgs[msgnum].ownersys==0) && (msgnum>0) && (msgnum<=nummsgs))
valuser(msgs[msgnum].owneruser);
else
if ((cs()) && (msgnum>0) && (msgnum<=nummsgs)) {
nl();
pl("Post from another system.");
nl();
}
break;
case 'N':
if ((lcs()) && (msgnum>0) && (msgnum<=nummsgs)) {
msgs[msgnum].status ^= status_no_delete;
bchanged=1;
nl();
if (msgs[msgnum].status & status_no_delete)
pl("Message will NOT be auto-purged.");
else
pl("Message CAN now be auto-purged.");
nl();
}
break;
case 'X':
if ((lcs()) && (msgnum>0) && (msgnum<=nummsgs)) {
msgs[msgnum].status ^= status_pending_net;
bchanged=1;
nl();
if (msgs[msgnum].status & status_pending_net) {
val |= 2;
pl("Will be sent out on net now.");
} else
pl("Not set for net pending now.");
nl();
}
break;
case 'U':
if ((lcs()) && (msgnum>0) && (msgnum<=nummsgs)) {
msgs[msgnum].anony=0;
bchanged=1;
nl();
pl("Message is not anonymous now.");
}
break;
case 'D':
if (lcs()) {
if (msgnum) {
delete(msgnum);
if (msgnum>1)
msgnum--;
savebase();
}
}
break;
case 'E':
if (so()) {
if ((msgnum>0) && (msgnum<=nummsgs)) {
b=readfile(&(msgs[msgnum].msg),(subboards[curlsub].filename),&len);
extract_out(b,len, msgs[msgnum].title);
}
}
break;
case 'M':
if ((cs()) && (msgnum>0) && (msgnum<=nummsgs)) {
nl();
do {
prt(1,"Move to which sub? ");
ss1=mmkey(0);
if (ss1[0]=='?')
sublist();
} while ((!hangup) && (ss1[0]=='?'));
i=-1;
if (ss1[0]==0)
break;
for (i1=0; i1<MAX_SUBS; i1++)
if (strcmp(usub[i1].keys,ss1)==0)
i=i1;
if (i!=-1) {
p=msgs[msgnum];
b=readfile(&(p.msg),(subboards[curlsub].filename),&len);
delete(msgnum);
savebase();
iscan(i);
p.msg.storage_type=subboards[curlsub].storage_type;
savefile(b,len,&(p.msg),(subboards[curlsub].filename));
p.qscan=status.qscanptr++;
if (nummsgs>=subboards[curlsub].maxmsgs) {
i1=1;
i2=0;
while ((i2==0) && (i1<=nummsgs)) {
if ((msgs[i1].status & status_no_delete)==0)
i2=i1;
++i1;
}
if (i2==0)
i2=1;
p1=msgs[i2];
remove_link(&p1.msg,(subboards[curlsub].filename));
for (i1=i2; i1<nummsgs; i1++)
msgs[i1]=msgs[i1+1];
--nummsgs;
}
msgs[++nummsgs]=p;
bchanged=1;
savebase();
save_status();
iscan(cursub);
nl();
pl("1Message moved.");
nl();
}
}
break;
/*************/
}
} else {
if (strcmp(s,"CLS")==0)
outchr('\x0c');
}
break;
case 1: /* List Titles */
i=0;
abort=0;
if (msgnum>=nummsgs)
abort=1;
ansic(0);
ss=syscfg.sl[thisuser.sl];
while ((!abort) && (!hangup) && (++i<=10)) {
++msgnum;
if (msgs[msgnum].qscan>thisuser.qscnptr[curlsub])
strcpy(s,"6*2 ");
else
strcpy(s,"8-2 ");
if (msgnum<100)
strcat(s," ");
if (msgnum<10)
strcat(s," ");
itoa(msgnum,s2,10);
usr=msgs[msgnum].owneruser;
if ((msgs[msgnum].ownersys==0) && (usr==usernum))
sprintf(s1,"%s[1%s2] ",s,s2);
else
sprintf(s1,"%s(1%s2) ",s,s2);
outstr(s1);
if ((msgs[msgnum].anony & anony_sender) && ((ss.ability & ability_read_post_anony)==0))
sprintf(s,"7>UNKNOWN<");
else
if (msgs[msgnum].ownersys==0) {
read_user(usr,&u);
sprintf(s,"f%s",nam(&u,usr));
} else
sprintf(s,"User %u @%u",usr,msgs[msgnum].ownersys);
outstr(s);
i1=41-strlen(s)-strlen(s1);
for (i2=1; i2<i1; i2++)
outstr(" ");
sprintf(s,"\3%c\"%s\3%c\"",'0',msgs[msgnum].title,'0');
if (strlen(s)>42) {
if (s[39]==3)
s[39]=32;
s[40]=3;
s[41]=48;
s[42]=34;
s[43]=0;
}
pla(s,&abort);
if (msgnum>=nummsgs)
abort=1;
}
optype=0;
break;
case 2: /* Read Message */
if ((msgnum>0) && (msgnum<=nummsgs))
read_message(msgnum,&next,&val);
ansic(0);
nl();
if (next) {
++msgnum;
if (msgnum>nummsgs)
done=1;
optype=2;
} else
optype=0;
if (expressabort)
if (realexpress) {
done=1;
quit=1;
*nextsub=0;
} else {
expressabort=0;
express=0;
optype=0;
}
break;
}
} while ((!done) && (!hangup));
if (!realexpress) {
express=0;
expressabort=0;
}
if ((val & 1) && (lcs()) && (!express)) {
nl();
prt(1,"Validate messages here? ");
if (yn()) {
for (i=1; i<=nummsgs; i++)
if (msgs[i].status & (status_unvalidated | status_delete))
msgs[i].status &= (~(status_unvalidated | status_delete));
bchanged=1;
}
}
if ((val & 2) && (lcs()) && (!express)) {
nl();
prt(1,"Network validate here? ");
if (yn()) {
i1=0;
for (i=1; i<=nummsgs; i++)
if (msgs[i].status & status_pending_net) {
send_net_post(msgs+i, subboards[curlsub].type,
subboards[curlsub].filename);
++i1;
msgs[i].status &= (~status_pending_net);
}
sprintf(s,"3%d messages sent.",i1);
nl();
pl(s);
nl();
bchanged=1;
}
}
if ((!quit) && (!express)) {
nl();
ss=syscfg.sl[actsl];
if (
((restrict_post & thisuser.restrict)==0) &&
(thisuser.posttoday<ss.posts) &&
(actsl>=subboards[curlsub].postsl)) {
sprintf(s,"3Post on %s? ",subboards[curlsub].name);
prt(5,s);
irt[0]=0;
irt_name[0]=0;
if (yn())
post();
}
}
savebase();
nl();
}
void qscan(int bn, int *ns)
{
int i,nextsub,os,sn;
char s[81],s1[81];
unsigned long qscnptrx,sd;
sn=usub[bn].subnum;
if ((hangup) || (sn<0))
return;
nl();
qscnptrx=QSCN(sn);
sd=sub_dates[sn];
if ((!sd) || (sd>qscnptrx)) {
nextsub=*ns;
os=cursub;
cursub=bn;
i=1;
iscan(cursub);
pl("f┌────────────────────────────────────────────────────────────────┐");
sprintf(s,"f│7 Q-scan 2%-41s1 %-2s - %-3u7 Msgsf │\r\n",subboards[curlsub].name,
usub[cursub].keys,nummsgs);
prt(1,s);
pl("f└────────────────────────────────────────────────────────────────┘");
nl();
while ((i<=nummsgs) && (msgs[i].qscan<=qscnptrx))
++i;
if ((nummsgs>0) && (msgs[nummsgs].qscan<=qscnptrx)) {
QSCN(curlsub)=status.qscanptr-1;
}
if ((nummsgs>0) && (i<=nummsgs))
if (msgs[i].qscan>QSCN(curlsub))
scan(i,2,&nextsub);
cursub=os;
*ns=nextsub;
pl("f┌───────────────────────────────────────────────────────┐");
sprintf(s,"f│7 Q-Scan Done 2%-41s f│\r\n",subboards[curlsub].name);
prt(1,s);
pl("f└───────────────────────────────────────────────────────┘");
} else {
sprintf(s,"7───1 Nothing new on 3%s1 %s7 ───",subboards[sn].name, usub[bn].keys);
prt(1,s);
}
nl();
}
void nscan(int ss)
{
int i,nextsub,abort,next;
nl();
nextsub=1;
prt(7,"─── 1Q-Scan All7 ───");
nl();
for (i=ss; (usub[i].subnum!=-1) && (i<MAX_SUBS) && (nextsub) && (!hangup); i++) {
#if MAX_SUBS>32
if (((i<32) && (thisuser.qscn & (1L<<(usub[i].subnum)))) ||
((i>=32) && (thisuser.qscn2 & (1L<<(usub[i].subnum-32))))
#else
if (thisuser.qscn & (1L<<(usub[i].subnum)))
#endif
qscan(i,&nextsub);
abort=next=0;
checka(&abort,&next);
if (abort)
nextsub=0;
}
nl();
prt(7,"─── 1Global Q-Scan Done7 ───");
nl();
nl();
if ((nextsub) && (thisuser.sysstatus & sysstatus_nscan_file_system) &&
((syscfg.sysconfig & sysconfig_no_xfer)==0))
{
prt(7,"Now scanning Transfers for new files...");
nscanall();
}
}
void scan2()
{
char s[81];
int i,i1;
iscan(cursub);
nl();
if (curlsub<0) {
pl("6No subs available.");
nl();
return;
}
npr("1%d3 msgs on1 %s\r\n",nummsgs, subboards[curlsub].name);
if (nummsgs==0)
return;
helpl=11;
prt(3,"Start listing at? ");
input(s,4);
i=atoi(s);
if (i<1)
i=0;
else
if (i>nummsgs)
i=nummsgs;
else
i--;
i1=0;
if (strcmp(s,"S")==0)
scan(0,0,&i1);
else
if (strcmp(s,"Q")) {
if (strcmp(s,"N")==0) {
} else
scan(i,1,&i1);
}
}
void printmenu(int i)
{
char s[81],s1[81];
int next;
next=0;
if ((thisuser.sysstatus & (sysstatus_color | sysstatus_ansi))
== (sysstatus_color | sysstatus_ansi)) {
sprintf(s1,"MENU%u.ANS", i);
sprintf(s,"%s%s",syscfg.gfilesdir,s1);
if (exist(s)) {
printfile(s1);
return;
}
}
sprintf(s1,"MENU%u.MSG", i);
sprintf(s,"%s%s",syscfg.gfilesdir,s1);
if (exist(s)) {
printfile(s1);
return;
}
if ((thisuser.screenchars==40) && (menus2[i].stored_as)) {
sprintf(s,"%sMENUS40.MSG",syscfg.gfilesdir);
read_message1(&menus2[i],0,0,&next,s);
} else
if ((okansi()) && (menus1[i].stored_as)) {
sprintf(s,"%sMENUSANS.MSG",syscfg.gfilesdir);
read_message1(&menus1[i],0,0,&next,s);
} else {
sprintf(s,"%sMENUS.MSG",syscfg.gfilesdir);
if (menus[i].stored_as)
read_message1(&menus[i],0,0,&next,s);
}
}
void delmail(int f, int loc)
{
mailrec m,m1;
userrec u;
int rm,i,t,otf;
lseek(f,((long) loc) * ((long) sizeof(mailrec)), SEEK_SET);
read(f,(void *)&m,sizeof(mailrec));
rm=1;
if (m.status & status_multimail) {
t=filelength(f)/sizeof(mailrec);
otf=0;
for (i=0; i<t; i++)
if (i!=loc) {
lseek(f,((long)i)*((long)sizeof(mailrec)),SEEK_SET);
read(f,(void *)&m1,sizeof(mailrec));
if ((m.msg.stored_as==m1.msg.stored_as) && (m.msg.storage_type==m1.msg.storage_type) && (m1.daten!=0xffffffff))
otf=1;
}
if (otf)
rm=0;
}
if (rm)
remove_link(&m.msg,"EMAIL");
if (m.tosys==0) {
read_user(m.touser,&u);
if (u.waiting) {
--u.waiting;
write_user(m.touser,&u);
close_user();
}
if (m.touser==1)
--fwaiting;
}
lseek(f,((long) loc) * ((long) sizeof(mailrec)), SEEK_SET);
m.touser=0;
m.tosys=0;
m.daten=0xffffffff;
m.msg.storage_type=0;
m.msg.stored_as=0xffffffff;
write(f,(void *)&m,sizeof(mailrec));
mailcheck=1;
}
void readmail()
{
int i,i1,i2,i3,f,mw,mloc[256],mfl,curmail,done,abort,next,okmail;
unsigned short x,xx;
char s[81],s1[81],s2[81],fn[81],*b;
mailrec m;
slrec ss;
userrec u;
char ch;
long len,num_mail,num_mail1;
ss=syscfg.sl[actsl];
sprintf(fn,"%sEMAIL.DAT",syscfg.datadir);
f=open(fn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
if (f<0) {
nl();
nl();
pl("No mail file exists!");
nl();
return;
}
mfl=filelength(f)/sizeof(mailrec);
mw=0;
for (i=0; (i<mfl) && (mw<255); i++) {
lseek(f,((long) (i)) * (sizeof(mailrec)), SEEK_SET);
read(f,(void *)(&m),sizeof(mailrec));
if ((m.tosys==0) && (m.touser==usernum))
mloc[mw++]=i;
}
thisuser.waiting=mw;
if (usernum==1)
fwaiting=mw;
if (mw==0) {
nl();
nl();
pl("Haha! No mail!");
nl();
return;
}
if (mw==1)
curmail=0;
else {
nl();
nl();
pl("1You have mail from3:");
nl();
for (i=0; i<mw; i++) {
lseek(f,((long) mloc[i]) * sizeof(mailrec),SEEK_SET);
read(f,(void *) (&m),sizeof(mailrec));
sprintf(s,"7[1%d7]3.5 ",i+1);
if ((m.anony & anony_sender) && ((ss.ability & ability_read_email_anony)==0)) {
strcat(s,"1>7UNKNOWN1<");
} else {
if (m.fromsys==0) {
if (m.fromuser==65535)
strcat(s,"NuclearArms Net");
else {
read_user(m.fromuser,&u);
strcat(s,nam(&u,m.fromuser));
}
} else {
sprintf(s1,"User %u @%u",m.fromuser,m.fromsys);
strcat(s,s1);
}
}
pl(s);
}
nl();
helpl=10;
pl("Hit return, or enter number");
outstr(":");
input(s,3);
if (strcmp(s,"Q")==0) {
close(f);
return;
}
i=atoi(s);
if (i)
if (i<=mw)
curmail=i-1;
else
curmail=0;
else
curmail=0;
}
done=0;
do {
sprintf(s,"7[1%u/%u7]3:7 ",curmail+1,mw);
abort=0;
nl();
nl();
osan(s,&abort,&next);
next=0;
ansic(MSG_COLOR);
s[0]=0;
if (mloc[curmail]<0) {
strcat(s,">>> MAIL DELETED <<<");
okmail=0;
pl(s);
nl();
nl();
} else {
lseek(f,((long) (mloc[curmail])) * (sizeof(mailrec)), SEEK_SET);
read(f,(void *)&m,sizeof(mailrec));
if ((m.tosys!=0) || (m.touser!=usernum)) {
mloc[curmail]=-1;
strcat(s,">>> MAIL DELETED <<<");
okmail=0;
pl(s);
nl();
nl();
} else {
strcat(s,m.title);
strcpy(irt,m.title);
irt_name[0]=0;
abort=0;
i=((ability_read_email_anony & ss.ability)!=0);
okmail=1;
pla(s,&abort);
if ((m.fromsys) && (!m.fromuser))
grab_user_name(&(m.msg),"EMAIL");
else
net_email_name[0]=0;
setorigin(m.fromsys, m.fromuser);
if (m.status & status_source_verified) {
if (strlen(m.title)<=78) {
xx=*(short *) (m.title+79);
sprintf(s,"-=-=: Type %u Source Verified",xx);
if (xx==1) {
strcat(s," (From NC)");
} else if ((xx>256) && (xx<512)) {
sprintf(s2," (From group %u GC)",xx-256);
strcat(s,s2);
}
} else {
strcpy(s,"-=-=: Source Verified (unknown type)");
}
if (!abort) {
ansic(4);
pla(s,&abort);
}
}
if (!abort)
read_message1(&m.msg, (m.anony & 0x0f), i, &next, "EMAIL");
}
}
do {
i2=1;
irt_name[0]=0;
prt(1,"Mail7 [1?7]3 : ");
helpl=34;
if (!okmail)
ch=onek("QI?-+G");
else
if (so())
ch=onek("QSRIDAF?-+GEZVUOL");
else
if (cs())
ch=onek("QSRIDAF?-+GZVUO");
else
ch=onek("QSRIDAF?+-G");
switch (ch) {
case 'E':
if ((so()) && (okmail)) {
b=readfile(&(m.msg),"EMAIL",&len);
extract_out(b,len,m.title);
}
i2=0;
break;
case 'Q':
done=1;
break;
case 'O':
if ((cs()) && (okmail) && (m.fromuser!=65535)) {
nl();
prt(2,"Which form letter? ");
input(s,4);
sprintf(s1,"%sFORM%s.MSG",syscfg.gfilesdir,s);
if (exist(s1)) {
load_workspace(s1,1);
close(f);
num_mail=((long) thisuser.feedbacksent) +
((long) thisuser.emailsent) +
((long) thisuser.emailnet);
if (m.fromuser!=65535)
email(m.fromuser,m.fromsys,0,m.anony);
f=open(fn,O_RDWR | O_BINARY);
num_mail1=((long) thisuser.feedbacksent) +
((long) thisuser.emailsent) +
((long) thisuser.emailnet);
if (num_mail != num_mail1) {
strcpy(s,nam(&thisuser,usernum));
if (m.anony & anony_receiver)
strcpy(s,"1>7UNKNOWN1<");
strcat(s," 3read your mail on ");
strcat(s,date());
if (m.fromsys==0)
ssm(m.fromuser,m.fromsys,s);
delmail(f,mloc[curmail]);
mloc[curmail]=-1;
++curmail;
if (curmail>=mw)
done=1;
if (!wfc)
topscreen();
} else {
sprintf(s,"%sINPUT.MSG",syscfg.tempdir);
unlink(s);
}
} else {
nl();
pl("File not found.");
nl();
i2=0;
}
}
break;
case 'G':
sprintf(s,"1Go to which 7[11-%u7]3 ? ",mw);
prt(2,s);
input(s,3);
i2=atoi(s);
if ((i2>0) && (i2<=mw)) {
curmail=i2-1;
i2=1;
} else
i2=0;
break;
case 'I':
case '+':
++curmail;
if (curmail>=mw)
done=1;
break;
case '-':
if (curmail)
--curmail;
break;
case 'R':
break;
case '?':
printmenu(4);
i2=0;
break;
case 'D':
if (!okmail)
break;
strcpy(s,nam(&thisuser,usernum));
if (m.anony & anony_receiver)
strcpy(s,"1>7UNKNOWN1<");
strcat(s," 3read your mail on ");
strcat(s,date());
if ((m.fromsys==0) && (m.fromuser!=65535))
ssm(m.fromuser,m.fromsys,s);
case 'Z':
if (!okmail)
break;
delmail(f,mloc[curmail]);
mloc[curmail]=-1;
++curmail;
if (curmail>=mw)
done=1;
if (!wfc)
topscreen();
break;
case 'F':
if (!okmail)
break;
if (m.status & status_multimail) {
nl();
pl("Can't forward multimail.");
nl();
break;
}
nl();
nl();
prt(1,"Forward to3: ");
input(s,30);
x=finduser(s);
if ((x==usernum) && (!cs())) {
x=0;
nl();
pl("Can't forward to yourself.");
nl();
}
xx=0;
if ((x) && (forwardm(&x,&xx))) {
nl();
if (x)
pl("Forwarded from there.");
else
pl("Can't forward to him.");
}
if (x>0) {
read_user(x,&u);
sprintf(s,"Forward to %s? ",nam(&u,x));
prt(5,s);
if (!yn())
x=0;
}
if (x>0) {
--thisuser.waiting;
if (usernum==1)
--fwaiting;
m.touser=x;
lseek(f,((long) (mloc[curmail])) * (sizeof(mailrec)), SEEK_SET);
write(f,(void *)&m,sizeof(mailrec));
read_user(x,&u);
++u.waiting;
write_user(x,&u);
if (x==1)
++fwaiting;
sprintf(s,"\r\n3Forwarded from1:7 %s",nam(&thisuser,usernum));
lineadd(&m.msg,s,"EMAIL");
sprintf(s,"%s forwarded your mail to %s",
nam(&thisuser,usernum), nam(&u,x));
if (m.fromsys==0)
ssm(m.fromuser,m.fromsys,s);
mloc[curmail]=-1;
++curmail;
if (curmail>=mw)
done=1;
if (!wfc)
topscreen();
npr("Forwarded to %s\r\n",nam(&u,x));
} else {
nl();
pl("3Don't know 'em.");
nl();
}
break;
case 'A':
case 'S':
if (!okmail)
break;
close(f);
num_mail=((long) thisuser.feedbacksent) +
((long) thisuser.emailsent) +
((long) thisuser.emailnet);
if (m.fromuser!=65535)
email(m.fromuser,m.fromsys,0,m.anony);
f=open(fn,O_RDWR | O_BINARY);
num_mail1=((long) thisuser.feedbacksent) +
((long) thisuser.emailsent) +
((long) thisuser.emailnet);
if (ch=='A') {
if (num_mail!=num_mail1) {
strcpy(s,nam(&thisuser,usernum));
if (m.anony & anony_receiver)
strcpy(s,"1>7UNKNOWN1<");
strcat(s," 3read your mail on ");
strcat(s,date());
if ((m.fromsys==0) && (m.fromuser!=65535))
ssm(m.fromuser,m.fromsys,s);
delmail(f,mloc[curmail]);
mloc[curmail]=-1;
++curmail;
if (curmail>=mw)
done=1;
if (!wfc)
topscreen();
} else {
nl();
pl("No mail sent.");
nl();
i2=0;
}
} else {
if (num_mail != num_mail1) {
++curmail;
if (curmail>=mw)
done=1;
if (!wfc)
topscreen();
}
}
break;
case 'U':
case 'V':
if (!okmail)
break;
if ((m.fromsys==0) && (cs()) && (m.fromuser!=65535))
if (ch=='V')
valuser(m.fromuser);
else
uedit(m.fromuser,0);
else
if (cs()) {
nl();
pl("Mail from another system.");
nl();
}
i2=0;
break;
case 'L':
if (!so())
break;
nl();
prt(3,"What's the filename? ");
input(s,50);
if (s[0]) {
nl();
prt(7,"You wanna edit? ");
if (yn()) {
nl();
load_workspace(s,0);
} else {
nl();
load_workspace(s,1);
}
}
}
} while ((!i2) && (!hangup));
} while ((!hangup) && (!done));
close(f);
}
void remove_post()
{
int i,i1,any,abort;
char s[161];
iscan(cursub);
if (curlsub<0) {
nl();
pl("6No subs available.");
nl();
return;
}
any=0;
abort=0;
nl();
nl();
npr("1Posts by you on 3%s\r\n", subboards[curlsub].name);
nl();
for (i=1; (i<=nummsgs) && (!abort); i++) {
if ((msgs[i].ownersys==0) && (msgs[i].owneruser==usernum)) {
any=1;
sprintf(s,"%u: %s",i,msgs[i].title);
pla(s,&abort);
}
}
if (!any) {
pl("6None.");
if (!cs())
return;
}
nl();
prt(3,"Remove which? ");
input(s,3);
i=atoi(s);
if ((i>0) && (i<=nummsgs)) {
if (((msgs[i].ownersys==0) && (msgs[i].owneruser==usernum)) || (lcs())) {
sprintf(s,"-%s removed from %s",msgs[i].title,subboards[curlsub].name);
sysoplog(s);
delete(i);
savebase();
nl();
pl("6Message removed.");
nl();
}
}
}
int external_edit(char *fn1, char *direc, int ednum, int numlines)
{
char s[255],s1[128],fn[128],s2[128],s3[81],sx1[21],sx2[21],sx3[21],ch;
int i,i1,i2,r,w,filethere,mod,newtl;
struct ftime ftimep,ftimep1;
if ((ednum>=numed) || (!okansi())) {
nl();
pl("You can't use that full screen editor.");
nl();
return(0);
}
i1=0;
for (i2=0; i2<81; i2++) {
i1+=editors[ednum].filename[i2];
i1+=editors[ednum].filenamecon[i2];
}
if (incom)
strcpy(s1,(editors[ednum].filename));
else
strcpy(s1,(editors[ednum].filenamecon));
if (s1[0]==0) {
nl();
pl("You can't use that full screen editor.");
nl();
return(0);
}
strcpy(s3,fn1);
stripfn1(s3);
if (direc[0]) {
cd_to(direc);
get_dir(fn,1);
cd_to(cdir);
} else
fn[0]=0;
strcat(fn,s3);
filethere=exist(fn);
if (filethere) {
i=open(fn,O_RDONLY | O_BINARY);
getftime(i,&ftimep);
close(i);
}
itoa(thisuser.screenchars,sx1,10);
if (screenlinest>defscreenbottom-topline)
newtl=0;
else
newtl=topline;
if (using_modem)
itoa(thisuser.screenlines,sx2,10);
else
itoa(defscreenbottom+1-newtl,sx2,10);
itoa(numlines,sx3,10);
stuff_in(s,s1,fn,sx1,sx2,sx3,"");
full_external(s,0,1);
if (!wfc)
topscreen();
mod=0;
if (!filethere) {
mod=exist(fn);
} else {
i=open(fn,O_RDONLY | O_BINARY);
getftime(i,&ftimep1);
close(i);
if ((ftimep.ft_year!=ftimep1.ft_year) ||
(ftimep.ft_month!=ftimep1.ft_month) ||
(ftimep.ft_day!=ftimep1.ft_day) ||
(ftimep.ft_hour!=ftimep1.ft_hour) ||
(ftimep.ft_min!=ftimep1.ft_min) ||
(ftimep.ft_tsec!=ftimep1.ft_tsec))
mod=1;
}
return(mod);
}