Annotation of sbbs/src/sbbs3/mail.cpp, revision 1.1.1.2

1.1       root        1: /* mail.cpp */
                      2: 
                      3: /* Synchronet mail-related routines */
                      4: 
1.1.1.2 ! root        5: /* $Id: mail.cpp,v 1.24 2010/03/10 08:04:20 rswindell Exp $ */
1.1       root        6: 
                      7: /****************************************************************************
                      8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                     10:  *                                                                                                                                                     *
1.1.1.2 ! root       11:  * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       12:  *                                                                                                                                                     *
                     13:  * This program is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU General Public License                         *
                     15:  * as published by the Free Software Foundation; either version 2                      *
                     16:  * of the License, or (at your option) any later version.                                      *
                     17:  * See the GNU General Public License for more details: gpl.txt or                     *
                     18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
                     19:  *                                                                                                                                                     *
                     20:  * Anonymous FTP access to the most recent released source is available at     *
                     21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     22:  *                                                                                                                                                     *
                     23:  * Anonymous CVS access to the development source and modification history     *
                     24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     26:  *     (just hit return, no password is necessary)                                                     *
                     27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     28:  *                                                                                                                                                     *
                     29:  * For Synchronet coding style and modification guidelines, see                                *
                     30:  * http://www.synchro.net/source.html                                                                          *
                     31:  *                                                                                                                                                     *
                     32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     33:  * format) via e-mail to [email protected]                                                                      *
                     34:  *                                                                                                                                                     *
                     35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     36:  ****************************************************************************/
                     37: 
                     38: #include "sbbs.h"
                     39: 
                     40: /****************************************************************************/
                     41: /* Deletes all mail messages for usernumber that have been marked 'deleted' */
                     42: /* smb_locksmbhdr() should be called prior to this function                            */
                     43: /****************************************************************************/
                     44: int sbbs_t::delmail(uint usernumber, int which)
                     45: {
                     46:        ulong    i,l,now;
                     47:        idxrec_t *idxbuf;
                     48:        smbmsg_t msg;
                     49: 
                     50:        now=time(NULL);
                     51:        if((i=smb_getstatus(&smb))!=0) {
                     52:                errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
1.1.1.2 ! root       53:                return(2)        !            54:        }
1.1       root       55:        if(!smb.status.total_msgs)
                     56:                return(0);
                     57:        if((idxbuf=(idxrec_t *)malloc(smb.status.total_msgs*sizeof(idxrec_t)))==NULL) {
                     58:                errormsg(WHERE,ERR_ALLOC,smb.file,smb.status.total_msgs*sizeof(idxrec_t));
1.1.1.2 ! root       59:                return(-1); 
        !            60:        }
1.1       root       61:        if((i=smb_open_da(&smb))!=0) {
                     62:                errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
                     63:                free(idxbuf);
1.1.1.2 ! root       64:                return(i); 
        !            65:        }
1.1       root       66:        if((i=smb_open_ha(&smb))!=0) {
                     67:                smb_close_da(&smb);
                     68:                errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
                     69:                free(idxbuf);
1.1.1.2 ! root       70:                return(i); 
        !            71:        }
1.1       root       72:        smb_rewind(smb.sid_fp);
                     73:        for(l=0;l<smb.status.total_msgs;) {
                     74:                if(smb_fread(&smb,&msg.idx,sizeof(idxrec_t),smb.sid_fp)!=sizeof(idxrec_t))
                     75:                        break;
1.1.1.2 ! root       76:                if(!(msg.idx.attr&MSG_PERMANENT)
1.1       root       77:                        && ((which==MAIL_SENT && usernumber==msg.idx.from)
1.1.1.2 ! root       78:                                || (which==MAIL_YOUR && usernumber==msg.idx.to)
        !            79:                                || (which==MAIL_ANY     && (usernumber==msg.idx.to || usernumber==msg.idx.from))
        !            80:                                || which==MAIL_ALL)) {
        !            81:                        if(smb.status.max_age && now>msg.idx.time
        !            82:                                && (now-msg.idx.time)/(24L*60L*60L)>smb.status.max_age)
        !            83:                                msg.idx.attr|=MSG_DELETE;
        !            84:                        else if(msg.idx.attr&MSG_KILLREAD && msg.idx.attr&MSG_READ)
        !            85:                                msg.idx.attr|=MSG_DELETE;
        !            86:                        if(msg.idx.attr&MSG_DELETE) {
        !            87:                                /* Don't need to lock message because base is locked */
        !            88:                                if((i=smb_getmsghdr(&smb,&msg))!=0)
        !            89:                                        errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
        !            90:                                else {
        !            91:                                        if(msg.hdr.attr!=msg.idx.attr) {
        !            92:                                                msg.hdr.attr=msg.idx.attr;
        !            93:                                                if((i=smb_putmsghdr(&smb,&msg))!=0)
        !            94:                                                        errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); 
        !            95:                                        }
        !            96:                                        if((i=smb_freemsg(&smb,&msg))!=0)
        !            97:                                                errormsg(WHERE,ERR_REMOVE,smb.file,i,smb.last_error);
        !            98:                                        if(msg.hdr.auxattr&MSG_FILEATTACH)
        !            99:                                                delfattach(&cfg,&msg);
        !           100:                                        smb_freemsgmem(&msg); 
        !           101:                                }
        !           102:                                continue; 
        !           103:                        }
        !           104:                }
1.1       root      105:                idxbuf[l]=msg.idx;
1.1.1.2 ! root      106:                l++; 
        !           107:        }
1.1       root      108:        smb_rewind(smb.sid_fp);
                    109:        smb_fsetlength(smb.sid_fp,0);
                    110:        for(i=0;i<l;i++)
                    111:                smb_fwrite(&smb,&idxbuf[i],sizeof(idxrec_t),smb.sid_fp);
                    112:        free(idxbuf);
                    113:        smb.status.total_msgs=l;
                    114:        smb_putstatus(&smb);
                    115:        smb_fflush(smb.sid_fp);
                    116:        smb_close_ha(&smb);
                    117:        smb_close_da(&smb);
                    118:        return(0);
                    119: }
                    120: 
                    121: 
                    122: /***********************************************/
                    123: /* Tell the user that so-and-so read your mail */
                    124: /***********************************************/
                    125: void sbbs_t::telluser(smbmsg_t* msg)
                    126: {
                    127:        char str[256];
                    128:        uint usernumber,n;
                    129:        node_t node;
                    130: 
                    131:        if(msg->from_net.type)
                    132:                return;
                    133:        if(msg->from_ext)
                    134:                usernumber=atoi(msg->from_ext);
                    135:        else {
                    136:                usernumber=matchuser(&cfg,msg->from,TRUE /*sysop_alias*/);
                    137:                if(!usernumber)
1.1.1.2 ! root      138:                        return; 
        !           139:        }
1.1       root      140:        for(n=1;n<=cfg.sys_nodes;n++) { /* Tell user */
                    141:                getnodedat(n,&node,0);
                    142:                if(node.useron==usernumber
                    143:                && (node.status==NODE_INUSE
                    144:                || node.status==NODE_QUIET)) {
                    145:                        sprintf(str
                    146:                                ,text[UserReadYourMailNodeMsg]
                    147:                                ,cfg.node_num,useron.alias);
                    148:                        putnmsg(&cfg,n,str);
1.1.1.2 ! root      149:                        break; 
        !           150:                } 
        !           151:        }
1.1       root      152:        if(n>cfg.sys_nodes) {
                    153:                now=time(NULL);
                    154:                sprintf(str,text[UserReadYourMail]
1.1.1.2 ! root      155:                        ,useron.alias,timestr(now));
        !           156:                putsmsg(&cfg,usernumber,str); 
        !           157:        }
1.1       root      158: }
                    159: 
                    160: /************************************************************************/
                    161: /* Deletes all mail waiting for user number 'usernumber'                */
                    162: /************************************************************************/
1.1.1.2 ! root      163: void sbbs_t::delallmail(uint usernumber, int which, bool permanent)
1.1       root      164: {
                    165:        int     i;
1.1.1.2 ! root      166:        long    l,deleted=0;
        !           167:        int32_t msgs;
1.1       root      168:        mail_t  *mail;
                    169:        smbmsg_t msg;
                    170: 
                    171:        if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) {
                    172:                errormsg(WHERE,ERR_OPEN,"MAIL",i);
1.1.1.2 ! root      173:                return; 
        !           174:        }
1.1       root      175:        sprintf(smb.file,"%smail",cfg.data_dir);
                    176:        smb.retry_time=cfg.smb_retry_time;
                    177:        smb.subnum=INVALID_SUB;
                    178:        if((i=smb_open(&smb))!=0) {
                    179:                errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
                    180:                smb_stack(&smb,SMB_STACK_POP);
1.1.1.2 ! root      181:                return; 
        !           182:        }
1.1       root      183: 
1.1.1.2 ! root      184:        mail=loadmail(&smb,&msgs,usernumber,which,0);
1.1       root      185:        if(!msgs) {
                    186:                smb_close(&smb);
                    187:                smb_stack(&smb,SMB_STACK_POP);
1.1.1.2 ! root      188:                return; 
        !           189:        }
1.1       root      190:        if((i=smb_locksmbhdr(&smb))!=0) {                       /* Lock the base, so nobody */
                    191:                smb_close(&smb);
                    192:                smb_stack(&smb,SMB_STACK_POP);
                    193:                free(mail);
                    194:                errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);     /* messes with the index */
1.1.1.2 ! root      195:                return; 
        !           196:        }
1.1       root      197:        for(l=0;l<msgs;l++) {
                    198:                msg.idx.offset=0;                                               /* search by number */
1.1.1.2 ! root      199:                if((mail[l].attr&MSG_PERMANENT) && !permanent)
        !           200:                        continue;
1.1       root      201:                if(loadmsg(&msg,mail[l].number)) {         /* message still there */
                    202:                        msg.hdr.attr|=MSG_DELETE;
                    203:                        msg.hdr.attr&=~MSG_PERMANENT;
                    204:                        msg.idx.attr=msg.hdr.attr;
                    205:                        if((i=smb_putmsg(&smb,&msg))!=0)
                    206:                                errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
                    207:                        else
                    208:                                deleted++;
                    209:                        smb_freemsgmem(&msg);
1.1.1.2 ! root      210:                        smb_unlockmsghdr(&smb,&msg); 
        !           211:                } 
        !           212:        }
1.1       root      213: 
                    214:        if(msgs)
                    215:                free(mail);
1.1.1.2 ! root      216:        if(permanent && deleted && (cfg.sys_misc&SM_DELEMAIL))
1.1       root      217:                delmail(usernumber,MAIL_ANY);
                    218:        smb_unlocksmbhdr(&smb);
                    219:        smb_close(&smb);
                    220:        smb_stack(&smb,SMB_STACK_POP);
                    221: }
                    222: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.