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