Commit 997f9e04 authored by rswindell's avatar rswindell
Browse files

Delete read-mail when it has the MSG_KILLREAD attribute flag set.

parent 037478f9
......@@ -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 2003 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2009 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 *
......@@ -50,53 +50,61 @@ int sbbs_t::delmail(uint usernumber, int which)
now=time(NULL);
if((i=smb_getstatus(&smb))!=0) {
errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
return(2); }
return(2);
}
if(!smb.status.total_msgs)
return(0);
if((idxbuf=(idxrec_t *)malloc(smb.status.total_msgs*sizeof(idxrec_t)))==NULL) {
errormsg(WHERE,ERR_ALLOC,smb.file,smb.status.total_msgs*sizeof(idxrec_t));
return(-1); }
return(-1);
}
if((i=smb_open_da(&smb))!=0) {
errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
free(idxbuf);
return(i); }
return(i);
}
if((i=smb_open_ha(&smb))!=0) {
smb_close_da(&smb);
errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
free(idxbuf);
return(i); }
return(i);
}
smb_rewind(smb.sid_fp);
for(l=0;l<smb.status.total_msgs;) {
if(smb_fread(&smb,&msg.idx,sizeof(idxrec_t),smb.sid_fp)!=sizeof(idxrec_t))
break;
if(which==MAIL_ALL && !(msg.idx.attr&MSG_PERMANENT)
&& smb.status.max_age && now>msg.idx.time
&& (now-msg.idx.time)/(24L*60L*60L)>smb.status.max_age)
msg.idx.attr|=MSG_DELETE;
if(msg.idx.attr&MSG_DELETE && !(msg.idx.attr&MSG_PERMANENT)
if(!(msg.idx.attr&MSG_PERMANENT)
&& ((which==MAIL_SENT && usernumber==msg.idx.from)
|| (which==MAIL_YOUR && usernumber==msg.idx.to)
|| (which==MAIL_ANY
&& (usernumber==msg.idx.to || usernumber==msg.idx.from))
|| which==MAIL_ALL)) {
/* Don't need to lock message because base is locked */
// if(which==MAIL_ALL && !online)
// lprintf(" #%lu",msg.idx.number);
if((i=smb_getmsghdr(&smb,&msg))!=0)
errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
else {
if(msg.hdr.attr!=msg.idx.attr) {
msg.hdr.attr=msg.idx.attr;
if((i=smb_putmsghdr(&smb,&msg))!=0)
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); }
if((i=smb_freemsg(&smb,&msg))!=0)
errormsg(WHERE,ERR_REMOVE,smb.file,i,smb.last_error);
if(msg.hdr.auxattr&MSG_FILEATTACH)
delfattach(&cfg,&msg);
smb_freemsgmem(&msg); }
continue; }
|| (which==MAIL_YOUR && usernumber==msg.idx.to)
|| (which==MAIL_ANY && (usernumber==msg.idx.to || usernumber==msg.idx.from))
|| which==MAIL_ALL)) {
if(smb.status.max_age && now>msg.idx.time
&& (now-msg.idx.time)/(24L*60L*60L)>smb.status.max_age)
msg.idx.attr|=MSG_DELETE;
else if(msg.idx.attr&MSG_KILLREAD && msg.idx.attr&MSG_READ)
msg.idx.attr|=MSG_DELETE;
if(msg.idx.attr&MSG_DELETE) {
/* Don't need to lock message because base is locked */
if((i=smb_getmsghdr(&smb,&msg))!=0)
errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
else {
if(msg.hdr.attr!=msg.idx.attr) {
msg.hdr.attr=msg.idx.attr;
if((i=smb_putmsghdr(&smb,&msg))!=0)
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
}
if((i=smb_freemsg(&smb,&msg))!=0)
errormsg(WHERE,ERR_REMOVE,smb.file,i,smb.last_error);
if(msg.hdr.auxattr&MSG_FILEATTACH)
delfattach(&cfg,&msg);
smb_freemsgmem(&msg);
}
continue;
}
}
idxbuf[l]=msg.idx;
l++; }
l++;
}
smb_rewind(smb.sid_fp);
smb_fsetlength(smb.sid_fp,0);
for(i=0;i<l;i++)
......@@ -127,7 +135,8 @@ void sbbs_t::telluser(smbmsg_t* msg)
else {
usernumber=matchuser(&cfg,msg->from,TRUE /*sysop_alias*/);
if(!usernumber)
return; }
return;
}
for(n=1;n<=cfg.sys_nodes;n++) { /* Tell user */
getnodedat(n,&node,0);
if(node.useron==usernumber
......@@ -137,12 +146,15 @@ void sbbs_t::telluser(smbmsg_t* msg)
,text[UserReadYourMailNodeMsg]
,cfg.node_num,useron.alias);
putnmsg(&cfg,n,str);
break; } }
break;
}
}
if(n>cfg.sys_nodes) {
now=time(NULL);
sprintf(str,text[UserReadYourMail]
,useron.alias,timestr(now));
putsmsg(&cfg,usernumber,str); }
putsmsg(&cfg,usernumber,str);
}
}
/************************************************************************/
......@@ -158,26 +170,30 @@ void sbbs_t::delallmail(uint usernumber)
if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) {
errormsg(WHERE,ERR_OPEN,"MAIL",i);
return; }
return;
}
sprintf(smb.file,"%smail",cfg.data_dir);
smb.retry_time=cfg.smb_retry_time;
smb.subnum=INVALID_SUB;
if((i=smb_open(&smb))!=0) {
errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
smb_stack(&smb,SMB_STACK_POP);
return; }
return;
}
mail=loadmail(&smb,&msgs,usernumber,MAIL_ANY,0);
if(!msgs) {
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
return; }
return;
}
if((i=smb_locksmbhdr(&smb))!=0) { /* Lock the base, so nobody */
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
free(mail);
errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error); /* messes with the index */
return; }
return;
}
for(l=0;l<msgs;l++) {
msg.idx.offset=0; /* search by number */
if(loadmsg(&msg,mail[l].number)) { /* message still there */
......@@ -189,7 +205,9 @@ void sbbs_t::delallmail(uint usernumber)
else
deleted++;
smb_freemsgmem(&msg);
smb_unlockmsghdr(&smb,&msg); } }
smb_unlockmsghdr(&smb,&msg);
}
}
if(msgs)
free(mail);
......
......@@ -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 2008 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2009 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 *
......@@ -311,6 +311,8 @@ void sbbs_t::readmail(uint usernumber, int which)
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
msg.hdr.attr|=MSG_READ;
if(msg.hdr.attr&MSG_KILLREAD)
msg.hdr.attr|=MSG_DELETE;
msg.idx.attr=msg.hdr.attr;
if((i=smb_putmsg(&smb,&msg))!=0)
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
......
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