...
 
Commits (1)
  • Rob Swindell's avatar
    Better error detection in msgtoqwk() · 2849731e
    Rob Swindell authored
    Have msgtoqwk() return a negative number upon error (e.g. blank message, failed to read to body text), which means *no* message header was written to the messages.dat file, so don't increment the record (block) counter used to create the index (NDX) file.
    
    If msgtoqwk() returns 0, that means that a header was written, but no body text (e.g. a vote message) and that is different than an error.
    2849731e
......@@ -44,8 +44,9 @@
/* Converts message 'msg' to QWK format, writing to file 'qwk_fp'. */
/* mode determines how to handle Ctrl-A codes */
/* Returns the number of bytes used for the body-text (multiple of 128) */
/* or negative on error. */
/****************************************************************************/
ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, smb_t* smb
long sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, smb_t* smb
, int conf, FILE* hdrs, FILE* voting)
{
char str[512],ch=0,tear=0,tearwatch=0,*buf,*p;
......@@ -75,7 +76,7 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, smb_t* smb
if(msg->hdr.type != SMB_MSG_TYPE_NORMAL) {
if(voting == NULL)
return 0;
return -1;
fprintf(voting,"[%lx]\n",offset);
switch(msg->hdr.type) {
case SMB_MSG_TYPE_BALLOT:
......@@ -257,7 +258,7 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, smb_t* smb
getmsgtxt_mode |= GETMSGTXT_PLAIN;
buf=smb_getmsgtxt(smb, msg, getmsgtxt_mode);
if(!buf)
return(0);
return -2;
char qwk_newline = QWK_NEWLINE;
if(smb_msg_is_utf8(msg) || (msg->hdr.auxattr & MSG_HFIELDS_UTF8)) {
......
......@@ -389,18 +389,20 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
size=msgtoqwk(&msg, qwk, mode|QM_REPLYTO, &smb, /* confnum: */0, hdrs);
smb_unlockmsghdr(&smb,&msg);
smb_freemsgmem(&msg);
msgndx++;
if(ndx && size) {
f=ltomsbin(msgndx); /* Record number */
ch=0; /* Sub number, not used */
if(personal) {
fwrite(&f,4,1,personal);
fwrite(&ch,1,1,personal);
if(size >= 0) {
msgndx++;
if(ndx && size > 0) {
f=ltomsbin(msgndx); /* Record number */
ch=0; /* Sub number, not used */
if(personal) {
fwrite(&f,4,1,personal);
fwrite(&ch,1,1,personal);
}
fwrite(&f,4,1,ndx);
fwrite(&ch,1,1,ndx);
msgndx+=size/QWK_BLOCK_LEN;
}
fwrite(&f,4,1,ndx);
fwrite(&ch,1,1,ndx);
msgndx+=size/QWK_BLOCK_LEN;
}
}
YIELD(); /* yield */
}
if(online == ON_REMOTE)
......@@ -528,24 +530,24 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
size=msgtoqwk(&msg, qwk, mode, &smb, conf, hdrs, voting);
smb_unlockmsghdr(&smb,&msg);
msgndx++;
if(ndx && size) {
f=ltomsbin(msgndx); /* Record number */
ch=0; /* Sub number, not used */
if(personal
&& (!stricmp(msg.to,useron.alias)
|| !stricmp(msg.to,useron.name))) {
fwrite(&f,4,1,personal);
fwrite(&ch,1,1,personal);
if(size >= 0) {
msgndx++;
if(ndx && size > 0) {
f=ltomsbin(msgndx); /* Record number */
ch=0; /* Sub number, not used */
if(personal
&& (!stricmp(msg.to,useron.alias)
|| !stricmp(msg.to,useron.name))) {
fwrite(&f,4,1,personal);
fwrite(&ch,1,1,personal);
}
fwrite(&f,4,1,ndx);
fwrite(&ch,1,1,ndx);
msgndx+=size/QWK_BLOCK_LEN;
}
fwrite(&f,4,1,ndx);
fwrite(&ch,1,1,ndx);
msgndx+=size/QWK_BLOCK_LEN;
}
smb_freemsgmem(&msg);
if(size) {
if(size > 0) {
(*msgcnt)++;
submsgs++;
}
......
......@@ -152,8 +152,8 @@ bool sbbs_t::pack_rep(uint hubnum)
mode |= (cfg.qhub[hubnum]->misc&(QHUB_EXT | QHUB_CTRL_A | QHUB_UTF8));
/* For an unclear reason, kludge lines (including @VIA and @TZ) were not included in NetMail previously */
if(!(cfg.qhub[hubnum]->misc&QHUB_NOHEADERS)) mode|=(QM_VIA|QM_TZ|QM_MSGID|QM_REPLYTO);
msgtoqwk(&msg, rep, mode, &smb, /* confnum: */0, hdrs);
packedmail++;
if(msgtoqwk(&msg, rep, mode, &smb, /* confnum: */0, hdrs) > 0)
packedmail++;
smb_unlockmsghdr(&smb,&msg);
smb_freemsgmem(&msg);
YIELD(); /* yield */
......@@ -228,12 +228,13 @@ bool sbbs_t::pack_rep(uint hubnum)
if(msg.from_net.type!=NET_QWK)
mode|=QM_TAGLINE;
msgtoqwk(&msg, rep, mode, &smb, cfg.qhub[hubnum]->conf[i], hdrs, voting);
if(msgtoqwk(&msg, rep, mode, &smb, cfg.qhub[hubnum]->conf[i], hdrs, voting) > 0) {
msgcnt++;
submsgs++;
}
smb_freemsgmem(&msg);
smb_unlockmsghdr(&smb,&msg);
msgcnt++;
submsgs++;
if(!(u%50))
YIELD(); /* yield */
}
......
......@@ -1081,7 +1081,7 @@ public:
bool unpack_rep(char* repfile=NULL);
/* msgtoqwk.cpp */
ulong msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, smb_t*, int conf, FILE* hdrs_dat, FILE* voting_dat = NULL);
long msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, smb_t*, int conf, FILE* hdrs_dat, FILE* voting_dat = NULL);
/* qwktomsg.cpp */
bool qwk_new_msg(ulong confnum, smbmsg_t* msg, char* hdrblk, long offset, str_list_t headers, bool parse_sender_hfields);
......