...
 
Commits (1)
  • Rob Swindell's avatar
    Make read/unread mail-waiting stats easier to access · bd17a29f
    Rob Swindell authored
    New JS User.stats properties:
    - read_mail_waiting
    - unread_mail_waiting
    - spam_waiting
    
    New @-codes:
    - MAILR (read mail waiting)
    - MAILU (unread mail waiting)
    
    And the corresponding MAILR# and MAILU# codes (for non-current user's stats).
    
    Addresses feature request #191.
    bd17a29f
......@@ -1593,6 +1593,16 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode, bool
return(tp);
}
if(!strcmp(sp,"MAILR")) {
safe_snprintf(str,maxlen,"%u",getmail(&cfg,useron.number, /* Sent: */FALSE, /* attr: */MSG_READ));
return(str);
}
if(!strcmp(sp,"MAILU")) {
safe_snprintf(str,maxlen,"%u",getmail(&cfg,useron.number, /* Sent: */FALSE, /* attr: */~MSG_READ));
return(str);
}
if(!strcmp(sp,"MAILW")) {
safe_snprintf(str,maxlen,"%u",getmail(&cfg,useron.number, /* Sent: */FALSE, /* attr: */0));
return(str);
......@@ -1608,6 +1618,16 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode, bool
return(str);
}
if(!strncmp(sp,"MAILR:",6) || !strncmp(sp,"MAILR#",6)) {
safe_snprintf(str,maxlen,"%u",getmail(&cfg,atoi(sp+6), /* Sent: */FALSE, /* attr: */MSG_READ));
return(str);
}
if(!strncmp(sp,"MAILU:",6) || !strncmp(sp,"MAILU#",6)) {
safe_snprintf(str,maxlen,"%u",getmail(&cfg,atoi(sp+6), /* Sent: */FALSE, /* attr: */~MSG_READ));
return(str);
}
if(!strncmp(sp,"MAILW:",6) || !strncmp(sp,"MAILW#",6)) {
safe_snprintf(str,maxlen,"%u",getmail(&cfg,atoi(sp+6), /* Sent: */FALSE, /* attr: */0));
return(str);
......
......@@ -26,7 +26,7 @@
/* If sent is non-zero, it returns the number of mail sent by usernumber */
/* If usernumber is 0, it returns all mail on the system */
/****************************************************************************/
int DLLCALL getmail(scfg_t* cfg, int usernumber, BOOL sent, uint16_t attr)
int DLLCALL getmail(scfg_t* cfg, int usernumber, BOOL sent, int attr)
{
char path[MAX_PATH+1];
int i=0;
......@@ -55,7 +55,9 @@ int DLLCALL getmail(scfg_t* cfg, int usernumber, BOOL sent, uint16_t attr)
continue;
if(idx.attr&MSG_DELETE)
continue;
if((idx.attr&attr) != attr)
if(attr < 0 && (idx.attr & (~attr)) != 0)
continue;
if(attr > 0 && (idx.attr & attr) != attr)
continue;
if(usernumber == 0
|| (!sent && idx.to==usernumber)
......
......@@ -28,7 +28,7 @@
extern "C" {
#endif
DLLEXPORT int getmail(scfg_t* cfg, int usernumber, BOOL sent, uint16_t attr);
DLLEXPORT int getmail(scfg_t* cfg, int usernumber, BOOL sent, int attr);
DLLEXPORT mail_t * loadmail(smb_t* smb, uint32_t* msgs, uint usernumber
,int which, long mode);
DLLEXPORT void freemail(mail_t* mail);
......@@ -37,4 +37,4 @@ DLLEXPORT BOOL delfattach(scfg_t*, smbmsg_t*);
#ifdef __cplusplus
}
#endif
#endif /* Don't add anything after this line */
\ No newline at end of file
#endif /* Don't add anything after this line */
/* Synchronet JavaScript "User" Object */
// vi: tabstop=4
/* $Id: js_user.c,v 1.119 2020/08/11 03:54:58 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
......@@ -16,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -88,6 +73,9 @@ enum {
,USER_PROP_ETODAY
,USER_PROP_PTODAY
,USER_PROP_MAIL_WAITING
,USER_PROP_READ_WAITING
,USER_PROP_UNREAD_WAITING
,USER_PROP_SPAM_WAITING
,USER_PROP_MAIL_PENDING
,USER_PROP_ULB
,USER_PROP_ULS
......@@ -391,7 +379,16 @@ static JSBool js_user_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
val=scfg->level_freecdtperday[p->user->level];
break;
case USER_PROP_MAIL_WAITING:
val=getmail(scfg,p->user->number,/* sent? */FALSE, /* SPAM: */FALSE);
val=getmail(scfg,p->user->number,/* sent? */FALSE, /* attr: */0);
break;
case USER_PROP_READ_WAITING:
val=getmail(scfg,p->user->number,/* sent? */FALSE, /* attr: */MSG_READ);
break;
case USER_PROP_UNREAD_WAITING:
val=getmail(scfg,p->user->number,/* sent? */FALSE, /* attr: */~MSG_READ);
break;
case USER_PROP_SPAM_WAITING:
val=getmail(scfg,p->user->number,/* sent? */FALSE, /* attr: */MSG_SPAM);
break;
case USER_PROP_MAIL_PENDING:
val=getmail(scfg,p->user->number,/* sent? */TRUE, /* SPAM: */FALSE);
......@@ -960,6 +957,9 @@ static jsSyncPropertySpec js_user_stats_properties[] = {
{ "files_downloaded" ,USER_PROP_DLS ,USER_PROP_FLAGS, 310 },
{ "leech_attempts" ,USER_PROP_LEECH ,USER_PROP_FLAGS, 310 },
{ "mail_waiting" ,USER_PROP_MAIL_WAITING ,USER_PROP_FLAGS, 312 },
{ "read_mail_waiting" ,USER_PROP_READ_WAITING ,USER_PROP_FLAGS, 31802 },
{ "unread_mail_waiting",USER_PROP_UNREAD_WAITING,USER_PROP_FLAGS, 31802 },
{ "spam_waiting" ,USER_PROP_SPAM_WAITING ,USER_PROP_FLAGS, 31802 },
{ "mail_pending" ,USER_PROP_MAIL_PENDING ,USER_PROP_FLAGS, 312 },
{0}
};
......@@ -984,7 +984,10 @@ static char* user_stats_prop_desc[] = {
,"total bytes downloaded"
,"total files downloaded"
,"suspected leech downloads"
,"number of e-mail messages currently waiting"
,"total number of e-mail messages currently waiting in inbox"
,"number of read e-mail messages currently waiting in inbox"
,"number of unread e-mail messages currently waiting in inbox"
,"number of SPAM e-mail messages currently waiting in inbox"
,"number of e-mail messages sent, currently pending deletion"
,NULL
};
......