Commit e7b45919 authored by rswindell's avatar rswindell
Browse files

Use smb_storage_mode() rather than the copy/pasted storage method determination

logic everywhere.
Enforce the sys_misc SM_DELREADM flag (SCFG->Message Options->Kill Read E-mail)
in more places (set the Kill After Read flag automatically).
Create a Message-ID (RFC822-style) for locally created email messages.
parent 8613125a
......@@ -205,7 +205,7 @@ int sbbs_t::bulkmailhdr(smb_t* smb, smbmsg_t* msg, uint usernum)
smb_hfield_str(&newmsg,RECIPIENTEXT,str);
}
j=smb_addmsghdr(smb,&newmsg,SMB_SELFPACK);
j=smb_addmsghdr(smb,&newmsg,smb_storage_mode(&cfg, smb));
smb_freemsgmem(&newmsg);
if(j!=SMB_SUCCESS)
return(j);
......
......@@ -49,6 +49,7 @@ bool sbbs_t::email(int usernumber, const char *top, const char *subj, long mode)
,buf[SDT_BLOCK_LEN];
char tmp[512];
char pid[128];
char msg_id[128];
char* editor=NULL;
uint16_t msgattr=0;
uint16_t xlat=XLAT_NONE;
......@@ -316,12 +317,14 @@ bool sbbs_t::email(int usernumber, const char *top, const char *subj, long mode)
/* Generate FidoNet Program Identifier */
smb_hfield_str(&msg,FIDOPID,msg_program_id(pid));
smb_hfield_str(&msg, RFC822MSGID, get_msgid(&cfg, INVALID_SUB, &msg, msg_id, sizeof(msg_id)));
if(editor!=NULL)
smb_hfield_str(&msg,SMB_EDITOR,editor);
smb_dfield(&msg,TEXT_BODY,length);
i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); // calls smb_unlocksmbhdr()
i=smb_addmsghdr(&smb,&msg,smb_storage_mode(&cfg, &smb)); // calls smb_unlocksmbhdr()
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
......
......@@ -2304,7 +2304,7 @@ js_save_msg(JSContext *cx, uintN argc, jsval *arglist)
break;
rc=JS_SUSPENDREQUEST(cx);
if((p->status=smb_addmsghdr(&(p->smb), &rcpt_msg, SMB_SELFPACK))!=SMB_SUCCESS) {
if((p->status=smb_addmsghdr(&(p->smb), &rcpt_msg, smb_storage_mode(scfg, &(p->smb))))!=SMB_SUCCESS) {
JS_RESUMEREQUEST(cx, rc);
break;
}
......
......@@ -3099,8 +3099,10 @@ static void smtp_thread(void* arg)
if(dnsbl_recvhdr) /* DNSBL-listed IP found in Received header? */
dnsbl_result.s_addr=0; /* Reset DNSBL look-up result between messages */
if((startup->options&MAIL_OPT_KILL_READ_SPAM) && (msg.hdr.attr&MSG_SPAM))
if((scfg.sys_misc&SM_DELREADM)
|| ((startup->options&MAIL_OPT_KILL_READ_SPAM) && (msg.hdr.attr&MSG_SPAM)))
msg.hdr.attr |= MSG_KILLREAD;
if(sender[0]==0) {
lprintf(LOG_WARNING,"%04d !SMTP MISSING mail header 'FROM' field (%u total)"
,socket, ++stats.msgs_refused);
......@@ -3340,7 +3342,7 @@ static void smtp_thread(void* arg)
if(agent!=newmsg.to_agent)
smb_hfield(&newmsg, RECIPIENTAGENT, sizeof(agent), &agent);
i=smb_addmsghdr(&smb,&newmsg,SMB_SELFPACK);
i=smb_addmsghdr(&smb,&newmsg,smb_storage_mode(&scfg, &smb));
smb_freemsgmem(&newmsg);
if(i!=SMB_SUCCESS) {
lprintf(LOG_ERR,"%04d !SMTP ERROR %d (%s) adding message header"
......@@ -4429,6 +4431,10 @@ BOOL bounce(SOCKET sock, smb_t* smb, smbmsg_t* msg, char* err, BOOL immediate)
smb_hfield(&newmsg, RECIPIENTAGENT, sizeof(msg->from_agent), &msg->from_agent);
}
newmsg.hdr.attr|=MSG_NOREPLY;
newmsg.hdr.attr&=~MSG_READ;
if(scfg.sys_misc&SM_DELREADM)
newmsg.hdr.attr |= MSG_KILLREAD;
strcpy(str,"Mail Delivery Subsystem");
smb_hfield_str(&newmsg, SENDER, str);
smb_hfield(&newmsg, SENDERAGENT, sizeof(agent), &agent);
......@@ -4451,7 +4457,7 @@ BOOL bounce(SOCKET sock, smb_t* smb, smbmsg_t* msg, char* err, BOOL immediate)
smb_hfield_str(&newmsg, SMB_COMMENT, err);
smb_hfield_str(&newmsg, SMB_COMMENT, "\r\nOriginal message text follows:");
if((i=smb_addmsghdr(smb,&newmsg,SMB_SELFPACK))!=SMB_SUCCESS)
if((i=smb_addmsghdr(smb,&newmsg,smb_storage_mode(&scfg, smb)))!=SMB_SUCCESS)
lprintf(LOG_ERR,"%04d !BOUNCE ERROR %d (%s) adding message header"
,sock,i,smb->last_error);
else {
......
......@@ -267,7 +267,7 @@ bool sbbs_t::inetmail(const char *into, const char *subj, long mode)
smb_dfield(&msg,TEXT_BODY,length);
i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); // calls smb_unlocksmbhdr()
i=smb_addmsghdr(&smb,&msg,smb_storage_mode(&cfg, &smb)); // calls smb_unlocksmbhdr()
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
......@@ -474,7 +474,7 @@ bool sbbs_t::qnetmail(const char *into, const char *subj, long mode)
smb_dfield(&msg,TEXT_BODY,length);
i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); // calls smb_unlocksmbhdr()
i=smb_addmsghdr(&smb,&msg,smb_storage_mode(&cfg, &smb)); // calls smb_unlocksmbhdr()
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
......
......@@ -59,7 +59,6 @@ int msgbase_open(scfg_t* cfg, smb_t* smb, int* storage, long* dupechk_hashes, ui
{
int i;
*storage=SMB_SELFPACK;
*dupechk_hashes=SMB_HASH_SOURCE_DUPE;
*xlat=XLAT_NONE;
......@@ -70,8 +69,6 @@ int msgbase_open(scfg_t* cfg, smb_t* smb, int* storage, long* dupechk_hashes, ui
smb->status.max_age=cfg->mail_maxage;
smb->status.max_msgs=0; /* unlimited */
smb->status.attr=SMB_EMAIL;
if(cfg->sys_misc&SM_FASTMAIL)
*storage = SMB_FASTALLOC;
/* duplicate message-IDs must be allowed in mail database */
*dupechk_hashes&=~(1<<SMB_HASH_SOURCE_MSG_ID);
} else {
......@@ -80,11 +77,6 @@ int msgbase_open(scfg_t* cfg, smb_t* smb, int* storage, long* dupechk_hashes, ui
smb->status.max_msgs=cfg->sub[smb->subnum]->maxmsgs;
smb->status.max_age=cfg->sub[smb->subnum]->maxage;
smb->status.attr=0;
if(cfg->sub[smb->subnum]->misc&SUB_HYPER)
*storage = smb->status.attr = SMB_HYPERALLOC;
else if(cfg->sub[smb->subnum]->misc&SUB_FAST)
*storage = SMB_FASTALLOC;
if(cfg->sub[smb->subnum]->misc&SUB_LZH)
*xlat=XLAT_LZH;
}
......@@ -97,6 +89,8 @@ int msgbase_open(scfg_t* cfg, smb_t* smb, int* storage, long* dupechk_hashes, ui
if(filelength(fileno(smb->shd_fp)) < 1) /* MsgBase doesn't exist yet, create it */
i=smb_create(smb);
*storage=smb_storage_mode(cfg, smb);
return i;
}
......@@ -420,13 +414,13 @@ extern "C" int DLLCALL msg_client_hfields(smbmsg_t* msg, client_t* client)
return smb_hfield_str(msg,SENDERPORT,port);
}
/* Note: support MSG_BODY only, no tails or other data fields (dfields) */
extern "C" int DLLCALL savemsg(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, client_t* client, const char* server, char* msgbuf)
{
char pid[128];
char msg_id[256];
ushort xlat=XLAT_NONE;
int i;
int storage=SMB_SELFPACK;
long dupechk_hashes=SMB_HASH_SOURCE_DUPE;
if(msg==NULL)
......@@ -454,29 +448,11 @@ extern "C" int DLLCALL savemsg(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, client_t*
if(smb->subnum==INVALID_SUB) { /* e-mail */
/* exception here during recycle:
sbbs.dll!savemsg(scfg_t * cfg, smb_t * smb, smbmsg_t * msg, client_t * client, char * msgbuf) Line 473 + 0xf bytes C++
sbbs.dll!js_save_msg(JSContext * cx, JSObject * obj, unsigned int argc, long * argv, long * rval) Line 1519 + 0x25 bytes C
js32.dll!js_Invoke(JSContext * cx, unsigned int argc, unsigned int flags) Line 1375 + 0x17 bytes C
js32.dll!js_Interpret(JSContext * cx, unsigned char * pc, long * result) Line 3944 + 0xf bytes C
js32.dll!js_Execute(JSContext * cx, JSObject * chain, JSObject * script, JSStackFrame * down, unsigned int flags, long * result) Line 1633 + 0x13 bytes C
js32.dll!JS_ExecuteScript(JSContext * cx, JSObject * obj, JSObject * script, long * rval) Line 4188 + 0x19 bytes C
sbbs.dll!sbbs_t::js_execfile(const char * cmd, const char * startup_dir) Line 686 + 0x27 bytes C++
sbbs.dll!sbbs_t::external(const char * cmdline, long mode, const char * startup_dir) Line 413 + 0x1e bytes C++
sbbs.dll!event_thread(void * arg) Line 2745 + 0x71 bytes C++
apparently the event_thread is sharing an scfg_t* with another thread! */
smb->status.max_crcs=cfg->mail_maxcrcs;
smb->status.max_age=cfg->mail_maxage;
smb->status.max_msgs=0; /* unlimited */
smb->status.attr=SMB_EMAIL;
if(cfg->sys_misc&SM_FASTMAIL)
storage=SMB_FASTALLOC;
/* duplicate message-IDs must be allowed in mail database */
dupechk_hashes&=~(1<<SMB_HASH_SOURCE_MSG_ID);
......@@ -487,11 +463,6 @@ extern "C" int DLLCALL savemsg(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, client_t*
smb->status.max_age=cfg->sub[smb->subnum]->maxage;
smb->status.attr=0;
if(cfg->sub[smb->subnum]->misc&SUB_HYPER)
storage = smb->status.attr = SMB_HYPERALLOC;
else if(cfg->sub[smb->subnum]->misc&SUB_FAST)
storage = SMB_FASTALLOC;
if(cfg->sub[smb->subnum]->misc&SUB_LZH)
xlat=XLAT_LZH;
......@@ -536,7 +507,7 @@ extern "C" int DLLCALL savemsg(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, client_t*
if(msg->ftn_pid==NULL)
smb_hfield_str(msg,FIDOPID,msg_program_id(pid));
if((i=smb_addmsg(smb,msg,storage,dupechk_hashes,xlat,(uchar*)msgbuf,NULL))==SMB_SUCCESS
if((i=smb_addmsg(smb,msg,smb_storage_mode(cfg, smb),dupechk_hashes,xlat,(uchar*)msgbuf, /* tail: */NULL))==SMB_SUCCESS
&& msg->to!=NULL /* no recipient means no header created at this stage */) {
if(smb->subnum == INVALID_SUB) {
if(msg->to_net.type == NET_FIDO)
......
......@@ -222,7 +222,6 @@ bool sbbs_t::qwk_import_msg(FILE *qwk_fp, char *hdrblk, ulong blocks
bool success=false;
uint16_t net_type;
ushort xlat=XLAT_NONE;
int storage=SMB_SELFPACK;
long dupechk_hashes=SMB_HASH_SOURCE_DUPE;
str_list_t kludges;
......@@ -255,8 +254,6 @@ bool sbbs_t::qwk_import_msg(FILE *qwk_fp, char *hdrblk, ulong blocks
msg->hdr.thread_back=atol((char *)hdrblk+108);
if(subnum==INVALID_SUB) { /* E-mail */
if(cfg.sys_misc&SM_FASTMAIL)
storage=SMB_FASTALLOC;
/* duplicate message-IDs must be allowed in mail database */
dupechk_hashes&=~(1<<SMB_HASH_SOURCE_MSG_ID);
......@@ -264,10 +261,6 @@ bool sbbs_t::qwk_import_msg(FILE *qwk_fp, char *hdrblk, ulong blocks
sprintf(str,"%u",touser);
smb_hfield_str(msg,RECIPIENTEXT,str);
} else {
if(cfg.sub[subnum]->misc&SUB_HYPER)
storage = SMB_HYPERALLOC;
else if(cfg.sub[subnum]->misc&SUB_FAST)
storage = SMB_FASTALLOC;
if(cfg.sub[subnum]->misc&SUB_LZH)
xlat=XLAT_LZH;
......@@ -462,7 +455,7 @@ bool sbbs_t::qwk_import_msg(FILE *qwk_fp, char *hdrblk, ulong blocks
if(smb.status.max_crcs==0) /* no CRC checking means no body text dupe checking */
dupechk_hashes&=~(1<<SMB_HASH_SOURCE_BODY);
if((i=smb_addmsg(&smb,msg,storage,dupechk_hashes,xlat,(uchar*)body,(uchar*)tail))==SMB_SUCCESS)
if((i=smb_addmsg(&smb,msg,smb_storage_mode(&cfg, &smb),dupechk_hashes,xlat,(uchar*)body,(uchar*)tail))==SMB_SUCCESS)
success=true;
else if(i==SMB_DUPE_MSG) {
bprintf("\r\n!%s\r\n",smb.last_error);
......
......@@ -1207,7 +1207,7 @@ void sbbs_t::forwardmail(smbmsg_t *msg, int usernumber)
smb_close_da(&smb);
if((i=smb_addmsghdr(&smb,msg,SMB_SELFPACK))!=SMB_SUCCESS) {
if((i=smb_addmsghdr(&smb,msg,smb_storage_mode(&cfg, &smb)))!=SMB_SUCCESS) {
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
smb_freemsg_dfields(&smb,msg,1);
return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment