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