Newer
Older
}
}
n++;
break;
}
}
if(!msg_specified) /* No message number or id specified */
if(n<argc && JSVAL_IS_BOOLEAN(argv[n]))
strip_ctrl_a=JSVAL_TO_BOOLEAN(argv[n++]);
if(n<argc && JSVAL_IS_BOOLEAN(argv[n]))
rfc822=JSVAL_TO_BOOLEAN(argv[n++]);
if(n<argc && JSVAL_IS_BOOLEAN(argv[n]))
tails=JSVAL_TO_BOOLEAN(argv[n++]);
if(n<argc && JSVAL_IS_BOOLEAN(argv[n]))
plain=JSVAL_TO_BOOLEAN(argv[n++]);
if(tails)
getmsgtxtmode |= GETMSGTXT_TAILS;
if(plain)
getmsgtxtmode |= GETMSGTXT_PLAIN;
rc=JS_SUSPENDREQUEST(cx);
buf = get_msg_text(p, msgptr, strip_ctrl_a, rfc822, getmsgtxtmode, existing_msg);
JS_RESUMEREQUEST(cx, rc);
if(buf==NULL)
if((js_str=JS_NewStringCopyZ(cx,buf))!=NULL)
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
smb_freemsgtxt(buf);
}
static JSBool
js_get_msg_tail(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* buf;
uintN n;
smbmsg_t msg;
smbmsg_t *msgptr;
JSBool by_offset=JS_FALSE;
JSBool strip_ctrl_a=JS_FALSE;
JSBool rfc822=JS_FALSE;
JSBool msg_specified=JS_FALSE;
JSBool existing_msg=JS_FALSE;
private_t* p;
JS_SET_RVAL(cx, arglist, JSVAL_NULL);
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
JS_ReportError(cx,getprivate_failure,WHERE);
if(!SMB_IS_OPEN(&(p->smb)))
memset(&msg,0,sizeof(msg));
for(n=0;n<argc;n++) {
if(JSVAL_IS_BOOLEAN(argv[n]))
by_offset=JSVAL_TO_BOOLEAN(argv[n]);
else if(JSVAL_IS_NUMBER(argv[n])) {
if(by_offset) { /* Get by offset */
if(!JS_ValueToInt32(cx,argv[n],(int32*)&msg.offset))
return JS_FALSE;
}
else { /* Get by number */
if(!JS_ValueToInt32(cx,argv[n],(int32*)&msg.hdr.number))
return JS_FALSE;
}
msg_specified=JS_TRUE;
n++;
break;
} else if(JSVAL_IS_STRING(argv[n])) { /* Get by ID */
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(argv[n]), cstr, NULL);
HANDLE_PENDING(cx);
rc=JS_SUSPENDREQUEST(cx);
if(!msg_offset_by_id(p
JS_RESUMEREQUEST(cx, rc);
return JS_TRUE; /* ID not found */
JS_RESUMEREQUEST(cx, rc);
msg_specified=JS_TRUE;
n++;
break;
} else if(JSVAL_IS_OBJECT(argv[n])) { /* Use existing header */
JSClass *oc=JS_GetClass(cx, JSVAL_TO_OBJECT(argv[n]));
if(strcmp(oc->name, js_msghdr_class.name)==0) {
privatemsg_t *pmsg=JS_GetPrivate(cx,JSVAL_TO_OBJECT(argv[n]));
if(pmsg != NULL) {
msg_specified=JS_TRUE;
existing_msg=JS_TRUE;
msgptr=&pmsg->msg;
}
}
n++;
break;
}
}
if(!msg_specified) /* No message number or id specified */
if(n<argc && JSVAL_IS_BOOLEAN(argv[n]))
strip_ctrl_a=JSVAL_TO_BOOLEAN(argv[n++]);
if(n<argc && JSVAL_IS_BOOLEAN(argv[n]))
rfc822=JSVAL_TO_BOOLEAN(argv[n++]);
rc=JS_SUSPENDREQUEST(cx);
buf = get_msg_text(p, msgptr, strip_ctrl_a, rfc822, GETMSGTXT_TAILS|GETMSGTXT_NO_BODY, existing_msg);
JS_RESUMEREQUEST(cx, rc);
if(buf==NULL)
if((js_str=JS_NewStringCopyZ(cx,buf))!=NULL)
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
smb_freemsgtxt(buf);
js_save_msg(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* body=NULL;
jsuint i;
jsuint rcpt_list_length;
jsval val;
JSObject* hdr=NULL;
JSObject* objarg;
JSObject* rcpt_list=NULL;
JSClass* cl;
smbmsg_t rcpt_msg;
client_t* client=NULL;
JSBool ret=JS_TRUE;
scfg_t* scfg;
scfg=JS_GetRuntimePrivate(JS_GetRuntime(cx));
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
JS_ReportError(cx,getprivate_failure,WHERE);
if(!SMB_IS_OPEN(&(p->smb))) {
for(n=0;n<argc;n++) {
if(JSVAL_IS_OBJECT(argv[n]) && !JSVAL_IS_NULL(argv[n])) {
objarg = JSVAL_TO_OBJECT(argv[n]);
if((cl=JS_GetClass(cx,objarg))!=NULL && strcmp(cl->name,"Client")==0) {
client=JS_GetPrivate(cx,objarg);
continue;
}
if(JS_IsArrayObject(cx, objarg)) { /* recipient_list is an array of objects */
if(body!=NULL && rcpt_list==NULL) { /* body text already specified */
rcpt_list = objarg;
continue;
}
}
else if(hdr==NULL) {
hdr = objarg;
continue;
JSVALUE_TO_MSTRING(cx, argv[n], body, NULL);
HANDLE_PENDING(cx);
JS_ReportError(cx,"Invalid message body string");
}
// Find and use the global client object if possible...
if(client==NULL) {
if(JS_GetProperty(cx, JS_GetGlobalObject(cx), "client", &val) && !JSVAL_NULL_OR_VOID(val)) {
objarg = JSVAL_TO_OBJECT(val);
if((cl=JS_GetClass(cx,objarg))!=NULL && strcmp(cl->name,"Client")==0)
client=JS_GetPrivate(cx,objarg);
}
}
if(hdr==NULL)
if(body==NULL)
if(rcpt_list!=NULL) {
if(!JS_GetArrayLength(cx, rcpt_list, &rcpt_list_length))
if(!rcpt_list_length)
}
if(parse_header_object(cx, p, hdr, &msg, rcpt_list==NULL)) {
if(body[0])
truncsp(body);
if((p->status=savemsg(scfg, &(p->smb), &msg, client, /* ToDo server hostname: */NULL, body))==SMB_SUCCESS) {
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
if(rcpt_list!=NULL) { /* Sending to a list of recipients */
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
SAFECOPY(p->smb.last_error,"Recipient list parsing failure");
if(!JS_GetElement(cx, rcpt_list, i, &val))
break;
if(!JSVAL_IS_OBJECT(val))
break;
rc=JS_SUSPENDREQUEST(cx);
if((p->status=smb_copymsgmem(&(p->smb), &rcpt_msg, &msg))!=SMB_SUCCESS) {
JS_RESUMEREQUEST(cx, rc);
if(!parse_recipient_object(cx, p, JSVAL_TO_OBJECT(val), &rcpt_msg))
break;
rc=JS_SUSPENDREQUEST(cx);
if((p->status=smb_addmsghdr(&(p->smb), &rcpt_msg, SMB_SELFPACK))!=SMB_SUCCESS) {
JS_RESUMEREQUEST(cx, rc);
}
smb_freemsgmem(&rcpt_msg); /* just in case we broke the loop */
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
}
} else {
ret=JS_FALSE;
SAFECOPY(p->smb.last_error,"Header parsing failure (required field missing?)");
smb_freemsgmem(&msg);
return(ret);
static JSBool
js_vote_msg(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject* obj=JS_THIS_OBJECT(cx, arglist);
jsval* argv=JS_ARGV(cx, arglist);
uintN n;
JSObject* hdr=NULL;
JSObject* objarg;
smbmsg_t msg;
private_t* p;
JSBool ret=JS_TRUE;
jsrefcount rc;
scfg_t* scfg;
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
return JS_TRUE;
if((p=(private_t*)JS_GetPrivate(cx, obj)) == NULL) {
JS_ReportError(cx, getprivate_failure, WHERE);
return JS_FALSE;
}
if(!SMB_IS_OPEN(&(p->smb))) {
if(!js_open(cx, 0, arglist))
return JS_FALSE;
if(JS_RVAL(cx, arglist) == JSVAL_FALSE)
return JS_TRUE;
}
msg.hdr.type = SMB_MSG_TYPE_VOTE;
if(JSVAL_IS_OBJECT(argv[n]) && !JSVAL_IS_NULL(argv[n])) {
objarg = JSVAL_TO_OBJECT(argv[n]);
hdr = objarg;
continue;
}
}
}
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
if(hdr == NULL)
return JS_TRUE;
if(parse_header_object(cx, p, hdr, &msg, FALSE)) {
rc = JS_SUSPENDREQUEST(cx);
if((p->status=votemsg(scfg, &(p->smb), &msg, NULL)) == SMB_SUCCESS) {
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
}
else
JS_RESUMEREQUEST(cx, rc);
} else {
ret = JS_FALSE;
SAFECOPY(p->smb.last_error,"Header parsing failure (required field missing?)");
}
smb_freemsgmem(&msg);
return ret;
}
static JSBool
js_add_poll(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject* obj=JS_THIS_OBJECT(cx, arglist);
jsval* argv=JS_ARGV(cx, arglist);
uintN n;
JSObject* hdr=NULL;
JSObject* objarg;
smbmsg_t msg;
private_t* p;
JSBool ret=JS_TRUE;
jsrefcount rc;
scfg_t* scfg;
scfg = JS_GetRuntimePrivate(JS_GetRuntime(cx));
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
if(argc < 1)
return JS_TRUE;
if((p=(private_t*)JS_GetPrivate(cx,obj)) == NULL) {
JS_ReportError(cx, getprivate_failure, WHERE);
return JS_FALSE;
}
if(!SMB_IS_OPEN(&(p->smb))) {
if(!js_open(cx, 0, arglist))
return JS_FALSE;
if(JS_RVAL(cx, arglist) == JSVAL_FALSE)
return JS_TRUE;
}
memset(&msg, 0, sizeof(msg));
msg.hdr.type = SMB_MSG_TYPE_POLL;
for(n=0; n<argc; n++) {
if(JSVAL_IS_OBJECT(argv[n]) && !JSVAL_IS_NULL(argv[n])) {
objarg = JSVAL_TO_OBJECT(argv[n]);
if(hdr == NULL) {
hdr = objarg;
continue;
}
}
}
if(hdr == NULL)
return JS_TRUE;
if(parse_header_object(cx, p, hdr, &msg, FALSE)) {
rc=JS_SUSPENDREQUEST(cx);
if((p->status=smb_addpoll(&(p->smb), &msg, smb_storage_mode(scfg, &(p->smb)))) == SMB_SUCCESS) {
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
}
else
JS_RESUMEREQUEST(cx, rc);
} else {
SAFECOPY(p->smb.last_error,"Header parsing failure (required field missing?)");
}
smb_freemsgmem(&msg);
}
/* MsgBase Object Properties */
enum {
SMB_PROP_LAST_ERROR
,SMB_PROP_FILE
,SMB_PROP_DEBUG
,SMB_PROP_RETRY_TIME
,SMB_PROP_RETRY_DELAY
,SMB_PROP_FIRST_MSG /* first message number */
,SMB_PROP_LAST_MSG /* last message number */
,SMB_PROP_TOTAL_MSGS /* total messages */
,SMB_PROP_MAX_CRCS /* Maximum number of CRCs to keep in history */
,SMB_PROP_MAX_MSGS /* Maximum number of message to keep in sub */
,SMB_PROP_MAX_AGE /* Maximum age of message to keep in sub (in days) */
,SMB_PROP_ATTR /* Attributes for this message base (SMB_HYPER,etc) */
,SMB_PROP_SUBNUM /* sub-board number */
,SMB_PROP_IS_OPEN
,SMB_PROP_STATUS /* Last SMBLIB returned status value (e.g. retval) */
static JSBool js_msgbase_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
jsval idval;
jsint tiny;
private_t* p;
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
JS_ReportError(cx,getprivate_failure,WHERE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case SMB_PROP_RETRY_TIME:
if(!JS_ValueToInt32(cx,*vp,(int32*)&(p->smb).retry_time))
return JS_FALSE;
break;
case SMB_PROP_RETRY_DELAY:
if(!JS_ValueToInt32(cx,*vp,(int32*)&(p->smb).retry_delay))
return JS_FALSE;
break;
case SMB_PROP_DEBUG:
JS_ValueToBoolean(cx,*vp,&p->debug);
break;
}
static JSBool js_msgbase_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
jsval idval;
char* s=NULL;
JSString* js_str;
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case SMB_PROP_FILE:
break;
case SMB_PROP_LAST_ERROR:
case SMB_PROP_STATUS:
*vp = INT_TO_JSVAL(p->status);
break;
case SMB_PROP_RETRY_TIME:
*vp = INT_TO_JSVAL(p->smb.retry_time);
break;
case SMB_PROP_RETRY_DELAY:
*vp = INT_TO_JSVAL(p->smb.retry_delay);
break;
case SMB_PROP_DEBUG:
*vp = INT_TO_JSVAL(p->debug);
break;
rc=JS_SUSPENDREQUEST(cx);
memset(&idx,0,sizeof(idx));
smb_getfirstidx(&(p->smb),&idx);
JS_RESUMEREQUEST(cx, rc);
*vp=UINT_TO_JSVAL(idx.number);
case SMB_PROP_LAST_MSG:
rc=JS_SUSPENDREQUEST(cx);
smb_getstatus(&(p->smb));
JS_RESUMEREQUEST(cx, rc);
*vp=UINT_TO_JSVAL(p->smb.status.last_msg);
break;
case SMB_PROP_TOTAL_MSGS:
rc=JS_SUSPENDREQUEST(cx);
smb_getstatus(&(p->smb));
JS_RESUMEREQUEST(cx, rc);
*vp=UINT_TO_JSVAL(p->smb.status.total_msgs);
break;
case SMB_PROP_MAX_CRCS:
*vp=UINT_TO_JSVAL(p->smb.status.max_crcs);
break;
case SMB_PROP_MAX_MSGS:
*vp=UINT_TO_JSVAL(p->smb.status.max_msgs);
break;
case SMB_PROP_MAX_AGE:
*vp=UINT_TO_JSVAL(p->smb.status.max_age);
break;
case SMB_PROP_ATTR:
*vp=UINT_TO_JSVAL(p->smb.status.attr);
case SMB_PROP_SUBNUM:
*vp = INT_TO_JSVAL(p->smb.subnum);
break;
case SMB_PROP_IS_OPEN:
*vp = BOOLEAN_TO_JSVAL(SMB_IS_OPEN(&(p->smb)));
break;
if(s!=NULL) {
if((js_str=JS_NewStringCopyZ(cx, s))==NULL)
*vp = STRING_TO_JSVAL(js_str);
}
}
#define SMB_PROP_FLAGS JSPROP_ENUMERATE|JSPROP_READONLY
static jsSyncPropertySpec js_msgbase_properties[] = {
/* name ,tinyid ,flags, ver */
{ "error" ,SMB_PROP_LAST_ERROR ,SMB_PROP_FLAGS, 310 },
{ "last_error" ,SMB_PROP_LAST_ERROR ,JSPROP_READONLY, 311 }, /* alias */
{ "status" ,SMB_PROP_STATUS ,SMB_PROP_FLAGS, 312 },
{ "file" ,SMB_PROP_FILE ,SMB_PROP_FLAGS, 310 },
{ "debug" ,SMB_PROP_DEBUG ,0, 310 },
{ "retry_time" ,SMB_PROP_RETRY_TIME ,JSPROP_ENUMERATE, 310 },
{ "retry_delay" ,SMB_PROP_RETRY_DELAY ,JSPROP_ENUMERATE, 311 },
{ "first_msg" ,SMB_PROP_FIRST_MSG ,SMB_PROP_FLAGS, 310 },
{ "last_msg" ,SMB_PROP_LAST_MSG ,SMB_PROP_FLAGS, 310 },
{ "total_msgs" ,SMB_PROP_TOTAL_MSGS ,SMB_PROP_FLAGS, 310 },
{ "max_crcs" ,SMB_PROP_MAX_CRCS ,SMB_PROP_FLAGS, 310 },
{ "max_msgs" ,SMB_PROP_MAX_MSGS ,SMB_PROP_FLAGS, 310 },
{ "max_age" ,SMB_PROP_MAX_AGE ,SMB_PROP_FLAGS, 310 },
{ "attributes" ,SMB_PROP_ATTR ,SMB_PROP_FLAGS, 310 },
{ "subnum" ,SMB_PROP_SUBNUM ,SMB_PROP_FLAGS, 310 },
{ "is_open" ,SMB_PROP_IS_OPEN ,SMB_PROP_FLAGS, 310 },
#ifdef BUILD_JSDOCS
static char* msgbase_prop_desc[] = {
"last occurred message base error - <small>READ ONLY</small>"
,"return value of last <i>SMB Library</i> function call - <small>READ ONLY</small>"
,"base path and filename of message base - <small>READ ONLY</small>"
,"message base open/lock retry timeout (in seconds)"
,"delay between message base open/lock retries (in milliseconds)"
,"first message number - <small>READ ONLY</small>"
,"last message number - <small>READ ONLY</small>"
,"total number of messages - <small>READ ONLY</small>"
,"maximum number of message CRCs to store (for dupe checking) - <small>READ ONLY</small>"
,"maximum number of messages before expiration - <small>READ ONLY</small>"
,"maximum age (in days) of messages to store - <small>READ ONLY</small>"
,"message base attributes - <small>READ ONLY</small>"
,"sub-board number (0-based, 65535 for e-mail) - <small>READ ONLY</small>"
,"<i>true</i> if the message base has been opened successfully - <small>READ ONLY</small>"
,NULL
};
#endif
static jsSyncMethodSpec js_msgbase_functions[] = {
{"open", js_open, 0, JSTYPE_BOOLEAN, JSDOCSTR("")
,JSDOCSTR("open message base")
,310
},
{"close", js_close, 0, JSTYPE_BOOLEAN, JSDOCSTR("")
,JSDOCSTR("close message base (if open)")
,310
{"get_msg_header", js_get_msg_header, 4, JSTYPE_OBJECT, JSDOCSTR("[by_offset=<tt>false</tt>,] number_or_id [,expand_fields=<tt>true</tt>] [,include_votes=<tt>false</tt>]")
,JSDOCSTR("returns a specific message header, <i>null</i> on failure. "
"<br><i>New in v3.12:</i> Pass <i>false</i> for the <i>expand_fields</i> argument (default: <i>true</i>) "
"if you will be re-writing the header later with <i>put_msg_header()</i>")
,312
{"get_all_msg_headers", js_get_all_msg_headers, 1, JSTYPE_ARRAY, JSDOCSTR("[include_votes=<tt>false</tt>]")
,JSDOCSTR("returns an object of all message headers indexed by message number.<br>"
"Message headers returned by this function include 2 additional properties: <tt>upvotes</tt> and <tt>downvotes</tt>.<br>"
{"put_msg_header", js_put_msg_header, 2, JSTYPE_BOOLEAN, JSDOCSTR("[by_offset=<tt>false</tt>,] number, object header")
,JSDOCSTR("modify an existing message header")
,310
{"get_msg_body", js_get_msg_body, 2, JSTYPE_STRING, JSDOCSTR("[by_offset=<tt>false</tt>,] number_or_id [, message_header] [,strip_ctrl_a=<tt>false</tt>] "
"[,rfc822_encoded=<tt>false</tt>] [,include_tails=<tt>true</tt>] [,plain_text=<tt>false</tt>]")
,JSDOCSTR("returns the entire body text of a specific message as a single String, <i>null</i> on failure. "
"The default behavior is to leave Ctrl-A codes intact, perform no RFC-822 encoding, and to include tails (if any) in the "
"returned body text. When <i>plain_text</i> is true, only the first plain-text portion of a multi-part MIME encoded message body is returned."
)
,310
{"get_msg_tail", js_get_msg_tail, 2, JSTYPE_STRING, JSDOCSTR("[by_offset=<tt>false</tt>,] number_or_id [, message_header] [,strip_ctrl_a]=<tt>false</tt>")
,JSDOCSTR("returns the tail text of a specific message, <i>null</i> on failure")
,310
{"get_msg_index", js_get_msg_index, 3, JSTYPE_OBJECT, JSDOCSTR("[by_offset=<tt>false</tt>,] number, [include_votes=<tt>false</tt>]")
,JSDOCSTR("returns a specific message index, <i>null</i> on failure. "
"The index object will contain the following properties:<br>"
"<table>"
"<tr><td align=top><tt>attr</tt><td>Attribute bitfield"
"<tr><td align=top><tt>time</tt><td>Date/time imported (in time_t format)"
"<tr><td align=top><tt>number</tt><td>Message number"
"<tr><td align=top><tt>offset</tt><td>Record number in index file"
"</table>"
"Indexes of regular messages will contain the following additional properties:<br>"
"<table>"
"<tr><td align=top><tt>subject</tt><td>CRC-16 of lowercase message subject"
"<tr><td align=top><tt>to</tt><td>CRC-16 of lowercase recipient's name (or user number if e-mail)"
"<tr><td align=top><tt>from</tt><td>CRC-16 of lowercase sender's name (or user number if e-mail)"
"</table>"
"Indexes of vote messages will contain the following additional properties:<br>"
"<table>"
"<tr><td align=top><tt>vote</tt><td>vote value"
"<tr><td align=top><tt>remsg</tt><td>number of message this vote is in response to"
"</table>"
)
,311
},
{"remove_msg", js_remove_msg, 2, JSTYPE_BOOLEAN, JSDOCSTR("[by_offset=<tt>false</tt>,] number_or_id")
,311
{"save_msg", js_save_msg, 2, JSTYPE_BOOLEAN, JSDOCSTR("object header [,client=<i>none</i>] [,body_text=<tt>\"\"</tt>] [,array rcpt_list=<i>none</i>]")
,JSDOCSTR("create a new message in message base, the <i>header</i> object may contain the following properties:<br>"
"<tr><td align=top><tt>subject</tt><td>Message subject <i>(required)</i>"
"<tr><td align=top><tt>to</tt><td>Recipient's name <i>(required)</i>"
"<tr><td align=top><tt>to_ext</tt><td>Recipient's user number (for local e-mail)"
"<tr><td align=top><tt>to_org</tt><td>Recipient's organization"
"<tr><td align=top><tt>to_net_type</tt><td>Recipient's network type (default: 0 for local)"
"<tr><td align=top><tt>to_net_addr</tt><td>Recipient's network address"
"<tr><td align=top><tt>to_agent</tt><td>Recipient's agent type"
"<tr><td align=top><tt>from</tt><td>Sender's name <i>(required)</i>"
"<tr><td align=top><tt>from_ext</tt><td>Sender's user number"
"<tr><td align=top><tt>from_org</tt><td>Sender's organization"
"<tr><td align=top><tt>from_net_type</tt><td>Sender's network type (default: 0 for local)"
"<tr><td align=top><tt>from_net_addr</tt><td>Sender's network address"
"<tr><td align=top><tt>from_agent</tt><td>Sender's agent type"
"<tr><td align=top><tt>from_ip_addr</tt><td>Sender's IP address (if available, for security tracking)"
"<tr><td align=top><tt>from_host_name</tt><td>Sender's host name (if available, for security tracking)"
"<tr><td align=top><tt>from_protocol</tt><td>TCP/IP protocol used by sender (if available, for security tracking)"
"<tr><td align=top><tt>from_port</tt><td>TCP/UDP port number used by sender (if available, for security tracking)"
"<tr><td align=top><tt>sender_userid</tt><td>Sender's user ID (if available, for security tracking)"
"<tr><td align=top><tt>sender_server</tt><td>Server's host name (if available, for security tracking)"
"<tr><td align=top><tt>sender_time</tt><td>Time/Date message was received from sender (if available, for security tracking)"
"<tr><td align=top><tt>replyto</tt><td>Replies should be sent to this name"
"<tr><td align=top><tt>replyto_ext</tt><td>Replies should be sent to this user number"
"<tr><td align=top><tt>replyto_org</tt><td>Replies should be sent to organization"
"<tr><td align=top><tt>replyto_net_type</tt><td>Replies should be sent to this network type"
"<tr><td align=top><tt>replyto_net_addr</tt><td>Replies should be sent to this network address"
"<tr><td align=top><tt>replyto_agent</tt><td>Replies should be sent to this agent type"
"<tr><td align=top><tt>id</tt><td>Message's RFC-822 compliant Message-ID"
"<tr><td align=top><tt>reply_id</tt><td>Message's RFC-822 compliant Reply-ID"
"<tr><td align=top><tt>reverse_path</tt><td>Message's SMTP sender address"
"<tr><td align=top><tt>forward_path</tt><td>Argument to SMTP 'RCPT TO' command"
"<tr><td align=top><tt>path</tt><td>Messages's NNTP path"
"<tr><td align=top><tt>newsgroups</tt><td>Message's NNTP newsgroups header"
"<tr><td align=top><tt>ftn_msgid</tt><td>FidoNet FTS-9 Message-ID"
"<tr><td align=top><tt>ftn_reply</tt><td>FidoNet FTS-9 Reply-ID"
"<tr><td align=top><tt>ftn_area</tt><td>FidoNet FTS-4 echomail AREA tag"
"<tr><td align=top><tt>ftn_flags</tt><td>FidoNet FSC-53 FLAGS"
"<tr><td align=top><tt>ftn_pid</tt><td>FidoNet FSC-46 Program Identifier"
"<tr><td align=top><tt>ftn_tid</tt><td>FidoNet FSC-46 Tosser Identifier"
"<tr><td align=top><tt>date</tt><td>RFC-822 formatted date/time"
"<tr><td align=top><tt>attr</tt><td>Attribute bitfield"
"<tr><td align=top><tt>auxattr</tt><td>Auxillary attribute bitfield"
"<tr><td align=top><tt>netattr</tt><td>Network attribute bitfield"
"<tr><td align=top><tt>when_written_time</tt><td>Date/time (in time_t format)"
"<tr><td align=top><tt>when_written_zone</tt><td>Time zone (in SMB format)"
"<tr><td align=top><tt>when_written_zone_offset</tt><td>Time zone in minutes east of UTC"
"<tr><td align=top><tt>when_imported_time</tt><td>Date/time message was imported"
"<tr><td align=top><tt>when_imported_zone</tt><td>Time zone (in SMB format)"
"<tr><td align=top><tt>when_imported_zone_offset</tt><td>Time zone in minutes east of UTC"
"<tr><td align=top><tt>thread_id</tt><td>Thread identifier (originating message number)"
"<tr><td align=top><tt>thread_back</tt><td>Message number that this message is a reply to"
"<tr><td align=top><tt>thread_next</tt><td>Message number of the next reply to the original message in this thread"
"<tr><td align=top><tt>thread_first</tt><td>Message number of the first reply to this message"
"<tr><td align=top><tt>field_list[].type</tt><td>Other SMB header fields (type)"
"<tr><td align=top><tt>field_list[].data</tt><td>Other SMB header fields (data)"
"</table>"
"<br><i>New in v3.12:</i> "
"The optional <i>client</i> argument is an instance of the <i>Client</i> class to be used for the "
"security log header fields (e.g. sender IP address, hostname, protocol, and port). As of version 3.16c, the "
"global client object will be used if this is omitted."
"<br><br><i>New in v3.12:</i> "
"The optional <i>rcpt_list</i> is an array of objects that specifies multiple recipients "
"for a single message (e.g. bulk e-mail). Each object in the array may include the following header properties "
"(described above): <br>"
"<i>to</i>, <i>to_ext</i>, <i>to_org</i>, <i>to_net_type</i>, <i>to_net_addr</i>, and <i>to_agent</i>"
)
,312
},
{"vote_msg", js_vote_msg, 1, JSTYPE_BOOLEAN, JSDOCSTR("object header")
,JSDOCSTR("create a new vote in message base, the <i>header</i> object should contain the following properties:<br>"
"<table>"
"<tr><td align=top><tt>from</tt><td>Sender's name <i>(required)</i>"
"<tr><td align=top><tt>from_ext</tt><td>Sender's user number (if applicable)"
"<tr><td align=top><tt>from_net_type</tt><td>Sender's network type (default: 0 for local)"
"<tr><td align=top><tt>from_net_addr</tt><td>Sender's network address"
"<tr><td align=top><tt>reply_id</tt><td>The Reply-ID of the message being voted on (or specify thread_back)"
"<tr><td align=top><tt>thread_back</tt><td>Message number of the message being voted on"
"<tr><td align=top><tt>attr</tt><td>Should be either MSG_UPVOTE, MSG_DOWNVOTE, or MSG_VOTE (if answer to poll)"
"</table>"
)
,317
},
{"add_poll", js_add_poll, 1, JSTYPE_BOOLEAN, JSDOCSTR("object header")
,JSDOCSTR("create a new poll in message base, the <i>header</i> object should contain the following properties:<br>"
"<table>"
"<tr><td align=top><tt>subject</tt><td>Polling question <i>(required)</i>"
"<tr><td align=top><tt>from</tt><td>Sender's name <i>(required)</i>"
"<tr><td align=top><tt>from_ext</tt><td>Sender's user number (if applicable)"
"<tr><td align=top><tt>from_net_type</tt><td>Sender's network type (default: 0 for local)"
"<tr><td align=top><tt>from_net_addr</tt><td>Sender's network address"
"</table>"
)
,317
},
static JSBool js_msgbase_resolve(JSContext *cx, JSObject *obj, jsid id)
if(id != JSID_VOID && id != JSID_EMPTY) {
jsval idval;
JS_IdToValue(cx, id, &idval);
if(JSVAL_IS_STRING(idval)) {
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(idval), name, NULL);
HANDLE_PENDING(cx);
}
ret=js_SyncResolve(cx, obj, name, js_msgbase_properties, js_msgbase_functions, NULL, 0);
if(name)
free(name);
return ret;
}
static JSBool js_msgbase_enumerate(JSContext *cx, JSObject *obj)
{
}
static JSClass js_msgbase_class = {
"MsgBase" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
,JS_PropertyStub /* addProperty */
,JS_PropertyStub /* delProperty */
,js_msgbase_get /* getProperty */
,js_msgbase_set /* setProperty */
,js_msgbase_enumerate /* enumerate */
,js_msgbase_resolve /* resolve */
,JS_ConvertStub /* convert */
,js_finalize_msgbase /* finalize */
};
/* MsgBase Constructor (open message base) */
static JSBool
js_msgbase_constructor(JSContext *cx, uintN argc, jsval *arglist)
JSObject * obj;
jsval * argv=JS_ARGV(cx, arglist);
JSString* js_str;
JSObject* cfgobj;
char* base;
private_t* p;
scfg_t* scfg;
scfg=JS_GetRuntimePrivate(JS_GetRuntime(cx));
obj=JS_NewObject(cx, &js_msgbase_class, NULL, NULL);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(obj));
if((p=(private_t*)malloc(sizeof(private_t)))==NULL) {
JS_ReportError(cx,"malloc failed");
}
memset(p,0,sizeof(private_t));
p->smb.retry_time=scfg->smb_retry_time;
js_str = JS_ValueToString(cx, argv[0]);
JSSTRING_TO_MSTRING(cx, js_str, base, NULL);
HANDLE_PENDING(cx);
if(base==NULL) {
JS_ReportError(cx, "Invalid base parameter");
free(p);
return JS_FALSE;
}
p->debug=JS_FALSE;
if(!JS_SetPrivate(cx, obj, p)) {
JS_ReportError(cx,"JS_SetPrivate failed");
free(p);
}
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx,obj,"Class used for accessing message bases",310);
js_DescribeSyncConstructor(cx,obj,"To create a new MsgBase object: "
"<tt>var msgbase = new MsgBase('<i>code</i>')</tt><br>"
"where <i>code</i> is a sub-board internal code, or <tt>mail</tt> for the e-mail message base");
js_CreateArrayOfStrings(cx, obj, "_property_desc_list", msgbase_prop_desc, JSPROP_READONLY);
#endif
if(stricmp(base,"mail")==0) {
p->smb.subnum=INVALID_SUB;
snprintf(p->smb.file,sizeof(p->smb.file),"%s%s",scfg->data_dir,"mail");
} else {
for(p->smb.subnum=0;p->smb.subnum<scfg->total_subs;p->smb.subnum++) {
if(!stricmp(scfg->sub[p->smb.subnum]->code,base))
break;
if(p->smb.subnum<scfg->total_subs) {
cfgobj=JS_NewObject(cx,NULL,NULL,obj);
#ifdef BUILD_JSDOCS
/* needed for property description alignment */
JS_DefineProperty(cx,cfgobj,"index",JSVAL_VOID
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
JS_DefineProperty(cx,cfgobj,"grp_index",JSVAL_VOID
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
#endif
js_CreateMsgAreaProperties(cx, scfg, cfgobj, p->smb.subnum);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx,cfgobj
,"Configuration parameters for this message area (<i>sub-boards only</i>) "
"- <small>READ ONLY</small>"
,310);
#endif
JS_DefineProperty(cx,obj,"cfg",OBJECT_TO_JSVAL(cfgobj)
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
snprintf(p->smb.file,sizeof(p->smb.file),"%s%s"
,scfg->sub[p->smb.subnum]->data_dir,scfg->sub[p->smb.subnum]->code);
} else { /* unknown code */
SAFECOPY(p->smb.file,base);
p->smb.subnum=INVALID_SUB;
}
}
static struct JSPropertySpec js_msgbase_static_properties[] = {
/* name ,tinyid ,flags, getter, setter */
{ "IndexPrototype" ,0 ,JSPROP_ENUMERATE|JSPROP_PERMANENT, NULL,NULL},
{ "HeaderPrototype" ,0 ,JSPROP_ENUMERATE|JSPROP_PERMANENT, NULL,NULL},
{0}
};
JSObject* DLLCALL js_CreateMsgBaseClass(JSContext* cx, JSObject* parent, scfg_t* cfg)
{
JSObject* obj;
JSObject* constructor;
jsval val;
obj = JS_InitClass(cx, parent, NULL
,&js_msgbase_class
,js_msgbase_constructor
,1 /* number of constructor args */
,NULL /* js_msgbase_properties */
,NULL /* js_msgbase_functions */
,js_msgbase_static_properties,NULL);
if(JS_GetProperty(cx, parent, js_msgbase_class.name, &val) && !JSVAL_NULL_OR_VOID(val)) {
JS_ValueToObject(cx,val,&constructor);
JS_DefineObject(cx,constructor,"IndexPrototype",NULL,NULL,JSPROP_PERMANENT|JSPROP_ENUMERATE);
JS_DefineObject(cx,constructor,"HeaderPrototype",NULL,NULL,JSPROP_PERMANENT|JSPROP_ENUMERATE);
return(obj);
}