Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 186c34a4 authored by rswindell's avatar rswindell

Initial support for QWK HEADERS.DAT file - generation only, consumption next.

A lot of strcpy->SAFECOPY and sprintf->safe_snprintf/SAFEPRINTF conversions
and other general code cleanup too.
parent c4ebc54a
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -45,17 +45,105 @@
/* mode determines how to handle Ctrl-A codes */
/****************************************************************************/
ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
, int conf)
, int conf, FILE* hdrs)
{
char str[512],from[512],to[512],ch=0,tear=0,tearwatch=0,*buf,*p;
char tmp[512];
long l,size=0,offset;
int i;
ushort hfield_type;
struct tm tm;
smbmsg_t remsg;
time_t tt;
offset=ftell(qwk_fp);
if(hdrs!=NULL) {
fprintf(hdrs,"[%x]\n",offset);
/* Message-IDs */
fprintf(hdrs,"Message-ID: %s\n",get_msgid(&cfg,subnum,msg));
if(msg->reply_id!=NULL)
fprintf(hdrs,"In-Reply-To: %s\n",msg->reply_id);
/* Time/Date/Zone info */
fprintf(hdrs,"WhenWritten: %-20s %04hx\n"
,xpDateTime_to_isoDateTimeStr(
time_to_xpDateTime(msg->hdr.when_written.time,smb_tzutc(msg->hdr.when_written.zone))
,/* separators: */"","","", /* precision: */0
,str,sizeof(str))
,msg->hdr.when_written.zone
);
fprintf(hdrs,"WhenImported: %-20s %04hx\n"
,xpDateTime_to_isoDateTimeStr(
time_to_xpDateTime(msg->hdr.when_imported.time,smb_tzutc(msg->hdr.when_imported.zone))
,/* separators: */"","","", /* precision: */0
,str,sizeof(str))
,msg->hdr.when_imported.zone
);
/* SENDER */
fprintf(hdrs,"%s: %s\n",smb_hfieldtype(SENDER),msg->from);
if(msg->from_net.type)
fprintf(hdrs,"%s: %s\n",smb_hfieldtype(SENDERNETADDR),smb_netaddrstr(&msg->from_net,tmp));
if((p=(char*)smb_get_hfield(msg,hfield_type=SENDERIPADDR,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n",smb_hfieldtype(hfield_type),p);
if((p=(char*)smb_get_hfield(msg,hfield_type=SENDERHOSTNAME,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n",smb_hfieldtype(hfield_type),p);
if((p=(char*)smb_get_hfield(msg,hfield_type=SENDERPROTOCOL,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n",smb_hfieldtype(hfield_type),p);
if(msg->from_org!=NULL)
fprintf(hdrs,"Organization: %s\n",msg->from_org);
/* Reply-To */
if((p=(char*)smb_get_hfield(msg,RFC822REPLYTO,NULL))==NULL) {
if(msg->replyto_net.type==NET_INTERNET)
p=(char*)msg->replyto_net.addr;
else if(msg->replyto!=NULL)
p=msg->replyto;
}
if(p!=NULL)
fprintf(hdrs,"Reply-To: %s\n",p); /* use original RFC822 header field */
/* SUBJECT */
fprintf(hdrs,"%s: %s\n",smb_hfieldtype(SUBJECT),msg->subj);
/* RECIPIENT */
fprintf(hdrs,"%s: %s\n",smb_hfieldtype(RECIPIENT),msg->to);
if(msg->to_net.type)
fprintf(hdrs,"%s: %s\n",smb_hfieldtype(RECIPIENTNETADDR),smb_netaddrstr(&msg->to_net,tmp));
/* FidoNet */
if((p=(char*)smb_get_hfield(msg,hfield_type=FIDOAREA,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
if((p=(char*)smb_get_hfield(msg,hfield_type=FIDOSEENBY,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
if((p=(char*)smb_get_hfield(msg,hfield_type=FIDOPATH,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
if((p=(char*)smb_get_hfield(msg,hfield_type=FIDOMSGID,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
if((p=(char*)smb_get_hfield(msg,hfield_type=FIDOREPLYID,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
if((p=(char*)smb_get_hfield(msg,hfield_type=FIDOPID,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
if((p=(char*)smb_get_hfield(msg,hfield_type=FIDOFLAGS,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
if((p=(char*)smb_get_hfield(msg,hfield_type=FIDOTID,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
/* USENET */
if((p=(char*)smb_get_hfield(msg,hfield_type=USENETPATH,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
if((p=(char*)smb_get_hfield(msg,hfield_type=USENETNEWSGROUPS,NULL))!=NULL)
fprintf(hdrs,"%s: %s\n", smb_hfieldtype(hfield_type), p);
/* RFC822 header fields: */
for(i=0;i<msg->total_hfields;i++)
if(msg->hfield[i].type==RFC822HEADER)
fprintf(hdrs,"%s\n",msg->hfield_dat[i]);
/* Blank line: */
fprintf(hdrs,"\n");
}
memset(str,' ',QWK_BLOCK_LEN);
fwrite(str,QWK_BLOCK_LEN,1,qwk_fp); /* Init header to space */
......@@ -70,14 +158,15 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
else
sprintf(from,"%.128s@%.128s",msg->from,(char*)msg->from_net.addr);
if(strlen(from)>25) {
sprintf(str,"From: %.128s%c%c",from,QWK_NEWLINE,QWK_NEWLINE);
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str);
sprintf(from,"%.128s",msg->from); } }
size+=fprintf(qwk_fp,"From: %.128s%c%c",from,QWK_NEWLINE,QWK_NEWLINE);
sprintf(from,"%.128s",msg->from);
}
}
else {
sprintf(from,"%.128s",msg->from);
if(msg->hdr.attr&MSG_ANONYMOUS && !SYSOP) /* from user */
strcpy(from,text[Anonymous]); }
SAFECOPY(from,text[Anonymous]);
}
if(msg->to_net.addr && (uint)subnum==INVALID_SUB) {
if(msg->to_net.type==NET_FIDO)
......@@ -89,10 +178,9 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
p=strchr((char *)msg->to_net.addr,'/');
if(p) { /* Another hop */
p++;
strcpy(to,"NETMAIL");
sprintf(str,"%.128s@%.128s%c",msg->to,p,QWK_NEWLINE);
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str); }
SAFECOPY(to,"NETMAIL");
size+=fprintf(qwk_fp,"%.128s@%.128s%c",msg->to,p,QWK_NEWLINE);
}
else
sprintf(to,"%.128s",msg->to); }
else
......@@ -100,73 +188,56 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
else
sprintf(to,"%.128s@%.128s",msg->to,(char*)msg->to_net.addr);
if(strlen(to)>25) {
sprintf(str,"To: %.128s%c%c",to,QWK_NEWLINE,QWK_NEWLINE);
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str);
size+=fprintf(qwk_fp,"To: %.128s%c%c",to,QWK_NEWLINE,QWK_NEWLINE);
if(msg->to_net.type==NET_QWK)
strcpy(to,"NETMAIL");
SAFECOPY(to,"NETMAIL");
else
sprintf(to,"%.128s",msg->to); } }
sprintf(to,"%.128s",msg->to);
}
}
else
sprintf(to,"%.128s",msg->to);
if(msg->from_net.type==NET_QWK && mode&QM_VIA && !msg->forwarded) {
sprintf(str,"@VIA: %.*s%c"
,(int)(sizeof(str)-12),(char*)msg->from_net.addr,QWK_NEWLINE);
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str); }
if(msg->from_net.type==NET_QWK && mode&QM_VIA && !msg->forwarded)
size+=fprintf(qwk_fp,"@VIA: %s%c"
,(char*)msg->from_net.addr,QWK_NEWLINE);
if(mode&QM_MSGID && (uint)subnum!=INVALID_SUB) {
sprintf(str,"@MSGID: %.*s%c"
,(int)(sizeof(str)-12),get_msgid(&cfg,subnum,msg),QWK_NEWLINE);
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str);
size+=fprintf(qwk_fp,"@MSGID: %s%c"
,get_msgid(&cfg,subnum,msg),QWK_NEWLINE);
str[0]=0;
if(msg->reply_id) {
SAFECOPY(tmp,msg->reply_id);
truncstr(tmp," ");
sprintf(str,"@REPLY: %.*s%c"
,(int)(sizeof(str)-12),tmp,QWK_NEWLINE);
size+=fprintf(qwk_fp,"@REPLY: %s%c"
,tmp,QWK_NEWLINE);
} else if(msg->hdr.thread_back) {
memset(&remsg,0,sizeof(remsg));
remsg.hdr.number=msg->hdr.thread_back;
if(smb_getmsgidx(&smb, &remsg))
sprintf(str,"@REPLY: <%s>%c",smb.last_error,QWK_NEWLINE);
size+=fprintf(qwk_fp,"@REPLY: <%s>%c",smb.last_error,QWK_NEWLINE);
else
sprintf(str,"@REPLY: %s%c"
size+=fprintf(qwk_fp,"@REPLY: %s%c"
,get_msgid(&cfg,subnum,&remsg)
,QWK_NEWLINE);
}
if(str[0]) {
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str);
}
}
if(msg->hdr.when_written.zone && mode&QM_TZ) {
sprintf(str,"@TZ: %04x%c",msg->hdr.when_written.zone,QWK_NEWLINE);
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str);
}
if(msg->hdr.when_written.zone && mode&QM_TZ)
size+=fprintf(qwk_fp,"@TZ: %04x%c",msg->hdr.when_written.zone,QWK_NEWLINE);
if(msg->replyto!=NULL && mode&QM_REPLYTO) {
sprintf(str,"@REPLYTO: %.*s%c"
,(int)(sizeof(str)-12),msg->replyto,QWK_NEWLINE);
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str);
}
if(msg->replyto!=NULL && mode&QM_REPLYTO)
size+=fprintf(qwk_fp,"@REPLYTO: %s%c"
,msg->replyto,QWK_NEWLINE);
p=0;
for(i=0;i<msg->total_hfields;i++) {
if(msg->hfield[i].type==SENDER)
p=(char *)msg->hfield_dat[i];
if(msg->hfield[i].type==FORWARDED && p) {
sprintf(str,"Forwarded from %s on %s%c",p
size+=fprintf(qwk_fp,"Forwarded from %s on %s%c",p
,timestr(*(time32_t *)msg->hfield_dat[i])
,QWK_NEWLINE);
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str);
}
}
......@@ -228,70 +299,68 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
str[0]=0;
switch(toupper(ch)) { /* non-color codes */
case 'L':
strcpy(str,"\x1b[2J\x1b[H");
SAFECOPY(str,"\x1b[2J\x1b[H");
break;
case 'W':
strcpy(str,ansi(LIGHTGRAY));
SAFECOPY(str,ansi(LIGHTGRAY));
break;
case 'K':
strcpy(str,ansi(BLACK));
SAFECOPY(str,ansi(BLACK));
break;
case 'H':
strcpy(str,ansi(HIGH));
SAFECOPY(str,ansi(HIGH));
break;
case 'I':
strcpy(str,ansi(BLINK));
SAFECOPY(str,ansi(BLINK));
break;
case 'N': /* Normal */
strcpy(str,ansi(ANSI_NORMAL));
SAFECOPY(str,ansi(ANSI_NORMAL));
break;
case 'R': /* Color codes */
strcpy(str,ansi(RED));
SAFECOPY(str,ansi(RED));
break;
case 'G':
strcpy(str,ansi(GREEN));
SAFECOPY(str,ansi(GREEN));
break;
case 'B':
strcpy(str,ansi(BLUE));
SAFECOPY(str,ansi(BLUE));
break;
case 'C':
strcpy(str,ansi(CYAN));
SAFECOPY(str,ansi(CYAN));
break;
case 'M':
strcpy(str,ansi(MAGENTA));
SAFECOPY(str,ansi(MAGENTA));
break;
case 'Y': /* Yellow */
strcpy(str,ansi(BROWN));
SAFECOPY(str,ansi(BROWN));
break;
case '0':
strcpy(str,ansi(BG_BLACK));
SAFECOPY(str,ansi(BG_BLACK));
break;
case '1':
strcpy(str,ansi(BG_RED));
SAFECOPY(str,ansi(BG_RED));
break;
case '2':
strcpy(str,ansi(BG_GREEN));
SAFECOPY(str,ansi(BG_GREEN));
break;
case '3':
strcpy(str,ansi(BG_BROWN));
SAFECOPY(str,ansi(BG_BROWN));
break;
case '4':
strcpy(str,ansi(BG_BLUE));
SAFECOPY(str,ansi(BG_BLUE));
break;
case '5':
strcpy(str,ansi(BG_MAGENTA));
SAFECOPY(str,ansi(BG_MAGENTA));
break;
case '6':
strcpy(str,ansi(BG_CYAN));
SAFECOPY(str,ansi(BG_CYAN));
break;
case '7':
strcpy(str,ansi(BG_LIGHTGRAY));
SAFECOPY(str,ansi(BG_LIGHTGRAY));
break;
}
if(str[0]) {
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str);
}
if(str[0])
size+=fwrite(str,sizeof(char),strlen(str),qwk_fp);
continue;
} /* End Expand */
......@@ -314,18 +383,18 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
if(mode&QM_TAGLINE && !(cfg.sub[subnum]->misc&SUB_NOTAG)) {
if(!tear) /* no tear line */
sprintf(str,"\1n---%c",QWK_NEWLINE); /* so add one */
SAFEPRINTF(str,"\1n---%c",QWK_NEWLINE); /* so add one */
else
strcpy(str,"\1n");
SAFECOPY(str,"\1n");
if(cfg.sub[subnum]->misc&SUB_ASCII) ch='*';
else ch='';
sprintf(tmp," %c \1g%.10s\1n %c %.127s%c"
safe_snprintf(tmp,sizeof(tmp)," %c \1g%.10s\1n %c %.127s%c"
,ch,VERSION_NOTICE,ch,cfg.sub[subnum]->tagline,QWK_NEWLINE);
strcat(str,tmp);
if(!(mode&A_LEAVE))
remove_ctrl_a(str,NULL);
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str); }
size+=fwrite(str,sizeof(char),strlen(str),qwk_fp);
}
while(size%QWK_BLOCK_LEN) { /* Pad with spaces */
size++;
......@@ -335,7 +404,7 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
if(localtime_r(&tt,&tm)==NULL)
memset(&tm,0,sizeof(tm));
sprintf(tmp,"%02u-%02u-%02u%02u:%02u"
safe_snprintf(tmp,sizeof(tmp),"%02u-%02u-%02u%02u:%02u"
,tm.tm_mon+1,tm.tm_mday,TM_YEAR(tm.tm_year)
,tm.tm_hour,tm.tm_min);
......@@ -351,7 +420,7 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
ch=' '; /* public, unread */ }
sprintf(str,"%c%-7lu%-13.13s%-25.25s"
safe_snprintf(str,sizeof(str),"%c%-7lu%-13.13s%-25.25s"
"%-25.25s%-25.25s%12s%-8lu%-6lu\xe1%c%c%c%c%c"
,ch /* message status flag */
,mode&QM_REP ? (ulong)conf /* conference or */
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -63,6 +63,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
post_t *post;
glob_t g;
FILE *stream,*qwk,*personal,*ndx;
FILE* hdrs=NULL;
DIR* dir;
DIRENT* dirent;
struct tm tm;
......@@ -73,7 +74,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
ex|=EX_OFFLINE;
delfiles(cfg.temp_dir,ALLFILES);
sprintf(str,"%sfile/%04u.qwk",cfg.data_dir,useron.number);
SAFEPRINTF2(str,"%sfile/%04u.qwk",cfg.data_dir,useron.number);
if(fexistcase(str)) {
for(k=0;k<cfg.total_fextrs;k++)
if(!stricmp(cfg.fextr[k]->ext,useron.tmpext)
......@@ -108,7 +109,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
/***************************/
/* Create CONTROL.DAT file */
/***************************/
sprintf(str,"%sCONTROL.DAT",cfg.temp_dir);
SAFEPRINTF(str,"%sCONTROL.DAT",cfg.temp_dir);
if((stream=fopen(str,"wb"))==NULL) {
errormsg(WHERE,ERR_OPEN,str,0);
return(false);
......@@ -137,11 +138,11 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
for(i=0;i<usrgrps;i++)
for(j=0;j<usrsubs[i];j++) {
if(useron.qwk&QWK_EXT) /* 255 char max */
sprintf(confname,"%s %s"
SAFEPRINTF2(confname,"%s %s"
,cfg.grp[cfg.sub[usrsub[i][j]]->grp]->sname
,cfg.sub[usrsub[i][j]]->lname);
else /* 10 char max */
strcpy(confname,cfg.sub[usrsub[i][j]]->qwkname);
SAFECOPY(confname,cfg.sub[usrsub[i][j]]->qwkname);
fprintf(stream,"%u\r\n%s\r\n"
,cfg.sub[usrsub[i][j]]->qwkconf ? cfg.sub[usrsub[i][j]]->qwkconf
: ((i+1)*1000)+j+1,confname);
......@@ -151,7 +152,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
/***********************/
/* Create DOOR.ID File */
/***********************/
sprintf(str,"%sDOOR.ID",cfg.temp_dir);
SAFEPRINTF(str,"%sDOOR.ID",cfg.temp_dir);
if((stream=fopen(str,"wb"))==NULL) {
errormsg(WHERE,ERR_OPEN,str,0);
return(false);
......@@ -190,7 +191,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
/***********************/
/* Create NETFLAGS.DAT */
/***********************/
sprintf(str,"%sNETFLAGS.DAT",cfg.temp_dir);
SAFEPRINTF(str,"%sNETFLAGS.DAT",cfg.temp_dir);
if((stream=fopen(str,"wb"))==NULL) {
errormsg(WHERE,ERR_CREATE,str,0);
return(false);
......@@ -206,7 +207,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
/****************************************************/
/* Create MESSAGES.DAT, write header and leave open */
/****************************************************/
sprintf(str,"%sMESSAGES.DAT",cfg.temp_dir);
SAFEPRINTF(str,"%sMESSAGES.DAT",cfg.temp_dir);
if(fexistcase(str))
fmode="r+b";
else
......@@ -215,6 +216,14 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
errormsg(WHERE,ERR_OPEN,str,0);
return(false);
}
if(useron.qwk&QWK_HEADERS) {
SAFEPRINTF(str,"%sHEADERS.DAT",cfg.temp_dir);
if((hdrs=fopen(str,"a"))==NULL) {
fclose(qwk);
errormsg(WHERE,ERR_OPEN,str,0);
return(false);
}
}
l=filelength(fileno(qwk));
if(l<1) {
fprintf(qwk,"%-128.128s","Produced by " VERSION_NOTICE " " COPYRIGHT_NOTICE);
......@@ -223,7 +232,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
msgndx=l/QWK_BLOCK_LEN;
fseek(qwk,0,SEEK_END);
}
sprintf(str,"%sNEWFILES.DAT",cfg.temp_dir);
SAFEPRINTF(str,"%sNEWFILES.DAT",cfg.temp_dir);
remove(str);
if(!(useron.rest&FLAG('T')) && useron.qwk&QWK_FILES)
files=create_filelist("NEWFILES.DAT",FL_ULTIME);
......@@ -236,9 +245,11 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
useron.qwk|=(QWK_EMAIL|QWK_ALLMAIL|QWK_DELMAIL);
if(!(useron.qwk&QWK_NOINDEX)) {
sprintf(str,"%sPERSONAL.NDX",cfg.temp_dir);
SAFEPRINTF(str,"%sPERSONAL.NDX",cfg.temp_dir);
if((personal=fopen(str,"ab"))==NULL) {
fclose(qwk);
if(hdrs!=NULL)
fclose(hdrs);
errormsg(WHERE,ERR_OPEN,str,0);
return(false);
}
......@@ -247,11 +258,13 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
personal=NULL;
if(useron.qwk&(QWK_EMAIL|QWK_ALLMAIL) /* && !prepack */) {
sprintf(smb.file,"%smail",cfg.data_dir);
SAFEPRINTF(smb.file,"%smail",cfg.data_dir);
smb.retry_time=cfg.smb_retry_time;
smb.subnum=INVALID_SUB;
if((i=smb_open(&smb))!=0) {
fclose(qwk);
if(hdrs!=NULL)
fclose(hdrs);
if(personal)
fclose(personal);
errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
......@@ -267,9 +280,11 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
if(mailmsgs && !(sys_status&SS_ABORT)) {
bputs(text[QWKPackingEmail]);
if(!(useron.qwk&QWK_NOINDEX)) {
sprintf(str,"%s000.NDX",cfg.temp_dir);
SAFEPRINTF(str,"%s000.NDX",cfg.temp_dir);
if((ndx=fopen(str,"ab"))==NULL) {
fclose(qwk);
if(hdrs!=NULL)
fclose(hdrs);
if(personal)
fclose(personal);
smb_close(&smb);
......@@ -298,14 +313,14 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
continue;
if(msg.hdr.auxattr&MSG_FILEATTACH && useron.qwk&QWK_ATTACH) {
sprintf(str,"%sfile/%04u.in/%s"
SAFEPRINTF3(str,"%sfile/%04u.in/%s"
,cfg.data_dir,useron.number,msg.subj);
sprintf(tmp,"%s%s",cfg.temp_dir,msg.subj);
SAFEPRINTF2(tmp,"%s%s",cfg.temp_dir,msg.subj);
if(fexistcase(str) && !fexistcase(tmp))
mv(str,tmp,1);
}
size=msgtoqwk(&msg,qwk,mode,INVALID_SUB,0);
size=msgtoqwk(&msg,qwk,mode,INVALID_SUB,0,hdrs);
smb_unlockmsghdr(&smb,&msg);
smb_freemsgmem(&msg);
if(ndx) {
......@@ -359,7 +374,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
continue;
}
sprintf(smb.file,"%s%s"
SAFEPRINTF2(smb.file,"%s%s"
,cfg.sub[usrsub[i][j]]->data_dir,cfg.sub[usrsub[i][j]]->code);
smb.retry_time=cfg.smb_retry_time;
smb.subnum=usrsub[i][j];
......@@ -389,9 +404,11 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
conf=((i+1)*1000)+j+1;
if(!(useron.qwk&QWK_NOINDEX)) {
sprintf(str,"%s%u.NDX",cfg.temp_dir,conf);
SAFEPRINTF2(str,"%s%u.NDX",cfg.temp_dir,conf);
if((ndx=fopen(str,"ab"))==NULL) {
fclose(qwk);
if(hdrs!=NULL)
fclose(hdrs);
if(personal)
fclose(personal);
smb_close(&smb);
......@@ -435,7 +452,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
else
mode&=~(QM_TAGLINE|QM_TO_QNET);
size=msgtoqwk(&msg,qwk,mode,usrsub[i][j],conf);
size=msgtoqwk(&msg,qwk,mode,usrsub[i][j],conf,hdrs);
smb_unlockmsghdr(&smb,&msg);
if(ndx) {
......@@ -468,7 +485,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
bprintf(text[QWKPackedSubboard],submsgs,(*msgcnt));
if(ndx) {
fclose(ndx);
sprintf(str,"%s%u.NDX",cfg.temp_dir,conf);
SAFEPRINTF2(str,"%s%u.NDX",cfg.temp_dir,conf);
if(!flength(str))
remove(str);
}
......@@ -497,7 +514,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
,ftell(qwk)
,time(NULL)-start
,((*msgcnt)+mailmsgs)/(time(NULL)-start));
sprintf(str,"Packed %lu messages (%lu bytes) in %lu seconds (%lu msgs/sec)"
SAFEPRINTF4(str,"Packed %lu messages (%lu bytes) in %lu seconds (%lu msgs/sec)"
,(*msgcnt)+mailmsgs
,ftell(qwk)
,(ulong)(time(NULL)-start)
......@@ -509,9 +526,11 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
}
fclose(qwk); /* close MESSAGE.DAT */
if(hdrs!=NULL)
fclose(hdrs); /* close HEADERS.DAT */
if(personal) {
fclose(personal); /* close PERSONAL.NDX */
sprintf(str,"%sPERSONAL.NDX",cfg.temp_dir);
SAFEPRINTF(str,"%sPERSONAL.NDX",cfg.temp_dir);
if(!flength(str))
remove(str);
}
......@@ -521,13 +540,13 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
return(false);
if(/*!prepack && */ useron.rest&FLAG('Q')) { /* If QWK Net node, check for files */
sprintf(str,"%sqnet/%s.out/",cfg.data_dir,useron.alias);
SAFEPRINTF2(str,"%sqnet/%s.out/",cfg.data_dir,useron.alias);
dir=opendir(str);
while(dir!=NULL && (dirent=readdir(dir))!=NULL) { /* Move files into temp dir */
sprintf(str,"%sqnet/%s.out/%s",cfg.data_dir,useron.alias,dirent->d_name);
SAFEPRINTF3(str,"%sqnet/%s.out/%s",cfg.data_dir,useron.alias,dirent->d_name);