Annotation of sbbs/src/sbbs3/email.cpp, revision 1.1

1.1     ! root        1: /* email.cpp */
        !             2: 
        !             3: /* Synchronet email function - for sending private e-mail */
        !             4: 
        !             5: /* $Id: email.cpp,v 1.41 2006/08/23 22:34:32 rswindell Exp $ */
        !             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:  *                                                                                                                                                     *
        !            11:  * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            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: #include "cmdshell.h"
        !            40: 
        !            41: /****************************************************************************/
        !            42: /* Mails a message to usernumber. 'top' is a buffer to place at beginning   */
        !            43: /* of message.                                                              */
        !            44: /* Called from functions main_sec, newuser, readmail and scanposts                     */
        !            45: /****************************************************************************/
        !            46: bool sbbs_t::email(int usernumber, char *top, char *subj, long mode)
        !            47: {
        !            48:        char    str[256],str2[256],msgpath[256],title[LEN_TITLE+1],ch
        !            49:                        ,buf[SDT_BLOCK_LEN];
        !            50:        char    tmp[512];
        !            51:        ushort  xlat=XLAT_NONE,msgattr=0;
        !            52:        ushort  nettype;
        !            53:        int     i,j,x,file;
        !            54:        long    l;
        !            55:        ulong   length,offset,crc=0xffffffffUL;
        !            56:        FILE    *instream;
        !            57:        node_t  node;
        !            58:        smbmsg_t msg;
        !            59: 
        !            60:        SAFECOPY(title,subj);
        !            61: 
        !            62:        if(useron.etoday>=cfg.level_emailperday[useron.level] && !SYSOP) {
        !            63:                bputs(text[TooManyEmailsToday]);
        !            64:                return(false); }
        !            65: 
        !            66:        if(usernumber==1 && useron.rest&FLAG('S')
        !            67:                && (cfg.node_valuser!=1 || useron.fbacks || useron.emails)) { /* ! val fback */
        !            68:                bprintf(text[R_Feedback],cfg.sys_op);
        !            69:                return(false); }
        !            70:        if(usernumber!=1 && useron.rest&FLAG('E')
        !            71:                && (cfg.node_valuser!=usernumber || useron.fbacks || useron.emails)) {
        !            72:                bputs(text[R_Email]);
        !            73:                return(false); }
        !            74:        if(!usernumber) {
        !            75:                bputs(text[UnknownUser]);
        !            76:                return(false); }
        !            77:        getuserrec(&cfg,usernumber,U_MISC,8,str);
        !            78:        l=ahtoul(str);
        !            79:        if(l&(DELETED|INACTIVE)) {              /* Deleted or Inactive User */
        !            80:                bputs(text[UnknownUser]);
        !            81:                return(false); }
        !            82:        if(l&NETMAIL && cfg.sys_misc&SM_FWDTONET) {
        !            83:                getuserrec(&cfg,usernumber,U_NETMAIL,LEN_NETMAIL,str);
        !            84:                bprintf(text[UserNetMail],str);
        !            85:                if(yesno(text[ForwardMailQ])) /* Forward to netmail address */
        !            86:                        return(netmail(str,subj,mode));
        !            87:        }
        !            88:        bprintf(text[Emailing],username(&cfg,usernumber,tmp),usernumber);
        !            89:        action=NODE_SMAL;
        !            90:        nodesync();
        !            91: 
        !            92:        sprintf(str,"%sfeedback.*", cfg.exec_dir);
        !            93:        if(usernumber==1 && useron.fbacks && fexist(str)) {
        !            94:                exec_bin("feedback",&main_csi);
        !            95:                if(main_csi.logic!=LOGIC_TRUE)
        !            96:                        return(false); }
        !            97: 
        !            98:        if(cfg.sys_misc&SM_ANON_EM && useron.exempt&FLAG('A')
        !            99:                && !noyes(text[AnonymousQ]))
        !           100:                msgattr|=MSG_ANONYMOUS;
        !           101: 
        !           102:        if(cfg.sys_misc&SM_DELREADM)
        !           103:                msgattr|=MSG_KILLREAD;
        !           104: 
        !           105:        msg_tmp_fname(useron.xedit, msgpath, sizeof(msgpath));
        !           106:        username(&cfg,usernumber,str2);
        !           107:        if(!writemsg(msgpath,top,title,mode,INVALID_SUB,str2)) {
        !           108:                bputs(text[Aborted]);
        !           109:                return(false); 
        !           110:        }
        !           111: 
        !           112:        if(mode&WM_FILE && !SYSOP && !(cfg.sys_misc&SM_FILE_EM))
        !           113:                mode&=~WM_FILE;
        !           114: 
        !           115: 
        !           116:        if(mode&WM_FILE) {
        !           117:                sprintf(str2,"%sfile/%04u.in", cfg.data_dir,usernumber);
        !           118:                MKDIR(str2);
        !           119:                sprintf(str2,"%sfile/%04u.in/%s", cfg.data_dir,usernumber,title);
        !           120:                if(fexistcase(str2)) {
        !           121:                        bputs(text[FileAlreadyThere]);
        !           122:                        remove(msgpath);
        !           123:                        return(false); }
        !           124: #if 0  /* no such thing as local logon */
        !           125:                if(online==ON_LOCAL) {          /* Local upload */
        !           126:                        bputs(text[EnterPath]);
        !           127:                        if(!getstr(str,60,K_LINE|K_UPPER)) {
        !           128:                                bputs(text[Aborted]);
        !           129:                                remove(msgpath);
        !           130:                                return(false); }
        !           131:                        backslash(str);
        !           132:                        strcat(str,title);
        !           133:                        mv(str,str2,1); }
        !           134:                else 
        !           135: #endif
        !           136:                { /* Remote */
        !           137:                        xfer_prot_menu(XFER_UPLOAD);
        !           138:                        mnemonics(text[ProtocolOrQuit]);
        !           139:                        strcpy(str,"Q");
        !           140:                        for(x=0;x<cfg.total_prots;x++)
        !           141:                                if(cfg.prot[x]->ulcmd[0] && chk_ar(cfg.prot[x]->ar,&useron)) {
        !           142:                                        sprintf(tmp,"%c",cfg.prot[x]->mnemonic);
        !           143:                                        strcat(str,tmp); }
        !           144:                        ch=(char)getkeys(str,0);
        !           145:                        if(ch=='Q' || sys_status&SS_ABORT) {
        !           146:                                bputs(text[Aborted]);
        !           147:                                remove(msgpath);
        !           148:                                return(false); }
        !           149:                        for(x=0;x<cfg.total_prots;x++)
        !           150:                                if(cfg.prot[x]->ulcmd[0] && cfg.prot[x]->mnemonic==ch
        !           151:                                        && chk_ar(cfg.prot[x]->ar,&useron))
        !           152:                                        break;
        !           153:                        if(x<cfg.total_prots)   /* This should be always */
        !           154:                                protocol(cfg.prot[x],XFER_UPLOAD,str2,nulstr,true); 
        !           155:                }
        !           156:                sprintf(tmp,"%s%s",cfg.temp_dir,title);
        !           157:                if(!fexistcase(str2) && fexistcase(tmp))
        !           158:                        mv(tmp,str2,0);
        !           159:                l=flength(str2);
        !           160:                if(l>0)
        !           161:                        bprintf(text[FileNBytesReceived],title,ultoac(l,tmp));
        !           162:                else {
        !           163:                        bprintf(text[FileNotReceived],title);
        !           164:                        remove(msgpath);
        !           165:                        return(false); } }
        !           166: 
        !           167:        bputs(text[WritingIndx]);
        !           168: 
        !           169:        if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) {
        !           170:                errormsg(WHERE,ERR_OPEN,"MAIL",i);
        !           171:                return(false); }
        !           172:        sprintf(smb.file,"%smail", cfg.data_dir);
        !           173:        smb.retry_time=cfg.smb_retry_time;
        !           174:        smb.subnum=INVALID_SUB;
        !           175:        if((i=smb_open(&smb))!=0) {
        !           176:                smb_stack(&smb,SMB_STACK_POP);
        !           177:                errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
        !           178:                return(false); }
        !           179: 
        !           180:        if(smb_fgetlength(smb.shd_fp)<1) {       /* Create it if it doesn't exist */
        !           181:                smb.status.max_crcs=cfg.mail_maxcrcs;
        !           182:                smb.status.max_age=cfg.mail_maxage;
        !           183:                smb.status.max_msgs=0;
        !           184:                smb.status.attr=SMB_EMAIL;
        !           185:                if((i=smb_create(&smb))!=0) {
        !           186:                        smb_close(&smb);
        !           187:                        smb_stack(&smb,SMB_STACK_POP);
        !           188:                        errormsg(WHERE,ERR_CREATE,smb.file,i,smb.last_error);
        !           189:                        return(false); } }
        !           190: 
        !           191:        if((i=smb_locksmbhdr(&smb))!=0) {
        !           192:                smb_close(&smb);
        !           193:                smb_stack(&smb,SMB_STACK_POP);
        !           194:                errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);
        !           195:                return(false); }
        !           196: 
        !           197:        length=flength(msgpath)+2;       /* +2 for translation string */
        !           198: 
        !           199:        if(length&0xfff00000UL) {
        !           200:                smb_unlocksmbhdr(&smb);
        !           201:                smb_close(&smb);
        !           202:                smb_stack(&smb,SMB_STACK_POP);
        !           203:                errormsg(WHERE,ERR_LEN,msgpath,length);
        !           204:                return(false); }
        !           205: 
        !           206:        if((i=smb_open_da(&smb))!=0) {
        !           207:                smb_unlocksmbhdr(&smb);
        !           208:                smb_close(&smb);
        !           209:                smb_stack(&smb,SMB_STACK_POP);
        !           210:                errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
        !           211:                return(false); }
        !           212:        if(cfg.sys_misc&SM_FASTMAIL)
        !           213:                offset=smb_fallocdat(&smb,length,1);
        !           214:        else
        !           215:                offset=smb_allocdat(&smb,length,1);
        !           216:        smb_close_da(&smb);
        !           217: 
        !           218:        if((file=open(msgpath,O_RDONLY|O_BINARY))==-1
        !           219:                || (instream=fdopen(file,"rb"))==NULL) {
        !           220:                smb_freemsgdat(&smb,offset,length,1);
        !           221:                smb_unlocksmbhdr(&smb);
        !           222:                smb_close(&smb);
        !           223:                smb_stack(&smb,SMB_STACK_POP);
        !           224:                errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY);
        !           225:                return(false); }
        !           226: 
        !           227:        setvbuf(instream,NULL,_IOFBF,2*1024);
        !           228:        smb_fseek(smb.sdt_fp,offset,SEEK_SET);
        !           229:        xlat=XLAT_NONE;
        !           230:        smb_fwrite(&smb,&xlat,2,smb.sdt_fp);
        !           231:        x=SDT_BLOCK_LEN-2;                              /* Don't read/write more than 255 */
        !           232:        while(!feof(instream)) {
        !           233:                memset(buf,0,x);
        !           234:                j=fread(buf,1,x,instream);
        !           235:                if(j<1)
        !           236:                        break;
        !           237:                if(j>1 && (j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR)
        !           238:                        buf[j-1]=buf[j-2]=0;
        !           239:                if(cfg.mail_maxcrcs) {
        !           240:                        for(i=0;i<j;i++)
        !           241:                                crc=ucrc32(buf[i],crc); }
        !           242:                smb_fwrite(&smb,buf,j,smb.sdt_fp);
        !           243:                x=SDT_BLOCK_LEN; }
        !           244:        smb_fflush(smb.sdt_fp);
        !           245:        fclose(instream);
        !           246:        crc=~crc;
        !           247: 
        !           248:        memset(&msg,0,sizeof(smbmsg_t));
        !           249:        msg.hdr.version=smb_ver();
        !           250:        msg.hdr.attr=msgattr;
        !           251:        if(mode&WM_FILE)
        !           252:                msg.hdr.auxattr|=MSG_FILEATTACH;
        !           253:        msg.hdr.when_written.time=msg.hdr.when_imported.time=time(NULL);
        !           254:        msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone(&cfg);
        !           255: 
        !           256:        if(cfg.mail_maxcrcs) {
        !           257:                i=smb_addcrc(&smb,crc);
        !           258:                if(i) {
        !           259:                        smb_freemsgdat(&smb,offset,length,1);
        !           260:                        smb_unlocksmbhdr(&smb);
        !           261:                        smb_close(&smb);
        !           262:                        smb_stack(&smb,SMB_STACK_POP);
        !           263:                        attr(cfg.color[clr_err]);
        !           264:                        bputs("Duplicate message!\r\n");
        !           265:                        return(false); 
        !           266:                } 
        !           267:        }
        !           268: 
        !           269:        msg.hdr.offset=offset;
        !           270: 
        !           271:        username(&cfg,usernumber,str);
        !           272:        smb_hfield_str(&msg,RECIPIENT,str);
        !           273: 
        !           274:        sprintf(str,"%u",usernumber);
        !           275:        smb_hfield_str(&msg,RECIPIENTEXT,str);
        !           276: 
        !           277:        strcpy(str,useron.alias);
        !           278:        smb_hfield_str(&msg,SENDER,str);
        !           279: 
        !           280:        sprintf(str,"%u",useron.number);
        !           281:        smb_hfield_str(&msg,SENDEREXT,str);
        !           282: 
        !           283:        if(useron.misc&NETMAIL) {
        !           284:                nettype=smb_netaddr_type(useron.netmail);
        !           285:                if(nettype!=NET_NONE && nettype!=NET_UNKNOWN) {
        !           286:                        smb_hfield(&msg,REPLYTONETTYPE,sizeof(nettype),&nettype);
        !           287:                        smb_hfield_str(&msg,REPLYTONETADDR,useron.netmail);
        !           288:                }
        !           289:        }
        !           290: 
        !           291:        /* Security logging */
        !           292:        msg_client_hfields(&msg,&client);
        !           293: 
        !           294:        smb_hfield_str(&msg,SUBJECT,title);
        !           295: 
        !           296:        smb_dfield(&msg,TEXT_BODY,length);
        !           297: 
        !           298:        i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); // calls smb_unlocksmbhdr() 
        !           299:        smb_close(&smb);
        !           300:        smb_stack(&smb,SMB_STACK_POP);
        !           301: 
        !           302:        smb_freemsgmem(&msg);
        !           303:        if(i!=SMB_SUCCESS) {
        !           304:                smb_freemsgdat(&smb,offset,length,1);
        !           305:                errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
        !           306:                return(false); 
        !           307:        }
        !           308: 
        !           309:        if(usernumber==1)
        !           310:                logon_fbacks++;
        !           311:        else
        !           312:                logon_emails++;
        !           313:        user_sent_email(&cfg, &useron, 1, usernumber==1);
        !           314:        bprintf(text[Emailed],username(&cfg,usernumber,tmp),usernumber);
        !           315:        sprintf(str,"%s sent e-mail to %s #%d"
        !           316:                ,useron.alias,username(&cfg,usernumber,tmp),usernumber);
        !           317:        logline("E+",str);
        !           318:        if(mode&WM_FILE && online==ON_REMOTE)
        !           319:                autohangup();
        !           320:        if(msgattr&MSG_ANONYMOUS)                               /* Don't tell user if anonymous */
        !           321:                return(true);
        !           322:        for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */
        !           323:                getnodedat(i,&node,0);
        !           324:                if(node.useron==usernumber && !(node.misc&NODE_POFF)
        !           325:                        && (node.status==NODE_INUSE || node.status==NODE_QUIET)) {
        !           326:                        sprintf(str,text[EmailNodeMsg],cfg.node_num,useron.alias);
        !           327:                        putnmsg(&cfg,i,str);
        !           328:                        break; } }
        !           329:        if(i>cfg.sys_nodes) {   /* User wasn't online, so leave short msg */
        !           330:                sprintf(str,text[UserSentYouMail],useron.alias);
        !           331:                putsmsg(&cfg,usernumber,str); }
        !           332:        return(true);
        !           333: }

unix.superglobalmegacorp.com

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