home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
WWIV2.ZIP
/
MSGBASE1.C
< prev
next >
Wrap
Text File
|
1995-12-16
|
47KB
|
1,868 lines
#include "vars.h"
#pragma hdrstop
#include "subxtr.h"
#include <dir.h>
#define ALLOW_FULLSCREEN 1
#define EMAIL_STORAGE 2
int deleted_flag;
/****************************************************************************/
void send_net_post(postrec *p, char *extra, int subnum)
{
net_header_rec nh, nh1;
char *b, *b1,*ss;
long len1, len2;
char s[81];
int f,i,onn,nn,n,nn1;
unsigned int *list;
xtrasubsnetrec *xnp;
b=readfile(&(p -> msg),extra,&len1);
if (b==NULL)
return;
onn=net_num;
if (p->status & status_post_new_net)
nn=p->title[80];
else if (xsubs[subnum].num_nets)
nn=xsubs[subnum].nets[0].net_num;
else
nn=net_num;
nn1=nn;
if (p->ownersys==0)
nn=-1;
nh1.tosys=0;
nh1.touser=0;
nh1.fromsys=p->ownersys;
nh1.fromuser=p->owneruser;
nh1.list_len=0;
nh1.daten=p->daten;
nh1.length=len1+1+strlen(p -> title);
nh1.method=0;
if (nh1.length > 32755) {
outstr(get_string(645));
npr("%lu",nh1.length-32755L);
outstr(get_string(646));
nh1.length = 32755;
len1=nh1.length-strlen(p->title)-1;
}
if ((b1=malloca(nh1.length+100))==NULL) {
farfree(b);
set_net_num(onn);
return;
}
strcpy(b1,p -> title);
memmove(&(b1[strlen(p -> title)+1]),b,(unsigned int) len1);
farfree(b);
for (n=0; n<xsubs[subnum].num_nets; n++) {
xnp=&(xsubs[subnum].nets[n]);
if ((xnp->net_num==nn) && (xnp->host))
continue;
set_net_num(xnp->net_num);
nh=nh1;
list=NULL;
nh.minor_type=xnp->type;
if (!nh.fromsys)
nh.fromsys=net_sysnum;
if (xnp->host) {
nh.main_type=main_type_pre_post;
nh.tosys=xnp->host;
} else {
nh.main_type=main_type_post;
sprintf(s,"%sN%s.NET",net_data, xnp->stype);
f=open(s,O_RDONLY|O_BINARY);
if (f>0) {
len1=filelength(f);
list=(unsigned int *)malloca(len1*2+1);
if (!list)
continue;
if ((b=malloca(len1+100L))==NULL) {
farfree(list);
continue;
}
read(f,b,len1);
close(f);
b[len1]=0;
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 (((net_num!=nn) || (nh.fromsys!=i)) && (i!=net_sysnum))
list[(nh.list_len)++]=i;
while ((len2<len1) && (b[len2]>='0') && (b[len2]<='9'))
++len2;
}
}
farfree(b);
}
if (!nh.list_len) {
if (list)
farfree(list);
continue;
}
}
if (!xnp->type)
nh.main_type=main_type_new_post;
if (nn1==net_num)
send_net(&nh, list, b1, xnp->type?NULL:xnp->stype);
else
gate_msg(&nh, b1, xnp->net_num, xnp->stype, list, nn);
if (list)
farfree(list);
}
farfree(b1);
set_net_num(onn);
}
/****************************************************************************/
void post(void)
{
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(get_string(668));
nl();
return;
}
ss=syscfg.sl[actsl];
if (freek1(syscfg.msgsdir)<10.0) {
nl();
pl(get_string(332));
nl();
return;
}
if ((restrict_post & thisuser.restrict) || (thisuser.posttoday>=ss.posts)) {
nl();
pl(get_string(669));
nl();
return;
}
if (actsl<subboards[curlsub].postsl) {
nl();
pl(get_string(670));
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 (xsubs[curlsub].num_nets) {
a &= (anony_real_name);
if (thisuser.restrict & restrict_net) {
nl();
pl(get_string(671));
nl();
return;
}
if (thisuser.restrict & (restrict_validate)) {
nl();
pl(get_string(671));
nl();
return;
}
if (net_sysnum) {
nl();
outstr(get_string(672));
for (i=0; i<xsubs[curlsub].num_nets; i++) {
if (i)
outstr(", ");
outstr(net_networks[xsubs[curlsub].nets[i].net_num].name);
}
outstr(".\r\n");
nl();
}
}
inmsg(&m,p.title,&a,1,(subboards[curlsub].filename),ALLOW_FULLSCREEN,
subboards[curlsub].name, (subboards[curlsub].anony&anony_no_tag)?1:0);
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 ((xsubs[curlsub].num_nets) &&
(subboards[curlsub].anony & anony_val_net) && (!lcs() || irt[0])) {
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,get_stringx(1,37),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,get_stringx(1,38),p.title,subboards[curlsub].name);
sysoplog(s);
outstr(get_string(673));
pl(subboards[curlsub].name);
save_status();
npr("\r\n1Your p/c ratio is now %-5.3f",post_ratio());
thisuser.gold=thisuser.gold+1;
if (xsubs[curlsub].num_nets) {
++thisuser.postnet;
if (!(p.status & status_pending_net))
send_net_post(&p, subboards[curlsub].filename, curlsub);
}
}
}
void extract_out(char *b, long len, char *title)
{
char s1[81],s2[81],ch=26,ch1;
int i;
do {
prt(2,get_string(674)); /*Save under what filename*/
input(s1,50);
if (s1[0]) {
if (strchr(s1,':') || strchr(s1,'\\'))
strcpy(s2,s1);
else
sprintf(s2,"%s%s",syscfg.gfilesdir,s1);
if (exist(s2)) {
nl();
pl(get_string(675)); /*filename already in use*/
nl();
prt(2,get_string(676)); /*Overwrite,append,etc..*/
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 (i<=0) {
pl(get_string(933)); /*Could not open file for writing*/
} else {
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);
outstr(get_string(677)); /*Message written to : */
pl(s2);
}
}
farfree(b);
}
void quote_out(char *b, long len, char *title)
{
char s1[81],s2[81],ch=26,ch1;
int i;
do {
strcpy(s1,"QUOTE");
if (s1[0]) {
if (strchr(s1,':') || strchr(s1,'\\'))
strcpy(s2,s1);
else
sprintf(s2,"%s%s",syscfg.gfilesdir,s1);
if (exist(s2)) {
unlink(s2);
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 (i<=0) {
pl(get_string(933)); /*Could not open file for writing*/
} else {
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);
/* outstr(get_string(677)); Message written to :
pl(s2);*/
}
}
farfree(b);
}
void grab_user_name(messagerec *m, char *fn)
{
char *ss,*ss1,*ss2;
long len;
ss=readfile(m,fn,&len);
if (ss) {
ss1=strchr(ss,'\r');
if (ss1) {
*ss1=0;
ss2=ss;
if ((ss[0]=='`') && (ss[1]=='`')) {
for (ss1=ss+2; *ss1; ss1++) {
if ((ss1[0]=='`') && (ss1[1]=='`'))
ss2=ss1+2;
}
while (*ss2==' ')
++ss2;
}
strcpy(net_email_name,ss2);
} 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;
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(get_string(668));
nl();
return;
}
do {
tleft(1);
if (xsubs[curlsub].num_nets)
set_net_num(xsubs[curlsub].nets[0].net_num);
else
set_net_num(0);
switch(optype) {
case 0: /* Read Prompt */
sprintf(s,"1%s5:7(11-%u7,1^%u7)5,7? 5:",get_string(678), nummsgs,msgnum);
nl();
if (express) {
s[0]=0;
nl();
nl();
} else {
sprintf(s1,"7[1%s7]\r\n",subboards[usub[cursub].subnum].name);
prt(2,s1);
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(okfsed()){
prt(5,"Quote message? ");
if(yn()) {
b=readfile(&(msgs[msgnum].msg),(subboards[curlsub].filename),&len);
quote_out(b,len, msgs[msgnum].title);
nl();
strcpy(s, "C:\\WWIV\\GFILES\\QUOTE");
if (s[0]) {
nl();
load_workspace(s,0);
}
}
}
if ((msgs[msgnum].ownersys) && (!msgs[msgnum].owneruser))
grab_user_name(&(msgs[msgnum].msg),subboards[curlsub].filename);
grab_quotes(&(msgs[msgnum].msg),subboards[curlsub].filename);
ss=syscfg.sl[actsl];
if (msgs[msgnum].status & status_post_new_net) {
set_net_num(msgs[msgnum].title[80]);
if (msgs[msgnum].title[80]==-1) {
pl(get_string(679));
break;
}
}
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);
grab_quotes(NULL, NULL);
break;
case 'P':
irt[0]=0;
irt_name[0]=0;
case 'W':
if (s[0]=='W') {
if(okfsed()){
prt(5,"Quote message? ");
if(yn()) {
b=readfile(&(msgs[msgnum].msg),(subboards[curlsub].filename),&len);
quote_out(b,len, msgs[msgnum].title);
nl();
strcpy(s, "C:\\WWIV\\GFILES\\QUOTE");
if (s[0]) {
nl();
load_workspace(s,0);
}
}
}}
deleted_flag=0;
grab_quotes(&(msgs[msgnum].msg),subboards[curlsub].filename);
post();
if (deleted_flag && (deleted_flag<=msgnum))
--msgnum;
grab_quotes(NULL, NULL);
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(get_string(680));
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(get_string(681));
else
pl(get_string(682));
nl();
}
break;
case 'X':
if ((lcs()) && (msgnum>0) && (msgnum<=nummsgs) &&
(subboards[curlsub].anony & anony_val_net) &&
(xsubs[curlsub].num_nets)) {
msgs[msgnum].status ^= status_pending_net;
bchanged=1;
nl();
if (msgs[msgnum].status & status_pending_net) {
val |= 2;
pl(get_string(683));
} else
pl(get_string(684));
nl();
}
break;
case 'U':
if ((lcs()) && (msgnum>0) && (msgnum<=nummsgs)) {
msgs[msgnum].anony=0;
bchanged=1;
nl();
pl(get_string(685));
}
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 ((lcs()) && (msgnum>0) && (msgnum<=nummsgs)) {
nl();
do {
prt(2,get_string(686));
ss1=mmkey(0);
if (ss1[0]=='?')
sublist();
} while ((!hangup) && (ss1[0]=='?'));
i=-1;
if (ss1[0]==0)
break;
for (i1=0; (i1<num_subs) && (usub[i1].subnum!=-1); 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);
if (msgnum>1)
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;
}
if ((!(subboards[curlsub].anony & anony_val_net)) ||
(!xsubs[curlsub].num_nets))
p.status &= ~status_pending_net;
msgs[++nummsgs]=p;
sub_dates[curlsub]=p.qscan;
bchanged=1;
savebase();
save_status();
iscan(cursub);
nl();
pl(get_string(687));
nl();
}
}
break;
case 'L':
if (!so())
break;
nl();
prt(2,get_string(7)); /*Filename?*/
input(s,50);
if (s[0]) {
nl();
prt(5,get_string(17)); /*Allow editing?*/
if (yn()) {
nl();
load_workspace(s,0);
} else {
nl();
load_workspace(s,1);
}
}
break;
/*************/
}
} else {
if (strcmp(s,"CLS")==0)
outchr('\x0c');
}
break;
case 1: /* List Titles */
i=0;
abort=0;
if (msgnum>=nummsgs)
abort=1;
while ((!abort) && (!hangup) && (++i<=10)) {
++msgnum;
if ((msgs[msgnum].ownersys==0) && (msgs[msgnum].owneruser==usernum))
sprintf(s1,"[%d]",msgnum);
else if (msgs[msgnum].ownersys!=0)
sprintf(s1,"<%d>",msgnum);
else
sprintf(s1,"(%d)",msgnum);
for (i1=0; i1<5; i1++)
s[i1]=32;
if (msgs[msgnum].qscan>qsc_p[curlsub])
s[0]='*';
if (msgs[msgnum].status & (status_pending_net | status_unvalidated))
s[0]='-';
strcpy(&s[7-strlen(s1)],s1);
strcat(s," ");
if ((msgs[msgnum].status&(status_unvalidated|status_delete))&&(!lcs()))
strcat(s,get_string(665));
else
strcat(s,msgs[msgnum].title);
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(5,get_string(688));
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(5,get_string(689));
if (yn()) {
i1=0;
for (i=1; i<=nummsgs; i++)
if (msgs[i].status & status_pending_net) {
send_net_post(msgs+i, subboards[curlsub].filename, curlsub);
++i1;
msgs[i].status &= (~status_pending_net);
}
nl();
npr("%d",i1);
pl(get_string(690));
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,"%s %s? ",get_string(691), subboards[curlsub].name);
prt(5,s);
irt[0]=0;
irt_name[0]=0;
grab_quotes(NULL, NULL);
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=qsc_p[sn];
sd=sub_dates[sn];
if ((!sd) || (sd>qscnptrx)) {
nextsub=*ns;
os=cursub;
cursub=bn;
i=1;
iscan(cursub);
sprintf(s,"7< 3%s %s %s 7- 3%u %s 7>",get_string(692), subboards[curlsub].name,
usub[cursub].keys,nummsgs, "msgs");
prt(1,s);
nl();
while ((i<=nummsgs) && (msgs[i].qscan<=qscnptrx))
++i;
if ((nummsgs>0) && (msgs[nummsgs].qscan<=qscnptrx)) {
qsc_p[curlsub]=status.qscanptr-1;
}
if ((nummsgs>0) && (i<=nummsgs))
if (msgs[i].qscan>qsc_p[curlsub])
scan(i,2,&nextsub);
cursub=os;
*ns=nextsub;
sprintf(s,"7< 3%s %s 7>",subboards[curlsub].name, get_string(693));
prt(1,s);
} else {
sprintf(s,"< %s %s %s >",get_string(694), subboards[sn].name, usub[bn].keys);
prt(1,s);
}
nl();
}
void nscan(int ss)
{
int i,nextsub,abort,next;
nl();
nextsub=1;
prt(3,get_string(695));
nl();
for (i=ss; (usub[i].subnum!=-1) && (i<num_subs) && (nextsub) && (!hangup); i++) {
if (qsc_q[usub[i].subnum/32]&(1L<<(usub[i].subnum%32)))
qscan(i,&nextsub);
abort=next=0;
checka(&abort,&next);
if (abort)
nextsub=0;
}
nl();
prt(3,get_string(696));
nl();
nl();
if ((nextsub) && (thisuser.sysstatus & sysstatus_nscan_file_system) &&
((syscfg.sysconfig & sysconfig_no_xfer)==0))
nscanall();
}
void scan2(void)
{
char s[81];
int i,i1;
iscan(cursub);
nl();
if (curlsub<0) {
pl(get_string(668));
nl();
return;
}
npr("%d",nummsgs);
outstr(get_string(697));
pl(subboards[curlsub].name);
if (nummsgs==0)
return;
helpl=11;
prt(2,get_string(698));
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",languagedir,s1);
if (exist(s)) {
printfile(s1);
return;
}
}
sprintf(s1,"MENU%u.MSG", i);
sprintf(s,"%s%s",languagedir,s1);
if (exist(s)) {
printfile(s1);
return;
}
if ((thisuser.screenchars==40) && (menus2[i].stored_as)) {
sprintf(s,"%sMENUS40.MSG",languagedir);
read_message1(&menus2[i],0,0,&next,s);
} else
if ((okansi()) && (menus1[i].stored_as)) {
sprintf(s,"%sMENUSANS.MSG",languagedir);
read_message1(&menus1[i],0,0,&next,s);
} else {
sprintf(s,"%sMENUS.MSG",languagedir);
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 purgemail(int f,int *mloc,int mw,int *curmail, mailrec *m1, slrec *ss)
{
int i;
mailrec m;
if (m1->fromuser==65535)
return;
ansic(5);
if ((m1->anony & anony_sender) && ((ss->ability & ability_read_email_anony)==0)) {
outstr(get_string(699));
} else {
outstr(get_string(700));
if (m1->fromsys) {
npr("#%u @%u? ",m1->fromuser, m1->fromsys);
} else {
npr("#%u? ",m1->fromuser);
}
}
if (yn()) {
for (i=0; i<mw; i++) {
if (mloc[i]>=0) {
lseek(f,((long) mloc[i]) * sizeof(mailrec),SEEK_SET);
read(f,(void *) (&m),sizeof(mailrec));
if ((m.fromuser==m1->fromuser) && (m.fromsys==m1->fromsys)) {
outstr(get_string(701));
npr("%d\r\n",i+1);
delmail(f,mloc[i]);
mloc[i]=-1;
if (*curmail==i)
++(*curmail);
}
} else {
if (*curmail==i)
++(*curmail);
}
}
}
}
void readmail(void)
{
int i,i1,i2,i3,f,mw,mloc[256],mfl,curmail,done,abort,next,okmail,tp,nn;
unsigned short x,xx;
char s[81],s1[81],s2[81],fn[81],*b,*ss1;
mailrec m;
slrec ss;
userrec u;
char ch;
long len,num_mail,num_mail1;
unsigned short un, sy;
net_system_list_rec *csne;
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(get_string(702));
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(get_string(27));
nl();
return;
}
if (mw==1)
curmail=0;
else {
nl();
nl();
pl(get_string(703));
nl();
for (i=0; i<mw; i++) {
lseek(f,((long) mloc[i]) * sizeof(mailrec),SEEK_SET);
read(f,(void *) (&m),sizeof(mailrec));
tp=80;
if (m.status & status_source_verified)
tp -= 2;
if (m.status & status_new_net) {
tp -= 1;
if (strlen(m.title)<=tp) {
nn=(unsigned char) m.title[tp+1];
} else
nn=0;
} else
nn=0;
sprintf(s,"%d. ",i+1);
if ((m.anony & anony_sender) && ((ss.ability & ability_read_email_anony)==0)) {
strcat(s,get_string(482));
} else {
if (m.fromsys==0) {
if (m.fromuser==65535) {
if (nn!=255)
strcat(s,net_networks[nn].name);
} else {
read_user(m.fromuser,&u);
strcat(s,nam(&u,m.fromuser));
}
} else {
set_net_num(nn);
csne=next_system(m.fromsys);
if (csne)
ss1=csne->name;
else
ss1=get_string(622);
if (nn==255) {
sprintf(s1,"%s #%u @%u",get_string(704), m.fromuser,m.fromsys);
} else {
if (net_num_max>1)
sprintf(s1,"%s #%u @%u (%s)",
net_networks[nn].name,m.fromuser,m.fromsys,ss1);
else
sprintf(s1,"%s %u @%u (%s)",get_string(658), m.fromuser,m.fromsys,ss1);
}
strcat(s,s1);
}
}
pl(s);
}
nl();
helpl=10;
pl(get_string(705));
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,"(%u/%u): ",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,get_string(706));
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,get_string(706));
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;
tp=80;
if (m.status & status_source_verified) {
tp -= 2;
if (strlen(m.title)<=tp) {
xx=*(short *) (m.title+tp+1);
strcpy(s,get_string(707));
sprintf(s+strlen(s),"%u",xx);
if (xx==1) {
strcat(s,get_string(708));
} else if ((xx>256) && (xx<512)) {
strcpy(s2,get_string(709));
sprintf(s2+strlen(s2),"%d)",xx-256);
strcat(s,s2);
}
} else {
strcpy(s,get_string(710));
}
if (!abort) {
ansic(4);
pla(s,&abort);
}
}
if (m.status & status_new_net) {
tp -= 1;
if (strlen(m.title)<=tp) {
nn=m.title[tp+1];
} else
nn=0;
} else
nn=0;
set_net_num(nn);
if (nn==255)
setorigin(0,0);
else
setorigin(m.fromsys, m.fromuser);
if (!abort)
read_message1(&m.msg, (m.anony & 0x0f), i, &next, "EMAIL");
}
}
do {
set_net_num(nn);
i2=1;
irt_name[0]=0;
prt(2,get_string(711));
helpl=34;
if (!okmail)
ch=onek("QI?-+G");
else
if (so())
ch=onek("QSRIDAF?-+GEZPVUOLC");
else
if (cs())
ch=onek("QSRIDAF?-+GZPVUOC");
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) && (nn!=255)) {
nl();
prt(2,get_string(712));
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);
grab_quotes(NULL, NULL);
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,nam1(&thisuser,usernum,net_sysnum));
if (m.anony & anony_receiver)
strcpy(s,get_string(482));
strcat(s,get_string(713));
strcat(s,date());
if (!(m.status & status_source_verified))
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(get_string(89));
nl();
i2=0;
}
}
break;
case 'G':
ansic(2);
outstr(get_string(714));
npr("%u) ? ",mw);
ansic(0);
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,nam1(&thisuser,usernum,net_sysnum));
if (m.anony & anony_receiver)
strcpy(s,get_string(482));
strcat(s,get_string(713));
strcat(s,date());
if ((!(m.status & status_source_verified)) && (nn!=255))
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 'P':
if (!okmail)
break;
purgemail(f,mloc,mw,&curmail,&m,&ss);
if (curmail>=mw)
done=1;
if (!wfc)
topscreen();
break;
case 'F':
if (!okmail)
break;
if (m.status & status_multimail) {
nl();
pl(get_string(715));
nl();
break;
}
nl();
nl();
prt(2,get_string(716));
input(s,30);
parse_email_info(s, &un, &sy);
if (un || sy) {
if (forwardm(&un, &sy)) {
pl(get_string(656));
}
if ((un==usernum) && (sy==0) && (!cs())) {
pl(get_string(469));
un=0;
}
if (un || sy) {
if (sy) {
if (net_num_max>1) {
if (un) {
sprintf(s1,"%s #%u @%u",net_name, un, sy);
} else {
sprintf(s1,"%s %s @%u",net_name, net_email_name, sy);
}
} else {
if (un) {
sprintf(s1,"#%u @%u", un, sy);
} else {
sprintf(s1,"%s @%u", net_email_name, sy);
}
}
} else {
set_net_num(nn);
read_user(un,&u);
strcpy(s1,nam1(&u,un,net_sysnum));
}
if (ok_to_mail(un, sy, 0)) {
ansic(5);
outstr(get_string(393));
npr("%s? ",s1);
if (yn()) {
i=net_num;
sprintf(s,"\r\n%s: %s", get_string(717),
nam1(&thisuser,usernum,net_sysnum));
set_net_num(nn);
lineadd(&m.msg,s,"EMAIL");
sprintf(s,"%s %s %s",
nam1(&thisuser,usernum,net_sysnum),
get_string(718), s1);
if (!(m.status & status_source_verified))
ssm(m.fromuser,m.fromsys,s);
set_net_num(i);
sysoplog(get_stringx(1,101));
--thisuser.waiting;
if (usernum==1)
--fwaiting;
outstr(get_string(720));
close(f);
if ((nn!=255) && ((status.net_version>=32) || (nn==net_num))) {
sendout_email(m.title, &m.msg, m.anony, un, sy, 1, m.fromuser, m.fromsys, 1, nn);
} else {
sendout_email(m.title, &m.msg, m.anony, un, sy, 1, usernum, net_sysnum, 1, net_num);
}
f=open(fn,O_RDWR | O_BINARY);
m.touser=0;
m.tosys=0;
m.daten=0xffffffff;
m.msg.storage_type=0;
m.msg.stored_as=0xffffffff;
lseek(f,((long) (mloc[curmail])) * (sizeof(mailrec)), SEEK_SET);
write(f,(void *)&m,sizeof(mailrec));
mloc[curmail]=-1;
++curmail;
if (curmail>=mw)
done=1;
if (!wfc)
topscreen();
mailcheck=1;
}
}
}
}
break;
case 'A':
case 'S':
if (!okmail)
break;
if(okfsed()){
prt(5,"Quote message? ");
if(yn()) {
b=readfile(&(m.msg),"EMAIL",&len);
quote_out(b,len,m.title);
nl();
strcpy(s, "C:\\WWIV\\GFILES\\QUOTE");
if (s[0]) {
nl();
load_workspace(s,0);
}
}
}
close(f);
num_mail=((long) thisuser.feedbacksent) +
((long) thisuser.emailsent) +
((long) thisuser.emailnet);
if (nn==255) {
pl(get_string(679));
i2=0;
break;
} else if (m.fromuser!=65535) {
grab_quotes(&(m.msg),"EMAIL");
email(m.fromuser,m.fromsys,0,m.anony);
grab_quotes(NULL, NULL);
}
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,nam1(&thisuser,usernum,net_sysnum));
if (m.anony & anony_receiver)
strcpy(s,get_string(482));
strcat(s,get_string(713));
strcat(s,date());
if (!(m.status & status_source_verified))
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(get_string(721));
nl();
i2=0;
}
} else {
if (num_mail != num_mail1) {
++curmail;
if (curmail>=mw)
done=1;
if (!wfc)
topscreen();
}
}
break;
case 'U':
case 'V':
case 'C':
if (!okmail)
break;
if ((m.fromsys==0) && (cs()) && (m.fromuser!=65535))
if (ch=='V')
valuser(m.fromuser);
else if (ch=='U')
uedit(m.fromuser,0);
else
uedit(m.fromuser,3);
else
if (cs()) {
nl();
pl(get_string(722));
nl();
}
i2=0;
break;
case 'L':
if (!so())
break;
nl();
prt(2,get_string(7));
input(s,50);
if (s[0]) {
nl();
prt(5,get_string(17));
if (yn()) {
nl();
load_workspace(s,0);
} else {
nl();
load_workspace(s,1);
}
}
break;
}
} while ((!i2) && (!hangup));
} while ((!hangup) && (!done));
close(f);
}
void remove_post(void)
{
int i,i1,any,abort;
char s[161];
iscan(cursub);
if (curlsub<0) {
nl();
pl(get_string(668));
nl();
return;
}
any=0;
abort=0;
nl();
nl();
outstr(get_string(723));
pl(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(get_string(5));
if (!cs())
return;
}
nl();
prt(2,get_string(724));
input(s,3);
i=atoi(s);
if ((i>0) && (i<=nummsgs)) {
if (((msgs[i].ownersys==0) && (msgs[i].owneruser==usernum)) || (lcs())) {
sprintf(s,get_stringx(1,39),msgs[i].title,subboards[curlsub].name);
sysoplog(s);
delete(i);
savebase();
nl();
pl(get_string(725));
--thisuser.msgpost;
npr("\r\n1Your p/c ratio is now %-5.3f",post_ratio());
--thisuser.gold;
nl();
}
}
}
int external_edit(char *fn1, char *direc, int ednum, int numlines, char *dest, char *title, int flags)
{
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;
FILE *f;
unlink("editor.inf");
unlink("result.ed");
if ((ednum>=numed) || (!okansi())) {
nl();
pl(get_string(726));
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(get_string(726));
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,"");
if ((f=fopen("EDITOR.INF","wt"))!=NULL) {
fprintf(f,"%s\n%s\n%u\n%s\n%s\n%u\n%u\n%u\n",
title,
dest,
usernum,
thisuser.name,
thisuser.realname,
thisuser.sl,
flags,
topline);
fclose(f);
}
if (flags&1) {
/* disable tag lines */
f=fopen("disable.tag","w");
if (f) fclose(f);
} else {
unlink("disable.tag");
}
if (!irt[0]) {
unlink("quotes.txt");
unlink("quotes.ind");
}
in_fsed=1;
full_external(s,0,1);
in_fsed=0;
unlink("editor.inf");
unlink("disable.tag");
unlink("quotes.txt");
unlink("quotes.ind");
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);
}
#define LINELEN 79
#define NL {if (!cp) fwrite(pfx,1,pfxlen,f);fwrite("\r\n",1,2,f); cp=ns=ctlc=0;}
#define FLSH {if (ss1) { if (cp && (l3+cp>=LINELEN)) NL else if (ns) cp+=fwrite(" ",1,1,f);\
if (!cp) {if (ctld) fprintf(f,"\x4%c",ctld);ctld=0;cp=fwrite(pfx,1,pfxlen,f);}\
fwrite(ss1,1,l2,f); cp+=l3; ss1=NULL;l2=l3=0;ns=1;}}
void grab_quotes(messagerec *m, char *aux)
{
char *ss,*ss1;
long l,l1,l2,l3;
FILE *f;
char *pfx;
int cp=0,ctla=0,ctlc=0,ns=0,ctld=0,ff;
int pfxlen;
pfx=get_stringx(1,102);
pfxlen=strlen(pfx);
unlink("quotes.txt");
unlink("quotes.ind");
if (quotes_nrm)
farfree(quotes_nrm);
if (quotes_ind)
farfree(quotes_ind);
quotes_nrm=quotes_ind=NULL;
quotes_nrm_l=quotes_ind_l=0;
if (m && aux) {
ss=readfile(m, aux, &l);
if (ss) {
quotes_nrm=ss;
quotes_nrm_l=l;
f=fopen("quotes.txt", "wb");
if (f) {
fwrite(ss, 1, l, f);
fclose(f);
}
f=fopen("quotes.ind", "wb");
if (f) {
l3=l2=0;
ss1=NULL;
for (l1=0; l1<l; l1++) {
if (ctld==-1)
ctld=ss[l1];
else switch(ss[l1]) {
case 1:
ctla=1;
break;
case 2:
break;
case 3:
if (!ss1)
ss1=ss+l1;
l2++;
ctlc=1;
break;
case 4:
ctld=-1;
break;
case '\n':
if (ctla) {
ctla=0;
} else {
FLSH;
NL;
}
break;
case ' ':
case '\r':
if (ss1) {
FLSH;
} else {
if (ss[l1]==' ') {
if (cp+1>=LINELEN)
NL;
if (!cp) {
if (ctld)
fprintf(f,"\x4%c",ctld);
ctld=0;
cp=fwrite(pfx,1,pfxlen,f);
}
cp++;
fwrite(" ",1,1,f);
}
}
break;
default:
if (!ss1)
ss1=ss+l1;
l2++;
if (ctlc)
ctlc=0;
else
l3++;
break;
}
}
FLSH;
if (cp)
fwrite("\r\n",1,2,f);
fclose(f);
#ifdef SAVE_IN_MEM
ff=open("quotes.ind",O_RDONLY|O_BINARY);
if (ff>0) {
quotes_ind_l=filelength(ff);
quotes_ind=(char *)farmalloc(quotes_ind_l);
if (quotes_ind) {
read(ff,quotes_ind, quotes_ind_l);
} else
quotes_ind_l=0;
close(ff);
}
#else
farfree(quotes_nrm);
quotes_nrm=NULL;
quotes_nrm_l=0;
#endif
}
}
}
}