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

1.1       root        1: /* readmail.cpp */
                      2: 
                      3: /* Synchronet private mail reading function */
                      4: 
1.1.1.2 ! root        5: /* $Id: readmail.cpp,v 1.56 2011/09/03 06:00:03 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 2011 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: /* Reads mail waiting for usernumber.                                       */
                     42: /****************************************************************************/
                     43: void sbbs_t::readmail(uint usernumber, int which)
                     44: {
                     45:        char    str[256],str2[256],str3[256],done=0,domsg=1
                     46:                        ,*p,*tp,*sp,ch;
                     47:        char    tmp[512];
                     48:        int             i,j;
                     49:        int             error;
                     50:        int             mismatches=0,act;
1.1.1.2 ! root       51:        uint    unum;
1.1       root       52:     long    length,l,lm_mode;
                     53:        ulong   last;
                     54:        bool    replied;
                     55:        file_t  fd;
                     56:        mail_t  *mail;
                     57:        smbmsg_t msg;
                     58: 
                     59:        if(which==MAIL_SENT && useron.rest&FLAG('K')) {
                     60:                bputs(text[R_ReadSentMail]);
                     61:                return;
                     62:        }
                     63: 
                     64:        msg.total_hfields=0;                    /* init to NULL, cause not allocated yet */
                     65: 
                     66:        fd.dir=cfg.total_dirs+1;                        /* temp dir for file attachments */
                     67: 
                     68:        if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) {
                     69:                errormsg(WHERE,ERR_OPEN,"MAIL",i);
1.1.1.2 ! root       70:                return; 
        !            71:        }
1.1       root       72:        sprintf(smb.file,"%smail",cfg.data_dir);
                     73:        smb.retry_time=cfg.smb_retry_time;
                     74:        smb.subnum=INVALID_SUB;
                     75:        if((i=smb_open(&smb))!=0) {
                     76:                smb_stack(&smb,SMB_STACK_POP);
                     77:                errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
1.1.1.2 ! root       78:                return; 
        !            79:        }
1.1       root       80: 
                     81:        if(cfg.sys_misc&SM_SYSVDELM && (SYSOP || cfg.sys_misc&SM_USRVDELM))
                     82:                lm_mode=LM_INCDEL;
                     83:        else
                     84:                lm_mode=0;
                     85:        mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode);
                     86:        if(!smb.msgs) {
                     87:                if(which==MAIL_SENT)
                     88:                        bputs(text[NoMailSent]);
                     89:                else if(which==MAIL_ALL)
                     90:                        bputs(text[NoMailOnSystem]);
                     91:                else
                     92:                        bputs(text[NoMailWaiting]);
                     93:                smb_close(&smb);
                     94:                smb_stack(&smb,SMB_STACK_POP);
1.1.1.2 ! root       95:                return; 
        !            96:        }
1.1       root       97: 
                     98:        last=smb.status.last_msg;
                     99: 
                    100:        if(which==MAIL_SENT)
                    101:                act=NODE_RSML;
                    102:        else if(which==MAIL_ALL)
                    103:                act=NODE_SYSP;
                    104:        else
                    105:                act=NODE_RMAL;
                    106:        action=act;
                    107:        if(smb.msgs>1 && which!=MAIL_ALL) {
                    108:                if(which==MAIL_SENT)
                    109:                        bputs(text[MailSentLstHdr]);
                    110:                else
                    111:                        bputs(text[MailWaitingLstHdr]);
                    112: 
                    113:                for(smb.curmsg=0;smb.curmsg<smb.msgs && !msgabort();smb.curmsg++) {
                    114:                        if(msg.total_hfields)
                    115:                                smb_freemsgmem(&msg);
                    116:                        msg.total_hfields=0;
                    117:                        msg.idx.offset=mail[smb.curmsg].offset;
                    118:                        if(!loadmsg(&msg,mail[smb.curmsg].number))
                    119:                                continue;
                    120:                        smb_unlockmsghdr(&smb,&msg);
                    121:                        bprintf(text[MailWaitingLstFmt],smb.curmsg+1
                    122:                                ,which==MAIL_SENT ? msg.to
                    123:                                : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP ? text[Anonymous]
                    124:                                : msg.from
                    125:                                ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
                    126:                                        : msg.hdr.attr&MSG_READ ? ' '
                    127:                                        : msg.from_net.type || msg.to_net.type ? 'N':'*'
                    128:                                ,msg.subj);
                    129:                        smb_freemsgmem(&msg);
1.1.1.2 ! root      130:                        msg.total_hfields=0; 
        !           131:                }
1.1       root      132: 
                    133:                ASYNC;
                    134:                if(!(sys_status&SS_ABORT)) {
                    135:                        bprintf(text[StartWithN],1L);
                    136:                        if((long)(smb.curmsg=getnum(smb.msgs))>0)
                    137:                                smb.curmsg--;
                    138:                        else if((long)smb.curmsg==-1) {
                    139:                                free(mail);
                    140:                                smb_close(&smb);
                    141:                                smb_stack(&smb,SMB_STACK_POP);
1.1.1.2 ! root      142:                                return; 
        !           143:                        }
        !           144:                        
        !           145:                }
        !           146:                sys_status&=~SS_ABORT; 
        !           147:        }
1.1       root      148:        else {
                    149:                smb.curmsg=0;
                    150:                if(which==MAIL_ALL)
1.1.1.2 ! root      151:                        domsg=0; 
        !           152:        }
1.1       root      153:        if(which==MAIL_SENT) {
                    154:                sprintf(str,"%s read sent mail",useron.alias);
                    155:                logline("E",str);
                    156:        } else if(which==MAIL_ALL) {
                    157:                sprintf(str,"%s read all mail",useron.alias);
                    158:                logline("S+",str);
                    159:        } else {
                    160:                sprintf(str,"%s read mail",useron.alias);
                    161:                logline("E",str);
                    162:        }
                    163:        if(useron.misc&RIP) {
                    164:                strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ?
                    165:                        "allmail" : "sentmail");
1.1.1.2 ! root      166:                menu(str); 
        !           167:        }
1.1       root      168:        while(online && !done) {
                    169:                action=act;
                    170: 
                    171:                if(msg.total_hfields)
                    172:                        smb_freemsgmem(&msg);
                    173:                msg.total_hfields=0;
                    174: 
                    175:                msg.idx.offset=mail[smb.curmsg].offset;
                    176:                msg.idx.number=mail[smb.curmsg].number;
                    177:                msg.idx.to=mail[smb.curmsg].to;
                    178:                msg.idx.from=mail[smb.curmsg].from;
                    179:                msg.idx.subj=mail[smb.curmsg].subj;
                    180: 
                    181:                if((i=smb_locksmbhdr(&smb))!=0) {
1.1.1.2 ! root      182:                        errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);
        !           183:                        break; 
        !           184:                }
1.1       root      185: 
                    186:                if((i=smb_getstatus(&smb))!=0) {
                    187:                        smb_unlocksmbhdr(&smb);
1.1.1.2 ! root      188:                        errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
        !           189:                        break; 
        !           190:                }
1.1       root      191:                smb_unlocksmbhdr(&smb);
                    192: 
                    193:                if(smb.status.last_msg!=last) {         /* New messages */
                    194:                        last=smb.status.last_msg;
                    195:                        free(mail);
                    196:                        mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode);   /* So re-load */
                    197:                        if(!smb.msgs)
                    198:                                break;
                    199:                        for(smb.curmsg=0;smb.curmsg<smb.msgs;smb.curmsg++)
                    200:                                if(mail[smb.curmsg].number==msg.idx.number)
                    201:                                        break;
                    202:                        if(smb.curmsg>=smb.msgs)
                    203:                                smb.curmsg=(smb.msgs-1);
1.1.1.2 ! root      204:                        continue; 
        !           205:                }
1.1       root      206: 
                    207:                if(!loadmsg(&msg,mail[smb.curmsg].number)) {    /* Message header gone */
                    208:                        if(mismatches>5) {      /* We can't do this too many times in a row */
                    209:                                errormsg(WHERE,ERR_CHK,"message number",mail[smb.curmsg].number);
1.1.1.2 ! root      210:                                break; 
        !           211:                        }
1.1       root      212:                        free(mail);
                    213:                        mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode);
                    214:                        if(!smb.msgs)
                    215:                                break;
                    216:                        if(smb.curmsg>(smb.msgs-1))
                    217:                                smb.curmsg=(smb.msgs-1);
                    218:                        mismatches++;
1.1.1.2 ! root      219:                        continue; 
        !           220:                }
1.1       root      221:                smb_unlockmsghdr(&smb,&msg);
                    222:                msg.idx.attr=msg.hdr.attr;
                    223: 
                    224:                mismatches=0;
                    225: 
                    226:                if(domsg && !(sys_status&SS_ABORT)) {
                    227: 
                    228:                        show_msg(&msg
                    229:                                ,msg.from_ext && msg.idx.from==1 && !msg.from_net.type
                    230:                                        ? 0:P_NOATCODES);
                    231: 
                    232:                        if(msg.hdr.auxattr&MSG_FILEATTACH) {  /* Attached file */
                    233:                                smb_getmsgidx(&smb,&msg);
                    234:                                strcpy(str,msg.subj);                                   /* filenames in title */
                    235: //                             strupr(str);
                    236:                                tp=str;
                    237:                                while(online) {
                    238:                                        p=strchr(tp,' ');
                    239:                                        if(p) *p=0;
                    240:                                        sp=strrchr(tp,'/');              /* sp is slash pointer */
                    241:                                        if(!sp) sp=strrchr(tp,'\\');
                    242:                                        if(sp) tp=sp+1;
                    243:                                        padfname(tp,fd.name);
                    244:                                        sprintf(str2,"%sfile/%04u.in/%s"  /* str2 is path/fname */
                    245:                                                ,cfg.data_dir,msg.idx.to,tp);
1.1.1.2 ! root      246:                                        length=(long)flength(str2);
1.1       root      247:                                        if(length<1)
                    248:                                                bputs(text[FileNotFound]);
                    249:                                        else if(!(useron.exempt&FLAG('T')) && cur_cps && !SYSOP
                    250:                                                && length/(long)cur_cps>(time_t)timeleft)
                    251:                                                bputs(text[NotEnoughTimeToDl]);
                    252:                                        else {
                    253:                                                sprintf(str3,text[DownloadAttachedFileQ]
                    254:                                                        ,tp,ultoac(length,tmp));
1.1.1.2 ! root      255:                                                if(length>0L && text[DownloadAttachedFileQ][0] && yesno(str3)) {
1.1       root      256:                                                        {       /* Remote User */
                    257:                                                                xfer_prot_menu(XFER_DOWNLOAD);
                    258:                                                                mnemonics(text[ProtocolOrQuit]);
                    259:                                                                strcpy(str3,"Q");
                    260:                                                                for(i=0;i<cfg.total_prots;i++)
                    261:                                                                        if(cfg.prot[i]->dlcmd[0]
1.1.1.2 ! root      262:                                                                                && chk_ar(cfg.prot[i]->ar,&useron,&client)) {
1.1       root      263:                                                                                sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
1.1.1.2 ! root      264:                                                                                strcat(str3,tmp); 
        !           265:                                                                        }
1.1       root      266:                                                                ch=(char)getkeys(str3,0);
                    267:                                                                for(i=0;i<cfg.total_prots;i++)
                    268:                                                                        if(cfg.prot[i]->dlcmd[0] && ch==cfg.prot[i]->mnemonic
1.1.1.2 ! root      269:                                                                                && chk_ar(cfg.prot[i]->ar,&useron,&client))
1.1       root      270:                                                                                break;
                    271:                                                                if(i<cfg.total_prots) {
                    272:                                                                        error=protocol(cfg.prot[i],XFER_DOWNLOAD,str2,nulstr,false);
                    273:                                                                        if(checkprotresult(cfg.prot[i],error,&fd)) {
                    274:                                                                                if(which==MAIL_YOUR)
                    275:                                                                                        remove(str2);
                    276:                                                                                logon_dlb+=length;      /* Update stats */
                    277:                                                                                logon_dls++;
                    278:                                                                                useron.dls=(ushort)adjustuserrec(&cfg,useron.number
                    279:                                                                                        ,U_DLS,5,1);
                    280:                                                                                useron.dlb=adjustuserrec(&cfg,useron.number
                    281:                                                                                        ,U_DLB,10,length);
                    282:                                                                                bprintf(text[FileNBytesSent]
                    283:                                                                                        ,fd.name,ultoac(length,tmp));
                    284:                                                                                sprintf(str3
                    285:                                                                                        ,"%s downloaded attached file: %s"
                    286:                                                                                        ,useron.alias
                    287:                                                                                        ,fd.name);
                    288:                                                                                logline("D-",str3); 
                    289:                                                                        }
                    290:                                                                        autohangup(); 
                    291:                                                                } 
                    292:                                                        } 
                    293:                                                } 
                    294:                                        }
                    295:                                        if(!p)
                    296:                                                break;
                    297:                                        tp=p+1;
                    298:                                        while(*tp==' ') tp++; 
                    299:                                }
                    300:                                sprintf(str,"%sfile/%04u.in",cfg.data_dir,usernumber);
1.1.1.2 ! root      301:                                rmdir(str); 
        !           302:                        }
1.1       root      303:                        if(which==MAIL_YOUR && !(msg.hdr.attr&MSG_READ)) {
                    304:                                mail[smb.curmsg].attr|=MSG_READ;
                    305:                                if(thisnode.status==NODE_INUSE)
                    306:                                        telluser(&msg);
                    307:                                if(msg.total_hfields)
                    308:                                        smb_freemsgmem(&msg);
                    309:                                msg.total_hfields=0;
                    310:                                msg.idx.offset=0;                                               /* Search by number */
                    311:                                if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
                    312:                                        if(loadmsg(&msg,msg.idx.number)) {
                    313:                                                msg.hdr.attr|=MSG_READ;
1.1.1.2 ! root      314:                                                if(msg.hdr.attr&MSG_KILLREAD)
        !           315:                                                        msg.hdr.attr|=MSG_DELETE;
1.1       root      316:                                                msg.idx.attr=msg.hdr.attr;
                    317:                                                if((i=smb_putmsg(&smb,&msg))!=0)
1.1.1.2 ! root      318:                                                        errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
        !           319:                                                smb_unlockmsghdr(&smb,&msg); 
        !           320:                                        }
        !           321:                                        smb_unlocksmbhdr(&smb); 
        !           322:                                }
1.1       root      323:                                if(!msg.total_hfields) {                                /* unsuccessful reload */
                    324:                                        domsg=0;
1.1.1.2 ! root      325:                                        continue; 
        !           326:                                }
1.1       root      327:                        }
1.1.1.2 ! root      328:                }
1.1       root      329:                else domsg=1;
                    330: 
                    331:                if(useron.misc&WIP) {
                    332:                        strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ?
                    333:                                "allmail" : "sentmail");
1.1.1.2 ! root      334:                        menu(str); 
        !           335:                }
1.1       root      336: 
                    337:                ASYNC;
                    338:                if(which==MAIL_SENT)
                    339:                        bprintf(text[ReadingSentMail],smb.curmsg+1,smb.msgs);
                    340:                else if(which==MAIL_ALL)
                    341:                        bprintf(text[ReadingAllMail],smb.curmsg+1,smb.msgs);
                    342:                else
                    343:                        bprintf(text[ReadingMail],smb.curmsg+1,smb.msgs);
1.1.1.2 ! root      344:                sprintf(str,"ADKFLNQRT?<>[]{}-+");
1.1       root      345:                if(SYSOP)
                    346:                        strcat(str,"CUSPH");
                    347:                if(which!=MAIL_YOUR)
                    348:                        strcat(str,"E");
                    349:                l=getkeys(str,smb.msgs);
                    350:                if(l&0x80000000L) {
                    351:                        if(l==-1)       /* ctrl-c */
                    352:                                break;
                    353:                        smb.curmsg=(l&~0x80000000L)-1;
1.1.1.2 ! root      354:                        continue; 
        !           355:                }
1.1       root      356:                switch(l) {
                    357:                        case 'A':   /* Auto-reply to last piece */
                    358:                        case 'R':
                    359:                                if(l==(cfg.sys_misc&SM_RA_EMU ? 'A' : 'R'))  /* re-read last message */
                    360:                                        break;
                    361: 
                    362:                                if(which==MAIL_SENT)
                    363:                                        break;
1.1.1.2 ! root      364:                                if((msg.hdr.attr&(MSG_NOREPLY|MSG_ANONYMOUS)) && !SYSOP) {
        !           365:                                        bputs(text[CantReplyToMsg]);
        !           366:                                        break; 
        !           367:                                }
1.1       root      368: 
1.1.1.2 ! root      369:                                quotemsg(&msg,/* include tails: */TRUE);
1.1       root      370: 
                    371:                                if(msg.from_net.addr==NULL)
                    372:                                        SAFECOPY(str,msg.from);
                    373:                                else if(msg.from_net.type==NET_FIDO)    /* FidoNet type */
                    374:                                        SAFEPRINTF2(str,"%s@%s",msg.from
                    375:                                                ,smb_faddrtoa((faddr_t *)msg.from_net.addr,tmp));
1.1.1.2 ! root      376:                                else if(msg.from_net.type==NET_INTERNET || strchr((char*)msg.from_net.addr,'@')!=NULL) {
1.1       root      377:                                        if(msg.replyto_net.type==NET_INTERNET)
                    378:                                                SAFECOPY(str,(char *)msg.replyto_net.addr);
                    379:                                        else
                    380:                                                SAFECOPY(str,(char *)msg.from_net.addr);
                    381:                                } else
                    382:                                        SAFEPRINTF2(str,"%s@%s",msg.from,(char*)msg.from_net.addr);
                    383: 
                    384:                                SAFECOPY(str2,str);
                    385: 
                    386:                                bputs(text[Email]);
                    387:                                if(!getstr(str,64,K_EDIT|K_AUTODEL))
                    388:                                        break;
                    389:                                msg.hdr.number=msg.idx.number;
                    390:                                smb_getmsgidx(&smb,&msg);
                    391: 
                    392:                                if(!stricmp(str2,str))          /* Reply to sender */
                    393:                                        sprintf(str2,text[Regarding],msg.subj);
                    394:                                else                                            /* Reply to other */
                    395:                                        sprintf(str2,text[RegardingByOn],msg.subj,msg.from
1.1.1.2 ! root      396:                                                ,timestr(msg.hdr.when_written.time));
1.1       root      397: 
                    398:                                p=strrchr(str,'@');
                    399:                                if(p) {                                                         /* name @addr */
                    400:                                        replied=netmail(str,msg.subj,WM_QUOTE);
1.1.1.2 ! root      401:                                        sprintf(str2,text[DeleteMailQ],msg.from); 
        !           402:                                }
1.1       root      403:                                else {
                    404:                                        if(!msg.from_net.type && !stricmp(str,msg.from))
                    405:                                                replied=email(msg.idx.from,str2,msg.subj,WM_EMAIL|WM_QUOTE);
                    406:                                        else if(!stricmp(str,"SYSOP"))
                    407:                                                replied=email(1,str2,msg.subj,WM_EMAIL|WM_QUOTE);
                    408:                                        else if((i=finduser(str))!=0)
                    409:                                                replied=email(i,str2,msg.subj,WM_EMAIL|WM_QUOTE);
                    410:                                        else
                    411:                                                replied=false;
1.1.1.2 ! root      412:                                        sprintf(str2,text[DeleteMailQ],msg.from); 
        !           413:                                }
1.1       root      414: 
                    415:                                if(replied==true && !(msg.hdr.attr&MSG_REPLIED)) {
                    416:                                        if(msg.total_hfields)
                    417:                                                smb_freemsgmem(&msg);
                    418:                                        msg.total_hfields=0;
                    419:                                        msg.idx.offset=0;
                    420:                                        if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
                    421:                                                if(loadmsg(&msg,msg.idx.number)) {
                    422:                                                        msg.hdr.attr|=MSG_REPLIED;
                    423:                                                        msg.idx.attr=msg.hdr.attr;
                    424:                                                        if((i=smb_putmsg(&smb,&msg))!=0)
1.1.1.2 ! root      425:                                                                errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
1.1       root      426:                                                        smb_unlockmsghdr(&smb,&msg); 
                    427:                                                }
                    428:                                                smb_unlocksmbhdr(&smb);
                    429:                                        }
                    430:                                }
                    431: 
1.1.1.2 ! root      432:                                if(msg.hdr.attr&MSG_DELETE || noyes(str2)) {
1.1       root      433:                                        if(smb.curmsg<smb.msgs-1) smb.curmsg++;
                    434:                                        else done=1;
                    435:                                        break;  }
                    436:                                /* Case 'D': must follow! */
                    437:                        case 'D':   /* Delete last piece (toggle) */
                    438:                                if(msg.hdr.attr&MSG_PERMANENT) {
1.1.1.2 ! root      439:                                        bputs(text[CantDeleteMsg]);
1.1       root      440:                                        domsg=0;
1.1.1.2 ! root      441:                                        break; 
        !           442:                                }
1.1       root      443:                                if(msg.total_hfields)
                    444:                                        smb_freemsgmem(&msg);
                    445:                                msg.total_hfields=0;
                    446:                                msg.idx.offset=0;
                    447:                                if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
                    448:                                        if(loadmsg(&msg,msg.idx.number)) {
                    449:                                                msg.hdr.attr^=MSG_DELETE;
                    450:                                                msg.idx.attr=msg.hdr.attr;
                    451:                //                                mail[smb.curmsg].attr=msg.hdr.attr;
                    452:                                                if((i=smb_putmsg(&smb,&msg))!=0)
1.1.1.2 ! root      453:                                                        errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
1.1       root      454:                                                smb_unlockmsghdr(&smb,&msg); 
                    455:                                        }
                    456:                                        smb_unlocksmbhdr(&smb);
                    457:                                }
                    458:                                if(smb.curmsg<smb.msgs-1) smb.curmsg++;
                    459:                                else done=1;
                    460:                                break;
1.1.1.2 ! root      461:                        case 'K':       /* Kill All Mail */
        !           462:                                SAFEPRINTF(str,text[DeleteMailQ],"everyone");
        !           463:                                if(!noyes(str))
        !           464:                                        delallmail(usernumber, MAIL_YOUR, /* permanent: */false);
        !           465:                                domsg=false;
        !           466:                                break;
1.1       root      467:                        case 'F':  /* Forward last piece */
                    468:                                domsg=0;
                    469:                                bputs(text[ForwardMailTo]);
                    470:                                if(!getstr(str,LEN_ALIAS,cfg.uq&UQ_NOUPRLWR ? K_NONE:K_UPRLWR))
                    471:                                        break;
                    472:                                i=finduser(str);
                    473:                                if(!i)
                    474:                                        break;
                    475:                                domsg=1;
                    476:                                if(smb.curmsg<smb.msgs-1) smb.curmsg++;
                    477:                                else done=1;
                    478:                                smb_getmsgidx(&smb,&msg);
                    479:                                forwardmail(&msg,i);
                    480:                                if(msg.hdr.attr&MSG_PERMANENT)
                    481:                                        break;
                    482:                                sprintf(str2,text[DeleteMailQ],msg.from);
                    483:                                if(!yesno(str2))
                    484:                                        break;
                    485:                                if(msg.total_hfields)
                    486:                                        smb_freemsgmem(&msg);
                    487:                                msg.total_hfields=0;
                    488:                                msg.idx.offset=0;
                    489:                                if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
                    490:                                        if(loadmsg(&msg,msg.idx.number)) {
                    491:                                                msg.hdr.attr|=MSG_DELETE;
                    492:                                                msg.idx.attr=msg.hdr.attr;
                    493:                //                                mail[smb.curmsg].attr=msg.hdr.attr;
                    494:                                                if((i=smb_putmsg(&smb,&msg))!=0)
1.1.1.2 ! root      495:                                                        errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
1.1       root      496:                                                smb_unlockmsghdr(&smb,&msg); 
                    497:                                        }
                    498:                                        smb_unlocksmbhdr(&smb);
                    499:                                }
                    500: 
                    501:                                break;
                    502:                        case 'H':
                    503:                                domsg=0;
                    504:                                msghdr(&msg);
                    505:                                break;
                    506:                        case 'L':     /* List mail */
                    507:                                domsg=0;
                    508:                                bprintf(text[StartWithN],(long)smb.curmsg+1);
                    509:                                if((i=getnum(smb.msgs))>0)
                    510:                                        i--;
                    511:                                else if(i==-1)
                    512:                                        break;
                    513:                                else
                    514:                                        i=smb.curmsg;
                    515:                                if(which==MAIL_SENT)
                    516:                                        bputs(text[MailSentLstHdr]);
                    517:                                else if(which==MAIL_ALL)
                    518:                                        bputs(text[MailOnSystemLstHdr]);
                    519:                                else
                    520:                                        bputs(text[MailWaitingLstHdr]);
                    521:                                for(;i<smb.msgs && !msgabort();i++) {
                    522:                                        if(msg.total_hfields)
                    523:                                                smb_freemsgmem(&msg);
                    524:                                        msg.total_hfields=0;
                    525:                                        msg.idx.offset=mail[i].offset;
                    526:                                        if(!loadmsg(&msg,mail[i].number))
                    527:                                                continue;
                    528:                                        smb_unlockmsghdr(&smb,&msg);
                    529:                                        if(which==MAIL_ALL)
                    530:                                                bprintf(text[MailOnSystemLstFmt]
                    531:                                                        ,i+1,msg.from,msg.to
                    532:                                                        ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
                    533:                                                                : msg.hdr.attr&MSG_READ ? ' '
                    534:                                                                : msg.from_net.type || msg.to_net.type ? 'N':'*'
                    535:                                                        ,msg.subj);
                    536:                                        else
                    537:                                                bprintf(text[MailWaitingLstFmt],i+1
                    538:                                                        ,which==MAIL_SENT ? msg.to
                    539:                                                        : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP
                    540:                                                        ? text[Anonymous] : msg.from
                    541:                                                        ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
                    542:                                                                : msg.hdr.attr&MSG_READ ? ' '
                    543:                                                                : msg.from_net.type || msg.to_net.type ? 'N':'*'
                    544:                                                        ,msg.subj);
                    545:                                        smb_freemsgmem(&msg);
1.1.1.2 ! root      546:                                        msg.total_hfields=0; 
        !           547:                                }
1.1       root      548:                                break;
                    549:                        case 'Q':
                    550:                                done=1;
                    551:                                break;
                    552:                        case 'C':   /* Change attributes of last piece */
                    553:                                i=chmsgattr(msg.hdr.attr);
                    554:                                if(msg.hdr.attr==i)
                    555:                                        break;
                    556:                                if(msg.total_hfields)
                    557:                                        smb_freemsgmem(&msg);
                    558:                                msg.total_hfields=0;
                    559:                                msg.idx.offset=0;
                    560:                                if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
                    561:                                        if(loadmsg(&msg,msg.idx.number)) {
                    562:                                                msg.hdr.attr=msg.idx.attr=(ushort)i;
                    563:                                                if((i=smb_putmsg(&smb,&msg))!=0)
1.1.1.2 ! root      564:                                                        errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
1.1       root      565:                                                smb_unlockmsghdr(&smb,&msg); 
                    566:                                        }
                    567:                                        smb_unlocksmbhdr(&smb);
                    568:                                }
                    569:                                break;
                    570:                        case '>':
                    571:                                for(i=smb.curmsg+1;i<smb.msgs;i++)
                    572:                                        if(mail[i].subj==msg.idx.subj)
                    573:                                                break;
                    574:                                if(i<smb.msgs)
                    575:                                        smb.curmsg=i;
                    576:                                else
                    577:                                        domsg=0;
                    578:                                break;
                    579:                        case '<':   /* Search Title backward */
                    580:                                for(i=smb.curmsg-1;i>-1;i--)
                    581:                                        if(mail[i].subj==msg.idx.subj)
                    582:                                                break;
                    583:                                if(i>-1)
                    584:                                        smb.curmsg=i;
                    585:                                else
                    586:                                        domsg=0;
                    587:                                break;
                    588:                        case '}':   /* Search Author forward */
                    589:                                strcpy(str,msg.from);
                    590:                                for(i=smb.curmsg+1;i<smb.msgs;i++)
                    591:                                        if(mail[i].from==msg.idx.from)
                    592:                                                break;
                    593:                                if(i<smb.msgs)
                    594:                                        smb.curmsg=i;
                    595:                                else
                    596:                                        domsg=0;
                    597:                                break;
                    598:                        case 'N':   /* Got to next un-read message */
                    599:                                for(i=smb.curmsg+1;i<smb.msgs;i++)
                    600:                                        if(!(mail[i].attr&MSG_READ))
                    601:                                                break;
                    602:                                if(i<smb.msgs)
                    603:                                        smb.curmsg=i;
                    604:                                else
                    605:                                        domsg=0;
                    606:                                break;
                    607:                        case '{':   /* Search Author backward */
                    608:                                strcpy(str,msg.from);
                    609:                                for(i=smb.curmsg-1;i>-1;i--)
                    610:                                        if(mail[i].from==msg.idx.from)
                    611:                                                break;
                    612:                                if(i>-1)
                    613:                                        smb.curmsg=i;
                    614:                                else
                    615:                                        domsg=0;
                    616:                                break;
                    617:                        case ']':   /* Search To User forward */
                    618:                                strcpy(str,msg.to);
                    619:                                for(i=smb.curmsg+1;i<smb.msgs;i++)
                    620:                                        if(mail[i].to==msg.idx.to)
                    621:                                                break;
                    622:                                if(i<smb.msgs)
                    623:                                        smb.curmsg=i;
                    624:                                else
                    625:                                        domsg=0;
                    626:                                break;
                    627:                        case '[':   /* Search To User backward */
                    628:                                strcpy(str,msg.to);
                    629:                                for(i=smb.curmsg-1;i>-1;i--)
                    630:                                        if(mail[i].to==msg.idx.to)
                    631:                                                break;
                    632:                                if(i>-1)
                    633:                                        smb.curmsg=i;
                    634:                                else
                    635:                                        domsg=0;
                    636:                                break;
                    637:                        case 0:
                    638:                        case '+':
                    639:                                if(smb.curmsg<smb.msgs-1) smb.curmsg++;
                    640:                                else done=1;
                    641:                                break;
                    642:                        case '-':
                    643:                                if(smb.curmsg>0) smb.curmsg--;
                    644:                                break;
                    645:                        case 'S':
                    646:                                domsg=0;
                    647:        /*
                    648:                                if(!yesno(text[SaveMsgToFile]))
                    649:                                        break;
                    650:        */
                    651:                                bputs(text[FileToWriteTo]);
                    652:                                if(getstr(str,40,K_LINE))
                    653:                                        msgtotxt(&msg,str,1,1);
                    654:                                break;
                    655:                        case 'E':
                    656:                                editmsg(&msg,INVALID_SUB);
                    657:                                break;
                    658:                        case 'T':
                    659:                                domsg=0;
                    660:                                i=smb.curmsg;
                    661:                                if(i) i++;
                    662:                                j=i+10;
                    663:                                if(j>smb.msgs)
                    664:                                        j=smb.msgs;
                    665: 
                    666:                                if(which==MAIL_SENT)
                    667:                                        bputs(text[MailSentLstHdr]);
                    668:                                else if(which==MAIL_ALL)
                    669:                                        bputs(text[MailOnSystemLstHdr]);
                    670:                                else
                    671:                                        bputs(text[MailWaitingLstHdr]);
                    672:                                for(;i<j;i++) {
                    673:                                        if(msg.total_hfields)
                    674:                                                smb_freemsgmem(&msg);
                    675:                                        msg.total_hfields=0;
                    676:                                        msg.idx.offset=mail[i].offset;
                    677:                                        if(!loadmsg(&msg,mail[i].number))
                    678:                                                continue;
                    679:                                        smb_unlockmsghdr(&smb,&msg);
                    680:                                        if(which==MAIL_ALL)
                    681:                                                bprintf(text[MailOnSystemLstFmt]
                    682:                                                        ,i+1,msg.from,msg.to
                    683:                                                        ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
                    684:                                                                : msg.hdr.attr&MSG_READ ? ' ' 
                    685:                                                                : msg.from_net.type || msg.to_net.type ? 'N':'*'
                    686:                                                        ,msg.subj);
                    687:                                        else
                    688:                                                bprintf(text[MailWaitingLstFmt],i+1
                    689:                                                        ,which==MAIL_SENT ? msg.to
                    690:                                                        : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP
                    691:                                                        ? text[Anonymous] : msg.from
                    692:                                                        ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
                    693:                                                                : msg.hdr.attr&MSG_READ ? ' '
                    694:                                                                : msg.from_net.type || msg.to_net.type ? 'N':'*'
                    695:                                                        ,msg.subj);
                    696:                                        smb_freemsgmem(&msg);
1.1.1.2 ! root      697:                                        msg.total_hfields=0; 
        !           698:                                }
1.1       root      699:                                smb.curmsg=(i-1);
                    700:                                break;
                    701:                        case 'U':   /* user edit */
                    702:                                msg.hdr.number=msg.idx.number;
                    703:                                smb_getmsgidx(&smb,&msg);
1.1.1.2 ! root      704:                                if((unum=(which==MAIL_SENT ? msg.idx.to : msg.idx.from)) == 0)
        !           705:                                        unum=(which==MAIL_SENT ? msg.idx.from : msg.idx.to);
        !           706:                                if(unum == 0 || unum > lastuser(&cfg)) {
        !           707:                                        bputs(text[UnknownUser]);
        !           708:                                        domsg=false;
        !           709:                                } else
        !           710:                                        useredit(unum);
1.1       root      711:                                break;
                    712:                        case 'P':   /* Purge author and all mail to/from */
1.1.1.2 ! root      713:                                if(noyes(text[UeditDeleteQ]))
1.1       root      714:                                        break;
                    715:                                msg.hdr.number=msg.idx.number;
                    716:                                smb_getmsgidx(&smb,&msg);
1.1.1.2 ! root      717:                                if((which==MAIL_SENT ? msg.idx.to : msg.idx.from) == 0) {
        !           718:                                        bputs(text[UnknownUser]);
        !           719:                                        domsg=false;
        !           720:                                } else {
        !           721:                                        purgeuser(msg.idx.from);
        !           722:                                        if(smb.curmsg<smb.msgs-1) smb.curmsg++;
        !           723:                                }
1.1       root      724:                                break;
                    725:                        case '?':
                    726:                                strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL
                    727:                                                ? "allmail" : "sentmail");
                    728:                                menu(str);
                    729:                                if(SYSOP && which==MAIL_SENT)
                    730:                                        menu("syssmail");
                    731:                                else if(SYSOP && which==MAIL_YOUR)
                    732:                                        menu("sysmailr");   /* Sysop Mail Read */
                    733:                                domsg=0;
                    734:                                break;
1.1.1.2 ! root      735:                                
        !           736:                } 
        !           737:        }
1.1       root      738: 
                    739:        if(msg.total_hfields)
                    740:                smb_freemsgmem(&msg);
                    741: 
                    742:        if(smb.msgs)
                    743:                free(mail);
                    744: 
                    745:        /***************************************/
                    746:        /* Delete messages marked for deletion */
                    747:        /***************************************/
                    748: 
                    749:        if(cfg.sys_misc&SM_DELEMAIL) {
                    750:                if((i=smb_locksmbhdr(&smb))!=0)                         /* Lock the base, so nobody */
1.1.1.2 ! root      751:                        errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);     /* messes with the index */
1.1       root      752:                else
1.1.1.2 ! root      753:                        delmail(usernumber,which); 
        !           754:        }
1.1       root      755: 
                    756:        smb_close(&smb);
                    757:        smb_stack(&smb,SMB_STACK_POP);
                    758: }
                    759: 

unix.superglobalmegacorp.com

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