|
|
1.1 ! root 1: /* bulkmail.cpp */ ! 2: ! 3: /* Synchronet bulk e-mail functions */ ! 4: ! 5: /* $Id: bulkmail.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: ! 39: #include "sbbs.h" ! 40: ! 41: void sbbs_t::bulkmail(uchar *ar) ! 42: { ! 43: char str[256],str2[256],msgpath[256],title[LEN_TITLE+1] ! 44: ,buf[SDT_BLOCK_LEN],found=0; ! 45: char tmp[512]; ! 46: ushort xlat=XLAT_NONE,msgattr=0; ! 47: int i,j,x,file; ! 48: long msgs=0; ! 49: ulong length,offset; ! 50: FILE *instream; ! 51: user_t user; ! 52: smbmsg_t msg; ! 53: ! 54: memset(&msg,0,sizeof(smbmsg_t)); ! 55: ! 56: title[0]=0; ! 57: action=NODE_SMAL; ! 58: nodesync(); ! 59: ! 60: if(cfg.sys_misc&SM_ANON_EM && (SYSOP || useron.exempt&FLAG('A')) ! 61: && !noyes(text[AnonymousQ])) ! 62: msgattr|=MSG_ANONYMOUS; ! 63: ! 64: sprintf(msgpath,"%sINPUT.MSG",cfg.node_dir); ! 65: sprintf(str2,"Bulk Mailing"); ! 66: if(!writemsg(msgpath,nulstr,title,WM_EMAIL,0,str2)) { ! 67: bputs(text[Aborted]); ! 68: return; } ! 69: ! 70: bputs(text[WritingIndx]); ! 71: CRLF; ! 72: ! 73: if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) { ! 74: errormsg(WHERE,ERR_OPEN,"MAIL",i); ! 75: return; } ! 76: sprintf(smb.file,"%smail",cfg.data_dir); ! 77: smb.retry_time=cfg.smb_retry_time; ! 78: if((i=smb_open(&smb))!=0) { ! 79: smb_stack(&smb,SMB_STACK_POP); ! 80: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); ! 81: return; } ! 82: ! 83: if(smb_fgetlength(smb.shd_fp)<1) { /* Create it if it doesn't exist */ ! 84: smb.status.max_crcs=cfg.mail_maxcrcs; ! 85: smb.status.max_msgs=MAX_SYSMAIL; ! 86: smb.status.max_age=cfg.mail_maxage; ! 87: smb.status.attr=SMB_EMAIL; ! 88: if((i=smb_create(&smb))!=0) { ! 89: smb_close(&smb); ! 90: smb_stack(&smb,SMB_STACK_POP); ! 91: errormsg(WHERE,ERR_CREATE,smb.file,i,smb.last_error); ! 92: return; } } ! 93: ! 94: length=flength(msgpath)+2; /* +2 for translation string */ ! 95: ! 96: if(length&0xfff00000UL) { ! 97: smb_close(&smb); ! 98: smb_stack(&smb,SMB_STACK_POP); ! 99: errormsg(WHERE,ERR_LEN,smb.file,length); ! 100: return; } ! 101: ! 102: if((i=smb_open_da(&smb))!=0) { ! 103: smb_close(&smb); ! 104: smb_stack(&smb,SMB_STACK_POP); ! 105: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); ! 106: return; } ! 107: if(cfg.sys_misc&SM_FASTMAIL) ! 108: offset=smb_fallocdat(&smb,length,1); ! 109: else ! 110: offset=smb_allocdat(&smb,length,1); ! 111: smb_close_da(&smb); ! 112: ! 113: if((file=open(msgpath,O_RDONLY|O_BINARY))==-1 ! 114: || (instream=fdopen(file,"rb"))==NULL) { ! 115: smb_freemsgdat(&smb,offset,length,1); ! 116: smb_close(&smb); ! 117: smb_stack(&smb,SMB_STACK_POP); ! 118: errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY); ! 119: return; } ! 120: ! 121: setvbuf(instream,NULL,_IOFBF,2*1024); ! 122: smb_fseek(smb.sdt_fp,offset,SEEK_SET); ! 123: xlat=XLAT_NONE; ! 124: smb_fwrite(&xlat,2,smb.sdt_fp); ! 125: x=SDT_BLOCK_LEN-2; /* Don't read/write more than 255 */ ! 126: while(!feof(instream)) { ! 127: memset(buf,0,x); ! 128: j=fread(buf,1,x,instream); ! 129: if((j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR) ! 130: buf[j-1]=buf[j-2]=0; ! 131: smb_fwrite(buf,j,smb.sdt_fp); ! 132: x=SDT_BLOCK_LEN; } ! 133: smb_fflush(smb.sdt_fp); ! 134: fclose(instream); ! 135: ! 136: j=lastuser(&cfg); ! 137: x=0; ! 138: ! 139: if(*ar) ! 140: for(i=1;i<=j;i++) { ! 141: user.number=i; ! 142: getuserdat(&cfg, &user); ! 143: if(user.misc&(DELETED|INACTIVE)) ! 144: continue; ! 145: if(chk_ar(ar,&user)) { ! 146: if(found) ! 147: smb_freemsgmem(&msg); ! 148: x=bulkmailhdr(i,&msg,msgattr,offset,length,title); ! 149: if(x) ! 150: break; ! 151: msgs++; ! 152: found=1; } } ! 153: else ! 154: while(1) { ! 155: bputs(text[EnterAfterLastDestUser]); ! 156: if(!getstr(str,LEN_ALIAS,K_UPRLWR)) ! 157: break; ! 158: if((i=finduser(str))!=0) { ! 159: if(found) ! 160: smb_freemsgmem(&msg); ! 161: x=bulkmailhdr(i,&msg,msgattr,offset,length,title); ! 162: if(x) ! 163: break; ! 164: msgs++; } ! 165: found=1; } ! 166: ! 167: if((i=smb_open_da(&smb))!=0) { ! 168: smb_close(&smb); ! 169: smb_stack(&smb,SMB_STACK_POP); ! 170: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error); ! 171: return; } ! 172: if(!msgs) ! 173: smb_freemsgdat(&smb,offset,length,1); ! 174: else if(msgs>1) ! 175: smb_incdat(&smb,offset,length,msgs-1); ! 176: smb_close_da(&smb); ! 177: ! 178: smb_close(&smb); ! 179: smb_stack(&smb,SMB_STACK_POP); ! 180: ! 181: smb_freemsgmem(&msg); ! 182: if(x) { ! 183: smb_freemsgdat(&smb,offset,length,1); ! 184: errormsg(WHERE,ERR_WRITE,smb.file,x); ! 185: return; } ! 186: ! 187: putuserrec(&cfg,useron.number,U_EMAILS,5,ultoa(useron.emails,tmp,10)); ! 188: putuserrec(&cfg,useron.number,U_ETODAY,5,ultoa(useron.etoday,tmp,10)); ! 189: } ! 190: ! 191: ! 192: int sbbs_t::bulkmailhdr(uint usernum, smbmsg_t *msg, ushort msgattr, ulong offset ! 193: , ulong length, char *title) ! 194: { ! 195: char str[256]; ! 196: char tmp[512]; ! 197: int i,j; ! 198: node_t node; ! 199: ! 200: memset(msg,0,sizeof(smbmsg_t)); ! 201: memcpy(msg->hdr.id,"SHD\x1a",4); ! 202: msg->hdr.version=smb_ver(); ! 203: msg->hdr.attr=msg->idx.attr=msgattr; ! 204: msg->hdr.when_written.time=msg->hdr.when_imported.time=time(NULL); ! 205: msg->hdr.when_written.zone=msg->hdr.when_imported.zone=cfg.sys_timezone; ! 206: msg->hdr.offset=msg->idx.offset=offset; ! 207: ! 208: username(&cfg, usernum,str); ! 209: smb_hfield(msg,RECIPIENT,strlen(str),str); ! 210: strlwr(str); ! 211: ! 212: sprintf(str,"%u",usernum); ! 213: smb_hfield(msg,RECIPIENTEXT,strlen(str),str); ! 214: msg->idx.to=usernum; ! 215: ! 216: strcpy(str,useron.alias); ! 217: smb_hfield(msg,SENDER,strlen(str),str); ! 218: strlwr(str); ! 219: ! 220: sprintf(str,"%u",useron.number); ! 221: smb_hfield(msg,SENDEREXT,strlen(str),str); ! 222: msg->idx.from=useron.number; ! 223: ! 224: strcpy(str,title); ! 225: smb_hfield(msg,SUBJECT,strlen(str),str); ! 226: strlwr(str); ! 227: msg->idx.subj=crc16(str); ! 228: ! 229: smb_dfield(msg,TEXT_BODY,length); ! 230: ! 231: j=smb_addmsghdr(&smb,msg,SMB_SELFPACK); ! 232: if(j) ! 233: return(j); ! 234: ! 235: // smb_incdat(&smb,offset,length,1); Remove 04/15/96 ! 236: lncntr=0; ! 237: bprintf("Bulk Mailed %s #%d\r\n",username(&cfg, usernum,tmp),usernum); ! 238: sprintf(str,"Bulk Mailed %s #%d",username(&cfg, usernum,tmp),usernum); ! 239: logline("E+",str); ! 240: useron.emails++; ! 241: logon_emails++; ! 242: useron.etoday++; ! 243: for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */ ! 244: getnodedat(i,&node,0); ! 245: if(node.useron==usernum && !(node.misc&NODE_POFF) ! 246: && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { ! 247: sprintf(str,text[EmailNodeMsg],cfg.node_num,useron.alias); ! 248: putnmsg(i,str); ! 249: break; } } ! 250: if(i>cfg.sys_nodes) { /* User wasn't online, so leave short msg */ ! 251: sprintf(str,text[UserSentYouMail],useron.alias); ! 252: putsmsg(&cfg,usernum,str); } ! 253: return(0); ! 254: } ! 255:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.