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

JS bbs object changes:

- finduser() method no longer prints "Unknown user" upon failure (the calling
  script can do this if/when it wants).
- read_mail() method now accepts an optional 3rd argumnet (loadmail_mode)
  which may be used to load *only* un-read mail (for example), see LM_* in
  sbbsdefs.js

Pass the lm_mode as a 4th argument to any readmail mod (if one is installed) -
this correlates with the LM_* mode flag values (0 is normal/usual).

File attachments can also be in a file/####.out directory (e.g. outbound
Internet email attachments), so try deleting from there too when deleting
mail with attachments.
parent e2f82044
/* data.cpp */
/* Synchronet data access routines */
/* Synchronet (oh, so old) data access routines */
/* $Id$ */
......@@ -8,7 +6,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2015 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 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 *
......@@ -47,7 +45,7 @@
/* Returns the number of the matched user or 0 if unsuccessful */
/* Called from functions main_sec, useredit and readmailw */
/****************************************************************************/
uint sbbs_t::finduser(char *instr)
uint sbbs_t::finduser(char *instr, bool silent_failure)
{
int file,i;
char str[128],str2[256],str3[256],ynq[25],c,pass=1;
......@@ -107,7 +105,8 @@ uint sbbs_t::finduser(char *instr)
}
pass++;
}
bputs(text[UnknownUser]);
if(!silent_failure)
bputs(text[UnknownUser]);
fclose(stream);
return(0);
}
......
......@@ -1699,7 +1699,7 @@ js_finduser(JSContext *cx, uintN argc, jsval *arglist)
}
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->finduser(p)));
JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->finduser(p, /* silent_failure: */true)));
free(p);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -2478,6 +2478,7 @@ js_readmail(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
int32 readwhich=MAIL_YOUR;
int32 usernumber;
int32 lm_mode = 0;
sbbs_t* sbbs;
jsrefcount rc;
......@@ -2495,9 +2496,13 @@ js_readmail(JSContext *cx, uintN argc, jsval *arglist)
if(!JS_ValueToInt32(cx,argv[1],&usernumber))
return JS_FALSE;
}
if(argc>2 && JSVAL_IS_NUMBER(argv[2])) {
if(!JS_ValueToInt32(cx, argv[2], &lm_mode))
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
sbbs->readmail(usernumber,readwhich);
sbbs->readmail(usernumber, readwhich, lm_mode);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -3799,7 +3804,7 @@ static jsSyncMethodSpec js_bbs_functions[] = {
,JSDOCSTR("display the logon list")
,310
},
{"read_mail", js_readmail, 0, JSTYPE_VOID, JSDOCSTR("[which=<tt>MAIL_YOUR</tt>] [,user_number=<i>current</i>]")
{"read_mail", js_readmail, 0, JSTYPE_VOID, JSDOCSTR("[which=<tt>MAIL_YOUR</tt>] [,user_number=<i>current</i>] [,loadmail_mode=<tt>0</tt>]")
,JSDOCSTR("read private e-mail"
"(see <tt>MAIL_*</tt> in <tt>sbbsdefs.js</tt> for valid <i>which</i> values)")
,310
......
......@@ -55,7 +55,7 @@ static char mail_listing_flag(smbmsg_t* msg)
/****************************************************************************/
/* Reads mail waiting for usernumber. */
/****************************************************************************/
void sbbs_t::readmail(uint usernumber, int which)
void sbbs_t::readmail(uint usernumber, int which, long lm_mode)
{
char str[256],str2[256],str3[256],done=0,domsg=1
,*p,*tp,*sp,ch;
......@@ -66,7 +66,7 @@ void sbbs_t::readmail(uint usernumber, int which)
int error;
int mismatches=0,act;
uint unum;
long length,l,lm_mode, last_mode;
long length,l,last_mode;
ulong last;
bool replied;
file_t fd;
......@@ -78,7 +78,7 @@ void sbbs_t::readmail(uint usernumber, int which)
char cmdline[256];
readmail_inside = true;
safe_snprintf(cmdline, sizeof(cmdline), "%s %d %u", cfg.readmail_mod, which, usernumber);
safe_snprintf(cmdline, sizeof(cmdline), "%s %d %u %lu", cfg.readmail_mod, which, usernumber, lm_mode);
exec_bin(cmdline, &main_csi);
readmail_inside = false;
return;
......@@ -107,9 +107,7 @@ void sbbs_t::readmail(uint usernumber, int which)
}
if(cfg.sys_misc&SM_SYSVDELM && (SYSOP || cfg.sys_misc&SM_USRVDELM))
lm_mode=LM_INCDEL;
else
lm_mode=0;
lm_mode |= LM_INCDEL;
mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode);
last_mode = lm_mode;
if(!smb.msgs) {
......@@ -118,7 +116,7 @@ void sbbs_t::readmail(uint usernumber, int which)
else if(which==MAIL_ALL)
bputs(text[NoMailOnSystem]);
else
bprintf(text[NoMailWaiting], "mail");
bprintf(text[NoMailWaiting], lm_mode&LM_UNREAD ? "un-read mail" : "mail");
smb_close(&smb);
smb_stack(&smb,SMB_STACK_POP);
return;
......@@ -192,11 +190,9 @@ void sbbs_t::readmail(uint usernumber, int which)
sprintf(str,"%s read mail",useron.alias);
logline("E",str);
}
if(useron.misc&RIP) {
strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ?
"allmail" : "sentmail");
menu(str);
}
const char* menu_file = (which == MAIL_ALL ? "allmail" : which==MAIL_SENT ? "sentmail" : "mailread");
if(useron.misc&RIP)
menu(menu_file);
current_msg=&msg; /* For MSG_* @-codes and bbs.msg_* property values */
while(online && !done) {
action=act;
......@@ -312,6 +308,9 @@ void sbbs_t::readmail(uint usernumber, int which)
padfname(tp,fd.name);
SAFEPRINTF3(path,"%sfile/%04u.in/%s" /* path is path/fname */
,cfg.data_dir,msg.idx.to,tp);
if(!fexistcase(path) && msg.idx.from)
SAFEPRINTF3(path,"%sfile/%04u.out/%s" /* path is path/fname */
,cfg.data_dir,msg.idx.from,tp);
length=(long)flength(path);
if(length<1)
bprintf(text[FileDoesNotExist], tp);
......@@ -397,11 +396,8 @@ void sbbs_t::readmail(uint usernumber, int which)
}
else domsg=1;
if(useron.misc&WIP) {
strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ?
"allmail" : "sentmail");
menu(str);
}
if(useron.misc&WIP)
menu(menu_file);
ASYNC;
if(which==MAIL_SENT)
......@@ -867,9 +863,7 @@ void sbbs_t::readmail(uint usernumber, int which)
searchmail(mail, (long)i64, smb.msgs, which, search_str);
break;
case '?':
strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL
? "allmail" : "sentmail");
menu(str);
menu(menu_file);
if(SYSOP && which==MAIL_SENT)
menu("syssmail");
else if(SYSOP && which==MAIL_YOUR)
......
......@@ -587,7 +587,7 @@ public:
void reset_logon_vars(void);
uint finduser(char *str);
uint finduser(char *str, bool silent_failure = false);
int sub_op(uint subnum);
......@@ -675,7 +675,7 @@ public:
ulong getmsgnum(uint subnum, time_t t);
/* readmail.cpp */
void readmail(uint usernumber, int which);
void readmail(uint usernumber, int which, long lm_mode = 0);
bool readmail_inside;
long searchmail(mail_t*, long start, long msgss, int which, const char *search);
......
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