|
|
1.1 ! root 1: /* email.cpp */ ! 2: ! 3: /* Synchronet email function - for sending private e-mail */ ! 4: ! 5: /* $Id: email.cpp,v 1.4 2000/12/11 23:21:11 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 2000 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: int i,j,x,file; ! 53: long l; ! 54: ulong length,offset,crc=0xffffffffUL; ! 55: FILE *instream; ! 56: node_t node; ! 57: smbmsg_t msg; ! 58: ! 59: sprintf(title,"%.*s",LEN_TITLE,subj); ! 60: ! 61: if(useron.etoday>=cfg.level_emailperday[useron.level] && !SYSOP) { ! 62: bputs(text[TooManyEmailsToday]); ! 63: return(false); } ! 64: ! 65: if(usernumber==1 && useron.rest&FLAG('S') ! 66: && (cfg.node_valuser!=1 || useron.fbacks || useron.emails)) { /* ! val fback */ ! 67: bprintf(text[R_Feedback],cfg.sys_op); ! 68: return(false); } ! 69: if(usernumber!=1 && useron.rest&FLAG('E') ! 70: && (cfg.node_valuser!=usernumber || useron.fbacks || useron.emails)) { ! 71: bputs(text[R_Email]); ! 72: return(false); } ! 73: if(!usernumber) { ! 74: bputs(text[UnknownUser]); ! 75: return(false); } ! 76: getuserrec(&cfg,usernumber,U_MISC,8,str); ! 77: l=ahtoul(str); ! 78: if(l&(DELETED|INACTIVE)) { /* Deleted or Inactive User */ ! 79: bputs(text[UnknownUser]); ! 80: return(false); } ! 81: if(l&NETMAIL && cfg.sys_misc&SM_FWDTONET ! 82: && yesno(text[ForwardMailQ])) { /* Forward to netmail address */ ! 83: getuserrec(&cfg,usernumber,U_NETMAIL,LEN_NETMAIL,str); ! 84: netmail(str,subj,mode); ! 85: return(false); } ! 86: bprintf(text[Emailing],username(&cfg,usernumber,tmp),usernumber); ! 87: action=NODE_SMAL; ! 88: nodesync(); ! 89: ! 90: sprintf(str,"%sFEEDBACK.BIN", cfg.exec_dir); ! 91: if(usernumber==1 && useron.fbacks && fexist(str)) { ! 92: exec_bin("FEEDBACK",&main_csi); ! 93: if(main_csi.logic!=LOGIC_TRUE) ! 94: return(false); } ! 95: ! 96: if(cfg.sys_misc&SM_ANON_EM && useron.exempt&FLAG('A') ! 97: && !noyes(text[AnonymousQ])) ! 98: msgattr|=MSG_ANONYMOUS; ! 99: ! 100: if(cfg.sys_misc&SM_DELREADM) ! 101: msgattr|=MSG_KILLREAD; ! 102: ! 103: sprintf(msgpath,"%sINPUT.MSG", cfg.node_dir); ! 104: #if 0 // Removed 01/06/00 (for external editor information) ! 105: sprintf(str2,"%s #%u",username(&cfg,usernumber,tmp),usernumber); ! 106: #else ! 107: username(&cfg,usernumber,str2); ! 108: #endif ! 109: if(!writemsg(msgpath,top,title,mode,0,str2)) { ! 110: bputs(text[Aborted]); ! 111: return(false); } ! 112: ! 113: if(mode&WM_FILE) { ! 114: sprintf(str2,"%sfile/%04u.in", cfg.data_dir,usernumber); ! 115: _mkdir(str2); ! 116: sprintf(str2,"%sfile/%04u.in/%s", cfg.data_dir,usernumber,title); ! 117: if(fexist(str2)) { ! 118: bputs(text[FileAlreadyThere]); ! 119: remove(msgpath); ! 120: return(false); } ! 121: if(online==ON_LOCAL) { /* Local upload */ ! 122: bputs(text[EnterPath]); ! 123: if(!getstr(str,60,K_LINE|K_UPPER)) { ! 124: bputs(text[Aborted]); ! 125: remove(msgpath); ! 126: return(false); } ! 127: backslash(str); ! 128: strcat(str,title); ! 129: mv(str,str2,1); } ! 130: else { /* Remote */ ! 131: menu("ulprot"); ! 132: mnemonics(text[ProtocolOrQuit]); ! 133: strcpy(str,"Q"); ! 134: for(x=0;x<cfg.total_prots;x++) ! 135: if(cfg.prot[x]->ulcmd[0] && chk_ar(cfg.prot[x]->ar,&useron)) { ! 136: sprintf(tmp,"%c",cfg.prot[x]->mnemonic); ! 137: strcat(str,tmp); } ! 138: ch=(char)getkeys(str,0); ! 139: if(ch=='Q' || sys_status&SS_ABORT) { ! 140: bputs(text[Aborted]); ! 141: remove(msgpath); ! 142: return(false); } ! 143: for(x=0;x<cfg.total_prots;x++) ! 144: if(cfg.prot[x]->ulcmd[0] && cfg.prot[x]->mnemonic==ch ! 145: && chk_ar(cfg.prot[x]->ar,&useron)) ! 146: break; ! 147: if(x<cfg.total_prots) /* This should be always */ ! 148: protocol(cmdstr(cfg.prot[x]->ulcmd,str2,nulstr,NULL),0); } ! 149: l=flength(str2); ! 150: if(l>0) ! 151: bprintf(text[FileNBytesReceived],title,ultoac(l,tmp)); ! 152: else { ! 153: bprintf(text[FileNotReceived],title); ! 154: remove(msgpath); ! 155: return(false); } } ! 156: ! 157: bputs(text[WritingIndx]); ! 158: ! 159: if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) { ! 160: errormsg(WHERE,ERR_OPEN,"MAIL",i); ! 161: return(false); } ! 162: sprintf(smb.file,"%smail", cfg.data_dir); ! 163: smb.retry_time=cfg.smb_retry_time; ! 164: if((i=smb_open(&smb))!=0) { ! 165: smb_stack(&smb,SMB_STACK_POP); ! 166: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); ! 167: return(false); } ! 168: ! 169: if(smb_fgetlength(smb.shd_fp)<1) { /* Create it if it doesn't exist */ ! 170: smb.status.max_crcs=cfg.mail_maxcrcs; ! 171: smb.status.max_age=cfg.mail_maxage; ! 172: smb.status.max_msgs=MAX_SYSMAIL; ! 173: smb.status.attr=SMB_EMAIL; ! 174: if((i=smb_create(&smb))!=0) { ! 175: smb_close(&smb); ! 176: smb_stack(&smb,SMB_STACK_POP); ! 177: errormsg(WHERE,ERR_CREATE,smb.file,i,smb.last_error); ! 178: return(false); } } ! 179: ! 180: if((i=smb_locksmbhdr(&smb))!=0) { ! 181: smb_close(&smb); ! 182: smb_stack(&smb,SMB_STACK_POP); ! 183: errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error); ! 184: return(false); } ! 185: ! 186: length=flength(msgpath)+2; /* +2 for translation string */ ! 187: ! 188: if(length&0xfff00000UL) { ! 189: smb_unlocksmbhdr(&smb); ! 190: smb_close(&smb); ! 191: smb_stack(&smb,SMB_STACK_POP); ! 192: errormsg(WHERE,ERR_LEN,msgpath,length); ! 193: return(false); } ! 194: ! 195: if((i=smb_open_da(&smb))!=0) { ! 196: smb_unlocksmbhdr(&smb); ! 197: smb_close(&smb); ! 198: smb_stack(&smb,SMB_STACK_POP); ! 199: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); ! 200: return(false); } ! 201: if(cfg.sys_misc&SM_FASTMAIL) ! 202: offset=smb_fallocdat(&smb,length,1); ! 203: else ! 204: offset=smb_allocdat(&smb,length,1); ! 205: smb_close_da(&smb); ! 206: ! 207: if((file=open(msgpath,O_RDONLY|O_BINARY))==-1 ! 208: || (instream=fdopen(file,"rb"))==NULL) { ! 209: smb_freemsgdat(&smb,offset,length,1); ! 210: smb_unlocksmbhdr(&smb); ! 211: smb_close(&smb); ! 212: smb_stack(&smb,SMB_STACK_POP); ! 213: errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY); ! 214: return(false); } ! 215: ! 216: setvbuf(instream,NULL,_IOFBF,2*1024); ! 217: smb_fseek(smb.sdt_fp,offset,SEEK_SET); ! 218: xlat=XLAT_NONE; ! 219: smb_fwrite(&xlat,2,smb.sdt_fp); ! 220: x=SDT_BLOCK_LEN-2; /* Don't read/write more than 255 */ ! 221: while(!feof(instream)) { ! 222: memset(buf,0,x); ! 223: j=fread(buf,1,x,instream); ! 224: if((j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR) ! 225: buf[j-1]=buf[j-2]=0; ! 226: if(cfg.mail_maxcrcs) { ! 227: for(i=0;i<j;i++) ! 228: crc=ucrc32(buf[i],crc); } ! 229: smb_fwrite(buf,j,smb.sdt_fp); ! 230: x=SDT_BLOCK_LEN; } ! 231: smb_fflush(smb.sdt_fp); ! 232: fclose(instream); ! 233: crc=~crc; ! 234: ! 235: memset(&msg,0,sizeof(smbmsg_t)); ! 236: memcpy(msg.hdr.id,"SHD\x1a",4); ! 237: msg.hdr.version=smb_ver(); ! 238: msg.hdr.attr=msg.idx.attr=msgattr; ! 239: if(mode&WM_FILE) ! 240: msg.hdr.auxattr|=MSG_FILEATTACH; ! 241: msg.hdr.when_written.time=msg.hdr.when_imported.time=time(NULL); ! 242: msg.hdr.when_written.zone=msg.hdr.when_imported.zone=cfg.sys_timezone; ! 243: ! 244: if(cfg.mail_maxcrcs) { ! 245: i=smb_addcrc(&smb,crc); ! 246: if(i) { ! 247: smb_freemsgdat(&smb,offset,length,1); ! 248: smb_unlocksmbhdr(&smb); ! 249: smb_close(&smb); ! 250: smb_stack(&smb,SMB_STACK_POP); ! 251: bputs("\1r\1h\1iDuplicate message!\r\n"); ! 252: return(false); } } ! 253: ! 254: msg.hdr.offset=offset; ! 255: ! 256: username(&cfg,usernumber,str); ! 257: smb_hfield(&msg,RECIPIENT,strlen(str),str); ! 258: ! 259: sprintf(str,"%u",usernumber); ! 260: smb_hfield(&msg,RECIPIENTEXT,strlen(str),str); ! 261: msg.idx.to=usernumber; ! 262: ! 263: strcpy(str,useron.alias); ! 264: smb_hfield(&msg,SENDER,strlen(str),str); ! 265: ! 266: sprintf(str,"%u",useron.number); ! 267: smb_hfield(&msg,SENDEREXT,strlen(str),str); ! 268: msg.idx.from=useron.number; ! 269: ! 270: smb_hfield(&msg,SUBJECT,strlen(title),title); ! 271: strlwr(title); ! 272: msg.idx.subj=crc16(title); ! 273: ! 274: smb_dfield(&msg,TEXT_BODY,length); ! 275: ! 276: smb_unlocksmbhdr(&smb); ! 277: i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); ! 278: smb_close(&smb); ! 279: smb_stack(&smb,SMB_STACK_POP); ! 280: ! 281: smb_freemsgmem(&msg); ! 282: if(i) { ! 283: smb_freemsgdat(&smb,offset,length,1); ! 284: errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); ! 285: return(false); } ! 286: ! 287: if(usernumber==1) { ! 288: useron.fbacks++; ! 289: logon_fbacks++; ! 290: putuserrec(&cfg,useron.number,U_FBACKS,5,ultoa(useron.fbacks,tmp,10)); } ! 291: else { ! 292: useron.emails++; ! 293: logon_emails++; ! 294: putuserrec(&cfg,useron.number,U_EMAILS,5,ultoa(useron.emails,tmp,10)); } ! 295: useron.etoday++; ! 296: putuserrec(&cfg,useron.number,U_ETODAY,5,ultoa(useron.etoday,tmp,10)); ! 297: bprintf(text[Emailed],username(&cfg,usernumber,tmp),usernumber); ! 298: sprintf(str,"E-mailed %s #%d",username(&cfg,usernumber,tmp),usernumber); ! 299: logline("E+",str); ! 300: if(mode&WM_FILE && online==ON_REMOTE) ! 301: autohangup(); ! 302: if(msgattr&MSG_ANONYMOUS) /* Don't tell user if anonymous */ ! 303: return(true); ! 304: for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */ ! 305: getnodedat(i,&node,0); ! 306: if(node.useron==usernumber && !(node.misc&NODE_POFF) ! 307: && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { ! 308: sprintf(str,text[EmailNodeMsg],cfg.node_num,useron.alias); ! 309: putnmsg(i,str); ! 310: break; } } ! 311: if(i>cfg.sys_nodes) { /* User wasn't online, so leave short msg */ ! 312: sprintf(str,text[UserSentYouMail],useron.alias); ! 313: putsmsg(&cfg,usernumber,str); } ! 314: return(true); ! 315: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.