Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit ee4e10fc authored by rswindell's avatar rswindell

Totally over-hauled bulkmail() function: now uses savemsg() hi-level function,

new smblib functions, and supports auto-forwarding to netmail addresses.
parent 8ded4165
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -38,103 +38,81 @@
#include "sbbs.h"
void sbbs_t::bulkmail(uchar *ar)
bool sbbs_t::bulkmail(uchar *ar)
{
char str[256],str2[256],msgpath[256],title[LEN_TITLE+1]
,buf[SDT_BLOCK_LEN],found=0;
char tmp[512];
ushort xlat=XLAT_NONE,msgattr=0;
int i,j,x,file;
long msgs=0;
ulong length,offset;
FILE *instream;
user_t user;
smbmsg_t msg;
memset(&msg,0,sizeof(smbmsg_t));
char str[256],title[LEN_TITLE+1];
char msgpath[MAX_PATH+1];
char* msgbuf;
char tmp[512];
ushort xlat=XLAT_NONE;
int i,j,x;
long msgs=0;
long length;
FILE* fp;
smb_t smb;
smbmsg_t msg;
user_t user;
memset(&msg,0,sizeof(msg));
title[0]=0;
action=NODE_SMAL;
nodesync();
if(cfg.sys_misc&SM_ANON_EM && (SYSOP || useron.exempt&FLAG('A'))
if(cfg.sys_misc&SM_ANON_EM && useron.exempt&FLAG('A')
&& !noyes(text[AnonymousQ]))
msgattr|=MSG_ANONYMOUS;
msg.hdr.attr|=MSG_ANONYMOUS;
sprintf(msgpath,"%sINPUT.MSG",cfg.node_dir);
sprintf(str2,"Bulk Mailing");
if(!writemsg(msgpath,nulstr,title,WM_EMAIL,INVALID_SUB,str2)) {
sprintf(msgpath,"%sinput.msg",cfg.node_dir);
if(!writemsg(msgpath,nulstr,title,WM_EMAIL,INVALID_SUB,"Bulk Mailing")) {
bputs(text[Aborted]);
return; }
return(false);
}
if((fp=fopen(msgpath,"r"))==NULL) {
errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY);
return(false);
}
if((length=filelength(fileno(fp)))<=0) {
fclose(fp);
return(false);
}
bputs(text[WritingIndx]);
CRLF;
if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) {
errormsg(WHERE,ERR_OPEN,"MAIL",i);
return; }
sprintf(smb.file,"%smail",cfg.data_dir);
smb.retry_time=cfg.smb_retry_time;
smb.subnum=INVALID_SUB;
if((i=smb_open(&smb))!=0) {
smb_stack(&smb,SMB_STACK_POP);
errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
return; }
if(smb_fgetlength(smb.shd_fp)<1) { /* Create it if it doesn't exist */
smb.status.max_crcs=cfg.mail_maxcrcs;
smb.status.max_msgs=MAX_SYSMAIL;
smb.status.max_age=cfg.mail_maxage;
smb.status.attr=SMB_EMAIL;
if((i=smb_create(&smb))!=0) {
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
errormsg(WHERE,ERR_CREATE,smb.file,i,smb.last_error);
return; } }
length=flength(msgpath)+2; /* +2 for translation string */
if(length&0xfff00000UL) {
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
errormsg(WHERE,ERR_LEN,smb.file,length);
return; }
if((msgbuf=(char*)malloc(length+1))==NULL) {
errormsg(WHERE,ERR_ALLOC,msgpath,length+1);
return(false);
}
length=fread(msgbuf,sizeof(char),length,fp);
fclose(fp);
if(length<0) {
free(msgbuf);
errormsg(WHERE,ERR_READ,msgpath,length);
return(false);
}
msgbuf[length]=0; /* ASCIIZ */
smb_hfield(&msg,SENDER,strlen(useron.alias),useron.alias);
if((i=smb_open_da(&smb))!=0) {
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
return; }
if(cfg.sys_misc&SM_FASTMAIL)
offset=smb_fallocdat(&smb,length,1);
else
offset=smb_allocdat(&smb,length,1);
smb_close_da(&smb);
sprintf(str,"%u",useron.number);
smb_hfield(&msg,SENDEREXT,strlen(str),str);
msg.idx.from=useron.number;
if((file=open(msgpath,O_RDONLY|O_BINARY))==-1
|| (instream=fdopen(file,"rb"))==NULL) {
smb_freemsgdat(&smb,offset,length,1);
smb_hfield(&msg,SUBJECT,strlen(title),title);
msg.idx.subj=subject_crc(title);
memset(&smb,0,sizeof(smb));
smb.subnum=INVALID_SUB; /* mail database */
i=savemsg(&cfg, &smb, &msg, msgbuf);
free(msgbuf);
if(i!=0) {
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY);
return; }
setvbuf(instream,NULL,_IOFBF,2*1024);
smb_fseek(smb.sdt_fp,offset,SEEK_SET);
xlat=XLAT_NONE;
smb_fwrite(&xlat,2,smb.sdt_fp);
x=SDT_BLOCK_LEN-2; /* Don't read/write more than 255 */
while(!feof(instream)) {
memset(buf,0,x);
j=fread(buf,1,x,instream);
if(j<1)
break;
if(j>1 && (j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR)
buf[j-1]=buf[j-2]=0;
smb_fwrite(buf,j,smb.sdt_fp);
x=SDT_BLOCK_LEN; }
smb_fflush(smb.sdt_fp);
fclose(instream);
smb_freemsgmem(&msg);
return(false);
}
j=lastuser(&cfg);
x=0;
......@@ -142,102 +120,94 @@ void sbbs_t::bulkmail(uchar *ar)
if(*ar)
for(i=1;i<=j;i++) {
user.number=i;
getuserdat(&cfg, &user);
if(getuserdat(&cfg, &user)!=0)
continue;
if(user.misc&(DELETED|INACTIVE))
continue;
if(chk_ar(ar,&user)) {
if(found)
smb_freemsgmem(&msg);
x=bulkmailhdr(i,&msg,msgattr,offset,length,title);
if(x)
if((x=bulkmailhdr(&smb, &msg, i))!=0) {
errormsg(WHERE,ERR_WRITE,smb.file,x);
break;
}
msgs++;
found=1; } }
}
}
else
while(1) {
while(online) {
bputs(text[EnterAfterLastDestUser]);
if(!getstr(str,LEN_ALIAS,K_UPRLWR))
break;
if((i=finduser(str))!=0) {
if(found)
smb_freemsgmem(&msg);
x=bulkmailhdr(i,&msg,msgattr,offset,length,title);
if(x)
if((x=bulkmailhdr(&smb, &msg, i))!=0) {
errormsg(WHERE,ERR_WRITE,smb.file,x);
break;
msgs++; }
found=1; }
if((i=smb_open_da(&smb))!=0) {
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
return; }
if(!msgs)
smb_freemsgdat(&smb,offset,length,1);
else if(msgs>1)
smb_incdat(&smb,offset,length,(ushort)msgs-1);
smb_close_da(&smb);
}
msgs++;
}
}
if((i=smb_open_da(&smb))==0) {
if(!msgs)
smb_freemsg_dfields(&smb,&msg,SMB_ALL_REFS);
else if(msgs>1)
smb_incmsg_dfields(&smb,&msg,(ushort)msgs-1);
smb_close_da(&smb);
}
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
smb_freemsgmem(&msg);
if(x) {
smb_freemsgdat(&smb,offset,length,1);
errormsg(WHERE,ERR_WRITE,smb.file,x);
return; }
if(i) {
errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
return(false);
}
putuserrec(&cfg,useron.number,U_EMAILS,5,ultoa(useron.emails,tmp,10));
putuserrec(&cfg,useron.number,U_ETODAY,5,ultoa(useron.etoday,tmp,10));
return(true);
}
int sbbs_t::bulkmailhdr(uint usernum, smbmsg_t *msg, ushort msgattr, ulong offset
, ulong length, char *title)
int sbbs_t::bulkmailhdr(smb_t* smb, smbmsg_t* msg, uint usernum)
{
char str[256];
char tmp[512];
int i,j;
node_t node;
memset(msg,0,sizeof(smbmsg_t));
msg->hdr.version=smb_ver();
msg->hdr.attr=msg->idx.attr=msgattr;
msg->hdr.when_written.time=msg->hdr.when_imported.time=time(NULL);
msg->hdr.when_written.zone=msg->hdr.when_imported.zone=cfg.sys_timezone;
msg->hdr.offset=msg->idx.offset=offset;
username(&cfg, usernum,str);
smb_hfield(msg,RECIPIENT,strlen(str),str);
strlwr(str);
sprintf(str,"%u",usernum);
smb_hfield(msg,RECIPIENTEXT,strlen(str),str);
msg->idx.to=usernum;
strcpy(str,useron.alias);
smb_hfield(msg,SENDER,strlen(str),str);
strlwr(str);
sprintf(str,"%u",useron.number);
smb_hfield(msg,SENDEREXT,strlen(str),str);
msg->idx.from=useron.number;
strcpy(str,title);
smb_hfield(msg,SUBJECT,strlen(str),str);
msg->idx.subj=subject_crc(str);
smb_dfield(msg,TEXT_BODY,length);
j=smb_addmsghdr(&smb,msg,SMB_SELFPACK);
char str[256];
int i,j;
ushort nettype;
node_t node;
user_t user;
smbmsg_t newmsg;
user.number=usernum;
if(getuserdat(&cfg, &user)!=0)
return(0);
if((i=smb_copymsgmem(NULL,&newmsg,msg))!=0)
return(i);
SAFECOPY(str,user.alias);
smb_hfield(&newmsg,RECIPIENT,strlen(str),str);
if(cfg.sys_misc&SM_FWDTONET && user.misc&NETMAIL && user.netmail[0]) {
bprintf(text[UserNetMail],user.netmail);
nettype=NET_INTERNET;
smb_hfield(&newmsg,RECIPIENTNETTYPE,sizeof(nettype),&nettype);
smb_hfield(&newmsg,RECIPIENTNETADDR,strlen(user.netmail),user.netmail);
} else {
sprintf(str,"%u",usernum);
smb_hfield(&newmsg,RECIPIENTEXT,strlen(str),str);
newmsg.idx.to=usernum;
}
j=smb_addmsghdr(smb,&newmsg,SMB_SELFPACK);
smb_freemsgmem(&newmsg);
if(j)
return(j);
// smb_incdat(&smb,offset,length,1); Remove 04/15/96
lncntr=0;
bprintf("Bulk-mailed %s #%d\r\n",username(&cfg, usernum,tmp),usernum);
bprintf("Bulk-mailed %s #%d\r\n",user.alias,usernum);
sprintf(str,"%s bulk-mailed %s #%d"
,useron.alias,username(&cfg, usernum,tmp),usernum);
,useron.alias,user.alias,usernum);
logline("E+",str);
useron.emails++;
logon_emails++;
......@@ -248,10 +218,13 @@ int sbbs_t::bulkmailhdr(uint usernum, smbmsg_t *msg, ushort msgattr, ulong offse
&& (node.status==NODE_INUSE || node.status==NODE_QUIET)) {
sprintf(str,text[EmailNodeMsg],cfg.node_num,useron.alias);
putnmsg(&cfg,i,str);
break; } }
break;
}
}
if(i>cfg.sys_nodes) { /* User wasn't online, so leave short msg */
sprintf(str,text[UserSentYouMail],useron.alias);
putsmsg(&cfg,usernum,str); }
putsmsg(&cfg,usernum,str);
}
return(0);
}
......@@ -461,9 +461,8 @@ public:
void readmail(uint usernumber, int sent);
/* bulkmail.cpp */
void bulkmail(uchar *ar);
int bulkmailhdr(uint usernum, smbmsg_t* msg, ushort msgattr, ulong offset
,ulong length, char *title);
bool bulkmail(uchar *ar);
int bulkmailhdr(smb_t*, smbmsg_t*, uint usernum);
/* con_out.cpp */
int bputs(char *str); /* BBS puts function */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment