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 d95d30ea authored by rswindell's avatar rswindell

sbbs_t::postmsg() and JS's bbs.post_msg() changes:

When the WM_QUOTE mode flag is set and the 'remsg' is specified, the original
message will quoted (excluding message tails, using the proper word-wrapping).
If the quote file already exists before calling postmsg()/bbs.post_msg(), it
will be over-written. This allows JS script to initiate reply-posts with quoted
text without having to create their own quotes file. It also means there's no
need to call sbbs_t::quotemsg() before calling sbbs_t::postmsg().
sbbs_t::quotemsg() now takes an smb_t* arg (stop using the sbbs_t 'global'
smb) and now returns bool.
parent 2c82a9dd
......@@ -77,8 +77,8 @@ int msgbase_open(scfg_t* cfg, smb_t* smb, int* storage, long* dupechk_hashes, ui
/****************************************************************************/
/* Posts a message on subboard number sub, with 'top' as top of message. */
/* Returns 1 if posted, 0 if not. */
/* Posts a message on sub-board number 'subnum' */
/* Returns true if posted, false if not. */
/****************************************************************************/
bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
{
......@@ -98,14 +98,15 @@ bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
uint reason;
if(remsg) {
sprintf(title,"%.*s",LEN_TITLE,remsg->subj);
SAFECOPY(title, remsg->subj);
if(remsg->hdr.attr&MSG_ANONYMOUS)
SAFECOPY(from,text[Anonymous]);
else
SAFECOPY(from,remsg->from);
// If user posted this message, reply to the original recipient again
if((remsg->from_ext!=NULL && atoi(remsg->from_ext)==useron.number)
|| stricmp(useron.alias,remsg->from)==0 || stricmp(useron.name,remsg->from)==0)
if(remsg->to != NULL
&& ((remsg->from_ext != NULL && atoi(remsg->from_ext)==useron.number)
|| stricmp(useron.alias,remsg->from) == 0 || stricmp(useron.name,remsg->from) == 0))
SAFECOPY(touser,remsg->to);
else
SAFECOPY(touser,from);
......@@ -208,15 +209,6 @@ bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
bputs(text[UsingRealName]);
msg_tmp_fname(useron.xedit, str, sizeof(str));
if(!writemsg(str,top,title,wm_mode,subnum,touser
,/* from: */cfg.sub[subnum]->misc&SUB_NAME ? useron.name : useron.alias
,&editor)
|| (length=(long)flength(str))<1) { /* Bugfix Aug-20-2003: Reject negative length */
bputs(text[Aborted]);
return(false);
}
bputs(text[WritingIndx]);
if((i=smb_stack(&smb,SMB_STACK_PUSH))!=SMB_SUCCESS) {
errormsg(WHERE,ERR_OPEN,cfg.sub[subnum]->code,i,smb.last_error);
......@@ -230,6 +222,23 @@ bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
return(false);
}
if(remsg != NULL && (wm_mode&WM_QUOTE)) {
if(!quotemsg(&smb, remsg, /* include tails: */FALSE))
wm_mode &= ~WM_QUOTE;
}
if(!writemsg(str,top,title,wm_mode,subnum,touser
,/* from: */cfg.sub[subnum]->misc&SUB_NAME ? useron.name : useron.alias
,&editor)
|| (length=(long)flength(str))<1) { /* Bugfix Aug-20-2003: Reject negative length */
bputs(text[Aborted]);
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
return(false);
}
bputs(text[WritingIndx]);
if((i=smb_locksmbhdr(&smb))!=SMB_SUCCESS) {
smb_close(&smb);
errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);
......
......@@ -437,7 +437,7 @@ void sbbs_t::readmail(uint usernumber, int which, long lm_mode)
break;
}
quotemsg(&msg,/* include tails: */TRUE);
quotemsg(&smb, &msg,/* include tails: */TRUE);
if(msg.from_net.addr==NULL)
SAFECOPY(str,msg.from);
......
......@@ -919,7 +919,6 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
bputs(text[CantReplyToMsg]);
break;
}
quotemsg(&msg,/* include tails: */FALSE);
FREE_AND_NULL(post);
postmsg(subnum,&msg,WM_QUOTE);
if(mode&SCAN_TOYOU)
......@@ -1121,7 +1120,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
break;
FREE_AND_NULL(post);
quotemsg(&msg,/* include tails: */TRUE);
quotemsg(&smb, &msg, /* include tails: */TRUE);
if(strchr(str, '@') != NULL) {
if(smb_netaddr_type(str)==NET_INTERNET)
inetmail(str,msg.subj,WM_QUOTE|WM_NETMAIL);
......
......@@ -653,7 +653,7 @@ public:
ulong msgeditor(char *buf, const char *top, char *title);
bool editfile(char *path, bool msg=false);
ushort chmsgattr(smbmsg_t);
void quotemsg(smbmsg_t* msg, int tails);
bool quotemsg(smb_t*, smbmsg_t*, int tails);
void editmsg(smbmsg_t* msg, uint subnum);
void editor_inf(int xeditnum, const char *to, const char* from, const char *subj, long mode
,uint subnum, const char* tagfile);
......
......@@ -74,7 +74,7 @@ char* sbbs_t::quotes_fname(int xedit, char *path, size_t len)
/****************************************************************************/
/****************************************************************************/
void sbbs_t::quotemsg(smbmsg_t* msg, int tails)
bool sbbs_t::quotemsg(smb_t* smb, smbmsg_t* remsg, int tails)
{
char fname[MAX_PATH+1];
char* buf;
......@@ -83,8 +83,8 @@ void sbbs_t::quotemsg(smbmsg_t* msg, int tails)
ushort useron_xedit = useron.xedit;
uint8_t org_cols = TERM_COLS_DEFAULT;
if(msg->columns != 0)
org_cols = msg->columns;
if(remsg->columns != 0)
org_cols = remsg->columns;
if(useron_xedit && !chk_ar(cfg.xedit[useron_xedit-1]->ar, &useron, &client))
useron_xedit = 0;
......@@ -94,23 +94,35 @@ void sbbs_t::quotemsg(smbmsg_t* msg, int tails)
if((fp=fopen(fname,"w"))==NULL) {
errormsg(WHERE,ERR_OPEN,fname,0);
return;
return false;
}
if((buf=smb_getmsgtxt(&smb,msg,tails)) != NULL) {
strip_invalid_attr(buf);
truncsp(buf);
if(!useron_xedit || (useron_xedit && (cfg.xedit[useron_xedit-1]->misc&QUOTEWRAP)))
wrapped=::wordwrap(buf, cols-4, org_cols - 1, /* handle_quotes: */TRUE);
if(wrapped!=NULL) {
fputs(wrapped,fp);
free(wrapped);
} else
fputs(buf,fp);
smb_freemsgtxt(buf);
} else if(smb_getmsgdatlen(msg)>2)
errormsg(WHERE,ERR_READ,smb.file,smb_getmsgdatlen(msg));
bool result = false;
smbmsg_t msg;
ZERO_VAR(msg);
msg.hdr.number = remsg->hdr.number;
if(smb_getmsgidx(smb, &msg) == SMB_SUCCESS && smb_getmsghdr(smb, &msg) == SMB_SUCCESS) {
if((buf=smb_getmsgtxt(smb, &msg, tails)) != NULL) {
strip_invalid_attr(buf);
truncsp(buf);
if(!useron_xedit || (useron_xedit && (cfg.xedit[useron_xedit-1]->misc&QUOTEWRAP)))
wrapped=::wordwrap(buf, cols-4, org_cols - 1, /* handle_quotes: */TRUE);
if(wrapped!=NULL) {
fputs(wrapped,fp);
free(wrapped);
} else
fputs(buf,fp);
smb_freemsgtxt(buf);
result = true;
} else if(smb_getmsgdatlen(&msg)>2)
errormsg(WHERE,ERR_READ,smb->file,smb_getmsgdatlen(&msg));
smb_freemsgmem(&msg);
}
fclose(fp);
return result;
}
/****************************************************************************/
......
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