|
|
1.1 root 1: /* bulkmail.cpp */
2:
3: /* Synchronet bulk e-mail functions */
4:
1.1.1.2 ! root 5: /* $Id: bulkmail.cpp,v 1.25 2004/11/17 01:52:34 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 2004 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:
39: #include "sbbs.h"
40:
1.1.1.2 ! root 41: bool sbbs_t::bulkmail(uchar *ar)
1.1 root 42: {
1.1.1.2 ! root 43: char str[256],title[LEN_TITLE+1];
! 44: char msgpath[MAX_PATH+1];
! 45: char* msgbuf;
! 46: char tmp[512];
! 47: int i,j,x;
! 48: long msgs=0;
! 49: long length;
! 50: FILE* fp;
! 51: smb_t smb;
! 52: smbmsg_t msg;
! 53: user_t user;
1.1 root 54:
1.1.1.2 ! root 55: memset(&msg,0,sizeof(msg));
! 56:
1.1 root 57: title[0]=0;
58: action=NODE_SMAL;
59: nodesync();
60:
1.1.1.2 ! root 61: if(cfg.sys_misc&SM_ANON_EM && useron.exempt&FLAG('A')
1.1 root 62: && !noyes(text[AnonymousQ]))
1.1.1.2 ! root 63: msg.hdr.attr|=MSG_ANONYMOUS;
1.1 root 64:
1.1.1.2 ! root 65: sprintf(msgpath,"%sinput.msg",cfg.node_dir);
! 66: if(!writemsg(msgpath,nulstr,title,WM_EMAIL,INVALID_SUB,"Bulk Mailing")) {
1.1 root 67: bputs(text[Aborted]);
1.1.1.2 ! root 68: return(false);
! 69: }
! 70:
! 71: if((fp=fopen(msgpath,"r"))==NULL) {
! 72: errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY);
! 73: return(false);
! 74: }
! 75:
! 76: if((length=filelength(fileno(fp)))<=0) {
! 77: fclose(fp);
! 78: return(false);
! 79: }
1.1 root 80:
81: bputs(text[WritingIndx]);
82: CRLF;
83:
1.1.1.2 ! root 84: if((msgbuf=(char*)malloc(length+1))==NULL) {
! 85: errormsg(WHERE,ERR_ALLOC,msgpath,length+1);
! 86: return(false);
! 87: }
! 88: length=fread(msgbuf,sizeof(char),length,fp);
! 89: fclose(fp);
! 90: if(length<0) {
! 91: free(msgbuf);
! 92: errormsg(WHERE,ERR_READ,msgpath,length);
! 93: return(false);
! 94: }
! 95: msgbuf[length]=0; /* ASCIIZ */
1.1 root 96:
1.1.1.2 ! root 97: smb_hfield_str(&msg,SENDER,useron.alias);
1.1 root 98:
1.1.1.2 ! root 99: sprintf(str,"%u",useron.number);
! 100: smb_hfield_str(&msg,SENDEREXT,str);
! 101: msg.idx.from=useron.number;
1.1 root 102:
1.1.1.2 ! root 103: smb_hfield_str(&msg,SUBJECT,title);
! 104: msg.idx.subj=smb_subject_crc(title);
1.1 root 105:
1.1.1.2 ! root 106: msg.hdr.when_written.time=time(NULL);
! 107: msg.hdr.when_written.zone=sys_timezone(&cfg);
1.1 root 108:
1.1.1.2 ! root 109: memset(&smb,0,sizeof(smb));
! 110: smb.subnum=INVALID_SUB; /* mail database */
! 111: i=savemsg(&cfg, &smb, &msg, &client, msgbuf);
! 112: free(msgbuf);
! 113: if(i!=0) {
1.1 root 114: smb_close(&smb);
1.1.1.2 ! root 115: smb_freemsgmem(&msg);
! 116: return(false);
! 117: }
1.1 root 118:
119: j=lastuser(&cfg);
120:
121: if(*ar)
122: for(i=1;i<=j;i++) {
123: user.number=i;
1.1.1.2 ! root 124: if(getuserdat(&cfg, &user)!=0)
! 125: continue;
1.1 root 126: if(user.misc&(DELETED|INACTIVE))
127: continue;
128: if(chk_ar(ar,&user)) {
1.1.1.2 ! root 129: if((x=bulkmailhdr(&smb, &msg, i))!=SMB_SUCCESS) {
! 130: errormsg(WHERE,ERR_WRITE,smb.file,x);
1.1 root 131: break;
1.1.1.2 ! root 132: }
1.1 root 133: msgs++;
1.1.1.2 ! root 134: }
! 135: }
1.1 root 136: else
1.1.1.2 ! root 137: while(online) {
1.1 root 138: bputs(text[EnterAfterLastDestUser]);
1.1.1.2 ! root 139: if(!getstr(str,LEN_ALIAS,cfg.uq&UQ_NOUPRLWR ? K_NONE:K_UPRLWR))
1.1 root 140: break;
141: if((i=finduser(str))!=0) {
1.1.1.2 ! root 142: if((x=bulkmailhdr(&smb, &msg, i))!=SMB_SUCCESS) {
! 143: errormsg(WHERE,ERR_WRITE,smb.file,x);
1.1 root 144: break;
1.1.1.2 ! root 145: }
! 146: msgs++;
! 147: }
! 148: }
! 149:
! 150: if((i=smb_open_da(&smb))==SMB_SUCCESS) {
! 151: if(!msgs)
! 152: smb_freemsg_dfields(&smb,&msg,SMB_ALL_REFS);
! 153: else if(msgs>1)
! 154: smb_incmsg_dfields(&smb,&msg,(ushort)msgs-1);
! 155: smb_close_da(&smb);
! 156: }
1.1 root 157:
158: smb_close(&smb);
159: smb_freemsgmem(&msg);
1.1.1.2 ! root 160:
! 161: if(i!=SMB_SUCCESS) {
! 162: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
! 163: return(false);
! 164: }
1.1 root 165:
166: putuserrec(&cfg,useron.number,U_EMAILS,5,ultoa(useron.emails,tmp,10));
167: putuserrec(&cfg,useron.number,U_ETODAY,5,ultoa(useron.etoday,tmp,10));
1.1.1.2 ! root 168:
! 169: return(true);
1.1 root 170: }
171:
172:
1.1.1.2 ! root 173: int sbbs_t::bulkmailhdr(smb_t* smb, smbmsg_t* msg, uint usernum)
1.1 root 174: {
1.1.1.2 ! root 175: char str[256];
! 176: int i,j;
! 177: ushort nettype=NET_UNKNOWN;
! 178: node_t node;
! 179: user_t user;
! 180: smbmsg_t newmsg;
! 181:
! 182: user.number=usernum;
! 183: if(getuserdat(&cfg, &user)!=0)
! 184: return(0);
! 185:
! 186: if((i=smb_copymsgmem(NULL,&newmsg,msg))!=SMB_SUCCESS)
! 187: return(i);
! 188:
! 189: SAFECOPY(str,user.alias);
! 190: smb_hfield_str(&newmsg,RECIPIENT,str);
! 191:
! 192: if(cfg.sys_misc&SM_FWDTONET && user.misc&NETMAIL && user.netmail[0]) {
! 193: bprintf(text[UserNetMail],user.netmail);
! 194: smb_hfield_netaddr(&newmsg,RECIPIENTNETADDR,user.netmail,&nettype);
! 195: smb_hfield_bin(&newmsg,RECIPIENTNETTYPE,nettype);
! 196: } else {
! 197: sprintf(str,"%u",usernum);
! 198: smb_hfield_str(&newmsg,RECIPIENTEXT,str);
! 199: newmsg.idx.to=usernum;
! 200: }
! 201:
! 202: j=smb_addmsghdr(smb,&newmsg,SMB_SELFPACK);
! 203: smb_freemsgmem(&newmsg);
! 204: if(j!=SMB_SUCCESS)
1.1 root 205: return(j);
206:
207: lncntr=0;
1.1.1.2 ! root 208: bprintf(text[Emailing],user.alias,usernum);
! 209: sprintf(str,"%s bulk-mailed %s #%d"
! 210: ,useron.alias,user.alias,usernum);
1.1 root 211: logline("E+",str);
212: useron.emails++;
213: logon_emails++;
214: useron.etoday++;
215: for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */
216: getnodedat(i,&node,0);
217: if(node.useron==usernum && !(node.misc&NODE_POFF)
218: && (node.status==NODE_INUSE || node.status==NODE_QUIET)) {
219: sprintf(str,text[EmailNodeMsg],cfg.node_num,useron.alias);
1.1.1.2 ! root 220: putnmsg(&cfg,i,str);
! 221: break;
! 222: }
! 223: }
1.1 root 224: if(i>cfg.sys_nodes) { /* User wasn't online, so leave short msg */
225: sprintf(str,text[UserSentYouMail],useron.alias);
1.1.1.2 ! root 226: putsmsg(&cfg,usernum,str);
! 227: }
1.1 root 228: return(0);
229: }
230:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.