js_msgbase.c 82.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/* js_msgbase.c */

/* Synchronet JavaScript "MsgBase" Object */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html		*
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * 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.	*
 ****************************************************************************/

#include "sbbs.h"
39
#include "js_request.h"
40 41 42

#ifdef JAVASCRIPT

43
static scfg_t* 		scfg=NULL;
44 45 46 47

typedef struct
{
	smb_t	smb;
48
	int		status;
49 50 51 52
	BOOL	debug;

} private_t;

53 54 55 56 57 58 59 60
typedef struct
{
	private_t	*p;
	BOOL		expand_fields;
	smbmsg_t	msg;

} privatemsg_t;

61 62
static const char* getprivate_failure = "line %d %s JS_GetPrivate failed";

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
/* Destructor */

static void js_finalize_msgbase(JSContext *cx, JSObject *obj)
{
	private_t* p;
	
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
		return;

	if(SMB_IS_OPEN(&(p->smb)))
		smb_close(&(p->smb));

	free(p);

	JS_SetPrivate(cx, obj, NULL);
}

/* Methods */

82
static JSBool
83
js_open(JSContext *cx, uintN argc, jsval *arglist)
84
{
85
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
86
	private_t* p;
deuce's avatar
deuce committed
87
	jsrefcount	rc;
88 89
	
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
90
		JS_ReportError(cx,getprivate_failure,WHERE);
91 92 93
		return(JS_FALSE);
	}

94
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
95 96 97 98 99 100 101 102

	if(p->smb.subnum==INVALID_SUB 
		&& strchr(p->smb.file,'/')==NULL
		&& strchr(p->smb.file,'\\')==NULL) {
		JS_ReportError(cx,"Unrecognized msgbase code: %s",p->smb.file);
		return(JS_TRUE);
	}

103
	rc=JS_SUSPENDREQUEST(cx);
deuce's avatar
deuce committed
104
	if((p->status=smb_open(&(p->smb)))!=SMB_SUCCESS) {
105
		JS_RESUMEREQUEST(cx, rc);
106
		return(JS_TRUE);
deuce's avatar
deuce committed
107
	}
108
	JS_RESUMEREQUEST(cx, rc);
109

110
	JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
111 112 113 114
	return(JS_TRUE);
}


115
static JSBool
116
js_close(JSContext *cx, uintN argc, jsval *arglist)
117
{
118
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
119
	private_t* p;
deuce's avatar
deuce committed
120
	jsrefcount	rc;
121
	
122
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
123
		JS_ReportError(cx,getprivate_failure,WHERE);
124
		return(JS_FALSE);
125
	}
126

127 128
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

129
	rc=JS_SUSPENDREQUEST(cx);
130
	smb_close(&(p->smb));
131
	JS_RESUMEREQUEST(cx, rc);
132 133 134 135

	return(JS_TRUE);
}

136
static BOOL parse_recipient_object(JSContext* cx, private_t* p, JSObject* hdr, smbmsg_t* msg)
137 138
{
	char*		cp;
139
	char		to[256];
140
	ushort		nettype=NET_UNKNOWN;
141 142 143 144
	ushort		agent;
	int32		i32;
	jsval		val;

145
	if(JS_GetProperty(cx, hdr, "to", &val) && !JSVAL_NULL_OR_VOID(val)) {
146
		JSVALUE_TO_STRING(cx, val, cp, NULL);
147 148
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to\" string in recipient object");
149
			return(FALSE);
150
		}
151
	} else {
152 153
		if(p->smb.status.attr&SMB_EMAIL) {	/* e-mail */
			JS_ReportError(cx, "\"to\" property not included in email recipient object");
154
			return(FALSE);					/* "to" property required */
155
		}
156 157
		cp="All";
	}
deuce's avatar
deuce committed
158

159
	if((p->status=smb_hfield_str(msg, RECIPIENT, cp))!=SMB_SUCCESS) {
160
		JS_ReportError(cx, "Error %d adding RECIPIENT field to message header", p->status);
161
		return(FALSE);
162
	}
163 164 165 166 167 168
	if(!(p->smb.status.attr&SMB_EMAIL)) {
		SAFECOPY(to,cp);
		strlwr(to);
		msg->idx.to=crc16(to,0);
	}

169
	if(JS_GetProperty(cx, hdr, "to_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
170
		JSVALUE_TO_STRING(cx, val, cp, NULL);
171 172
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_ext\" string in recipient object");
rswindell's avatar
rswindell committed
173
			return(FALSE);
174 175
		}
		if((p->status=smb_hfield_str(msg, RECIPIENTEXT, cp))!=SMB_SUCCESS) {
176
			JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header", p->status);
177
			return(FALSE);
178
		}
rswindell's avatar
rswindell committed
179 180 181 182
		if(p->smb.status.attr&SMB_EMAIL)
			msg->idx.to=atoi(cp);
	}

183
	if(JS_GetProperty(cx, hdr, "to_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
184
		JSVALUE_TO_STRING(cx, val, cp, NULL);
185 186
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_org\" string in recipient object");
rswindell's avatar
rswindell committed
187
			return(FALSE);
188 189
		}
		if((p->status=smb_hfield_str(msg, RECIPIENTORG, cp))!=SMB_SUCCESS) {
190
			JS_ReportError(cx, "Error %d adding RECIPIENTORG field to message header", p->status);
191
			return(FALSE);
192
		}
rswindell's avatar
rswindell committed
193 194
	}

195
	if(JS_GetProperty(cx, hdr, "to_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
196 197
		if(!JS_ValueToInt32(cx,val,&i32))
			return(FALSE);
rswindell's avatar
rswindell committed
198 199 200
		nettype=(ushort)i32;
	}

201
	if(JS_GetProperty(cx, hdr, "to_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
202
		JSVALUE_TO_STRING(cx, val, cp, NULL);
203 204
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_net_addr\" string in recipient object");
rswindell's avatar
rswindell committed
205
			return(FALSE);
206 207
		}
		if((p->status=smb_hfield_netaddr(msg, RECIPIENTNETADDR, cp, &nettype))!=SMB_SUCCESS) {
208
			JS_ReportError(cx, "Error %d adding RECIPIENTADDR field to message header", p->status);
209
			return(FALSE);
210
		}
211 212 213 214 215
	}

	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
		if(p->smb.status.attr&SMB_EMAIL)
			msg->idx.to=0;
216
		if((p->status=smb_hfield_bin(msg, RECIPIENTNETTYPE, nettype))!=SMB_SUCCESS) {
217
			JS_ReportError(cx, "Error %d adding RECIPIENTNETTYPE field to message header", p->status);
218
			return(FALSE);
219
		}
rswindell's avatar
rswindell committed
220 221
	}

222
	if(JS_GetProperty(cx, hdr, "to_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
223 224
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
rswindell's avatar
rswindell committed
225
		agent=(ushort)i32;
226
		if((p->status=smb_hfield_bin(msg, RECIPIENTAGENT, agent))!=SMB_SUCCESS) {
227
			JS_ReportError(cx, "Error %d adding RECIPIENTAGENT field to message header", p->status);
228
			return(FALSE);
229
		}
rswindell's avatar
rswindell committed
230
	}
231 232 233 234 235 236 237 238

	return(TRUE);
}

static BOOL parse_header_object(JSContext* cx, private_t* p, JSObject* hdr, smbmsg_t* msg
								,BOOL recipient)
{
	char*		cp;
239
	char		from[256];
240
	ushort		nettype=NET_UNKNOWN;
241
	ushort		type;
242 243
	ushort		agent;
	int32		i32;
244
	jsval		val;
245 246 247
	JSObject*	array;
	JSObject*	field;
	jsuint		i,len;
248

249 250
	if(hdr==NULL) {
		JS_ReportError(cx, "NULL header object");
251
		return(FALSE);
252
	}
253

254 255 256
	if(recipient && !parse_recipient_object(cx,p,hdr,msg))
		return(FALSE);

257
	/* Required Header Fields */
258
	if(JS_GetProperty(cx, hdr, "subject", &val) && !JSVAL_NULL_OR_VOID(val)) {
259
		JSVALUE_TO_STRING(cx, val, cp, NULL);
260 261
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"subject\" string in header object");
262
			return(FALSE);
263
		}
264 265
	} else
		cp="";
266 267

	if((p->status=smb_hfield_str(msg, SUBJECT, cp))!=SMB_SUCCESS) {
268
		JS_ReportError(cx, "Error %d adding SUBJECT field to message header", p->status);
269
		return(FALSE);
270
	}
271
	msg->idx.subj=smb_subject_crc(cp);
272

273
	if(JS_GetProperty(cx, hdr, "from", &val) && !JSVAL_NULL_OR_VOID(val)) {
274
		JSVALUE_TO_STRING(cx, val, cp, NULL);
275 276
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from\" string in header object");
277
			return(FALSE);
278 279 280
		}
	} else {
		JS_ReportError(cx, "\"from\" property required in header");
281
		return(FALSE);	/* "from" property required */
282 283
	}
	if((p->status=smb_hfield_str(msg, SENDER, cp))!=SMB_SUCCESS) {
284
		JS_ReportError(cx, "Error %d adding SENDER field to message header", p->status);
285
		return(FALSE);
286
	}
287
	if(!(p->smb.status.attr&SMB_EMAIL)) {
288 289
		SAFECOPY(from,cp);
		strlwr(from);
290
		msg->idx.from=crc16(from,0);
291
	}
292 293

	/* Optional Header Fields */
294
	if(JS_GetProperty(cx, hdr, "from_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
295
		JSVALUE_TO_STRING(cx, val, cp, NULL);
296 297
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_ext\" string in header object");
298
			return(FALSE);
299 300
		}
		if((p->status=smb_hfield_str(msg, SENDEREXT, cp))!=SMB_SUCCESS) {
301
			JS_ReportError(cx, "Error %d adding SENDEREXT field to message header", p->status);
302
			return(FALSE);
303
		}
304
		if(p->smb.status.attr&SMB_EMAIL)
305 306 307
			msg->idx.from=atoi(cp);
	}

308
	if(JS_GetProperty(cx, hdr, "from_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
309
		JSVALUE_TO_STRING(cx, val, cp, NULL);
310 311
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_org\" string in header object");
312
			return(FALSE);
313 314
		}
		if((p->status=smb_hfield_str(msg, SENDERORG, cp))!=SMB_SUCCESS) {
315
			JS_ReportError(cx, "Error %d adding SENDERORG field to message header", p->status);
316
			return(FALSE);
317
		}
318 319
	}

320
	if(JS_GetProperty(cx, hdr, "from_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
321 322
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
323
		nettype=(ushort)i32;
324 325
	}

326
	if(JS_GetProperty(cx, hdr, "from_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
327
		JSVALUE_TO_STRING(cx, val, cp, NULL);
328 329
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_net_addr\" string in header object");
330
			return(FALSE);
331 332
		}
		if((p->status=smb_hfield_netaddr(msg, SENDERNETADDR, cp, &nettype))!=SMB_SUCCESS) {
333
			JS_ReportError(cx, "Error %d adding SENDERNETADDR field to message header", p->status);
334
			return(FALSE);
335
		}
336 337 338 339 340
	}
	
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
		if(p->smb.status.attr&SMB_EMAIL)
			msg->idx.from=0;
341
		if((p->status=smb_hfield_bin(msg, SENDERNETTYPE, nettype))!=SMB_SUCCESS) {
342
			JS_ReportError(cx, "Error %d adding SENDERNETTYPE field to message header", p->status);
343
			return(FALSE);
344
		}
345 346
	}

347
	if(JS_GetProperty(cx, hdr, "from_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
348 349
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
350
		agent=(ushort)i32;
351
		if((p->status=smb_hfield_bin(msg, SENDERAGENT, agent))!=SMB_SUCCESS) {
352
			JS_ReportError(cx, "Error %d adding SENDERAGENT field to message header", p->status);
353
			return(FALSE);
354
		}
355 356
	}

357
	if(JS_GetProperty(cx, hdr, "from_ip_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
358
		JSVALUE_TO_STRING(cx, val, cp, NULL);
359 360
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_ip_addr\" string in header object");
361
			return(FALSE);
362 363
		}
		if((p->status=smb_hfield_str(msg, SENDERIPADDR, cp))!=SMB_SUCCESS) {
364
			JS_ReportError(cx, "Error %d adding SENDERIPADDR field to message header", p->status);
365
			return(FALSE);
366
		}
367 368
	}

369
	if(JS_GetProperty(cx, hdr, "from_host_name", &val) && !JSVAL_NULL_OR_VOID(val)) {
370
		JSVALUE_TO_STRING(cx, val, cp, NULL);
371 372
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_host_name\" string in header object");
373
			return(FALSE);
374 375
		}
		if((p->status=smb_hfield_str(msg, SENDERHOSTNAME, cp))!=SMB_SUCCESS) {
376
			JS_ReportError(cx, "Error %d adding SENDERHOSTNAME field to message header", p->status);
377
			return(FALSE);
378
		}
379 380
	}

381
	if(JS_GetProperty(cx, hdr, "from_protocol", &val) && !JSVAL_NULL_OR_VOID(val)) {
382
		JSVALUE_TO_STRING(cx, val, cp, NULL);
383 384
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_protocol\" string in header object");
385
			return(FALSE);
386 387
		}
		if((p->status=smb_hfield_str(msg, SENDERPROTOCOL, cp))!=SMB_SUCCESS) {
388
			JS_ReportError(cx, "Error %d adding SENDERPROTOCOL field to message header", p->status);
389
			return(FALSE);
390
		}
391 392
	}

393
	if(JS_GetProperty(cx, hdr, "from_port", &val) && !JSVAL_NULL_OR_VOID(val)) {
394
		JSVALUE_TO_STRING(cx, val, cp, NULL);
395 396
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_port\" string in header object");
397
			return(FALSE);
398 399
		}
		if((p->status=smb_hfield_str(msg, SENDERPORT, cp))!=SMB_SUCCESS) {
400
			JS_ReportError(cx, "Error %d adding SENDERPORT field to message header", p->status);
401
			return(FALSE);
402
		}
403 404
	}

405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
	if(JS_GetProperty(cx, hdr, "sender_userid", &val) && !JSVAL_NULL_OR_VOID(val)) {
		JSVALUE_TO_STRING(cx, val, cp, NULL);
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_userid\" string in header object");
			return(FALSE);
		}
		if((p->status=smb_hfield_str(msg, SENDERUSERID, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERUSERID field to message header", p->status);
			return(FALSE);
		}
	}

	if(JS_GetProperty(cx, hdr, "sender_server", &val) && !JSVAL_NULL_OR_VOID(val)) {
		JSVALUE_TO_STRING(cx, val, cp, NULL);
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_server\" string in header object");
			return(FALSE);
		}
		if((p->status=smb_hfield_str(msg, SENDERSERVER, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERSERVER field to message header", p->status);
			return(FALSE);
		}
	}

	if(JS_GetProperty(cx, hdr, "sender_time", &val) && !JSVAL_NULL_OR_VOID(val)) {
		JSVALUE_TO_STRING(cx, val, cp, NULL);
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_time\" string in header object");
			return(FALSE);
		}
		if((p->status=smb_hfield_str(msg, SENDERTIME, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERTIME field to message header", p->status);
			return(FALSE);
		}
	}
	
441
	if(JS_GetProperty(cx, hdr, "replyto", &val) && !JSVAL_NULL_OR_VOID(val)) {
442
		JSVALUE_TO_STRING(cx, val, cp, NULL);
443 444
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto\" string in header object");
445
			return(FALSE);
446 447
		}
		if((p->status=smb_hfield_str(msg, REPLYTO, cp))!=SMB_SUCCESS) {
448
			JS_ReportError(cx, "Error %d adding REPLYTO field to message header", p->status);
449
			return(FALSE);
450
		}
451 452
	}

453
	if(JS_GetProperty(cx, hdr, "replyto_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
454
		JSVALUE_TO_STRING(cx, val, cp, NULL);
455 456
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_ext\" string in header object");
457
			return(FALSE);
458 459
		}
		if((p->status=smb_hfield_str(msg, REPLYTOEXT, cp))!=SMB_SUCCESS) {
460
			JS_ReportError(cx, "Error %d adding REPLYTOEXT field to message header", p->status);
461
			return(FALSE);
462
		}
463 464
	}

465
	if(JS_GetProperty(cx, hdr, "replyto_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
466
		JSVALUE_TO_STRING(cx, val, cp, NULL);
467 468
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_org\" string in header object");
469
			return(FALSE);
470 471
		}
		if((p->status=smb_hfield_str(msg, REPLYTOORG, cp))!=SMB_SUCCESS) {
472
			JS_ReportError(cx, "Error %d adding REPLYTOORG field to message header", p->status);
473
			return(FALSE);
474
		}
475 476
	}

477
	nettype=NET_UNKNOWN;
478
	if(JS_GetProperty(cx, hdr, "replyto_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
479 480
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
481
		nettype=(ushort)i32;
482
	}
483
	if(JS_GetProperty(cx, hdr, "replyto_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
484
		JSVALUE_TO_STRING(cx, val, cp, NULL);
485 486
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_net_addr\" string in header object");
487
			return(FALSE);
488 489
		}
		if((p->status=smb_hfield_netaddr(msg, REPLYTONETADDR, cp, &nettype))!=SMB_SUCCESS) {
490
			JS_ReportError(cx, "Error %d adding REPLYTONETADDR field to message header", p->status);
491
			return(FALSE);
492
		}
493 494
	}
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
495
		if((p->status=smb_hfield_bin(msg, REPLYTONETTYPE, nettype))!=SMB_SUCCESS) {
496
			JS_ReportError(cx, "Error %d adding REPLYTONETTYPE field to message header", p->status);
497
			return(FALSE);
498
		}
499 500
	}

501
	if(JS_GetProperty(cx, hdr, "replyto_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
502 503
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
504
		agent=(ushort)i32;
505
		if((p->status=smb_hfield_bin(msg, REPLYTOAGENT, agent))!=SMB_SUCCESS) {
506
			JS_ReportError(cx, "Error %d adding REPLYTOAGENT field to message header", p->status);
507
			return(FALSE);
508
		}
509 510
	}

511
	/* RFC822 headers */
512
	if(JS_GetProperty(cx, hdr, "id", &val) && !JSVAL_NULL_OR_VOID(val)) {
513
		JSVALUE_TO_STRING(cx, val, cp, NULL);
514 515
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"id\" string in header object");
516
			return(FALSE);
517 518
		}
		if((p->status=smb_hfield_str(msg, RFC822MSGID, cp))!=SMB_SUCCESS) {
519
			JS_ReportError(cx, "Error %d adding RFC822MSGID field to message header", p->status);
520
			return(FALSE);
521
		}
522 523
	}

524
	if(JS_GetProperty(cx, hdr, "reply_id", &val) && !JSVAL_NULL_OR_VOID(val)) {
525
		JSVALUE_TO_STRING(cx, val, cp, NULL);
526 527
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"reply_id\" string in header object");
528
			return(FALSE);
529 530
		}
		if((p->status=smb_hfield_str(msg, RFC822REPLYID, cp))!=SMB_SUCCESS) {
531
			JS_ReportError(cx, "Error %d adding RFC822REPLYID field to message header", p->status);
532
			return(FALSE);
533
		}
534 535
	}

536
	/* SMTP headers */
537
	if(JS_GetProperty(cx, hdr, "reverse_path", &val) && !JSVAL_NULL_OR_VOID(val)) {
538
		JSVALUE_TO_STRING(cx, val, cp, NULL);
539 540
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"reverse_path\" string in header object");
541
			return(FALSE);
542 543
		}
		if((p->status=smb_hfield_str(msg, SMTPREVERSEPATH, cp))!=SMB_SUCCESS) {
544
			JS_ReportError(cx, "Error %d adding SMTPREVERSEPATH field to message header", p->status);
545
			return(FALSE);
546
		}
547 548
	}

549
	if(JS_GetProperty(cx, hdr, "forward_path", &val) && !JSVAL_NULL_OR_VOID(val)) {
550
		JSVALUE_TO_STRING(cx, val, cp, NULL);
551 552
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"forward_path\" string in header object");
553
			return(FALSE);
554 555
		}
		if((p->status=smb_hfield_str(msg, SMTPFORWARDPATH, cp))!=SMB_SUCCESS) {
556
			JS_ReportError(cx, "Error %d adding SMTPFORWARDPATH field to message header", p->status);
557
			return(FALSE);
558
		}
559 560
	}

561
	/* USENET headers */
562
	if(JS_GetProperty(cx, hdr, "path", &val) && !JSVAL_NULL_OR_VOID(val)) {
563
		JSVALUE_TO_STRING(cx, val, cp, NULL);
564 565
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"path\" string in header object");
566
			return(FALSE);
567 568
		}
		if((p->status=smb_hfield_str(msg, USENETPATH, cp))!=SMB_SUCCESS) {
569
			JS_ReportError(cx, "Error %d adding USENETPATH field to message header", p->status);
570
			return(FALSE);
571
		}
572 573
	}

574
	if(JS_GetProperty(cx, hdr, "newsgroups", &val) && !JSVAL_NULL_OR_VOID(val)) {
575
		JSVALUE_TO_STRING(cx, val, cp, NULL);
576 577
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"newsgroups\" string in header object");
578
			return(FALSE);
579 580
		}
		if((p->status=smb_hfield_str(msg, USENETNEWSGROUPS, cp))!=SMB_SUCCESS) {
581
			JS_ReportError(cx, "Error %d adding USENETNEWSGROUPS field to message header", p->status);
582
			return(FALSE);
583
		}
584 585 586
	}

	/* FTN headers */
587
	if(JS_GetProperty(cx, hdr, "ftn_msgid", &val) && !JSVAL_NULL_OR_VOID(val)) {
588
		JSVALUE_TO_STRING(cx, val, cp, NULL);
589 590
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_msgid\" string in header object");
591
			return(FALSE);
592 593
		}
		if((p->status=smb_hfield_str(msg, FIDOMSGID, cp))!=SMB_SUCCESS) {
594
			JS_ReportError(cx, "Error %d adding FIDOMSGID field to message header", p->status);
595
			return(FALSE);
596
		}
597 598
	}

599
	if(JS_GetProperty(cx, hdr, "ftn_reply", &val) && !JSVAL_NULL_OR_VOID(val)) {
600
		JSVALUE_TO_STRING(cx, val, cp, NULL);
601 602
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_reply\" string in header object");
603
			return(FALSE);
604 605
		}
		if((p->status=smb_hfield_str(msg, FIDOREPLYID, cp))!=SMB_SUCCESS) {
606
			JS_ReportError(cx, "Error %d adding FIDOREPLYID field to message header", p->status);
607
			return(FALSE);
608
		}
609 610
	}

611
	if(JS_GetProperty(cx, hdr, "ftn_area", &val) && !JSVAL_NULL_OR_VOID(val)) {
612
		JSVALUE_TO_STRING(cx, val, cp, NULL);
613 614
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_area\" string in header object");
615
			return(FALSE);
616 617
		}
		if((p->status=smb_hfield_str(msg, FIDOAREA, cp))!=SMB_SUCCESS) {
618
			JS_ReportError(cx, "Error %d adding FIDOAREA field to message header", p->status);
619
			return(FALSE);
620
		}
621 622
	}

623
	if(JS_GetProperty(cx, hdr, "ftn_flags", &val) && !JSVAL_NULL_OR_VOID(val)) {
624
		JSVALUE_TO_STRING(cx, val, cp, NULL);
625 626
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_flags\" string in header object");
627
			return(FALSE);
628 629
		}
		if((p->status=smb_hfield_str(msg, FIDOFLAGS, cp))!=SMB_SUCCESS) {
630
			JS_ReportError(cx, "Error %d adding FIDOFLAGS field to message header", p->status);
631
			return(FALSE);
632
		}
633 634
	}

635
	if(JS_GetProperty(cx, hdr, "ftn_pid", &val) && !JSVAL_NULL_OR_VOID(val)) {
636
		JSVALUE_TO_STRING(cx, val, cp, NULL);
637 638
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_pid\" string in header object");
639
			return(FALSE);
640 641
		}
		if((p->status=smb_hfield_str(msg, FIDOPID, cp))!=SMB_SUCCESS) {
642
			JS_ReportError(cx, "Error %d adding FIDOPID field to message header", p->status);
643
			return(FALSE);
644
		}
645 646
	}

647
	if(JS_GetProperty(cx, hdr, "ftn_tid", &val) && !JSVAL_NULL_OR_VOID(val)) {
648
		JSVALUE_TO_STRING(cx, val, cp, NULL);
649 650
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_tid\" string in header object");
651
			return(FALSE);
652 653
		}
		if((p->status=smb_hfield_str(msg, FIDOTID, cp))!=SMB_SUCCESS) {
654
			JS_ReportError(cx, "Error %d adding FIDOTID field to message header", p->status);
655
			return(FALSE);
656
		}
657 658
	}

659
	if(JS_GetProperty(cx, hdr, "date", &val) && !JSVAL_NULL_OR_VOID(val)) {
660
		JSVALUE_TO_STRING(cx, val, cp, NULL);
661 662
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"date\" string in header object");
663
			return(FALSE);
664
		}
665 666
		msg->hdr.when_written=rfc822date(cp);
	}
667

668
	/* Numeric Header Fields */
669
	if(JS_GetProperty(cx, hdr, "attr", &val) && !JSVAL_NULL_OR_VOID(val)) {
670 671
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
672
		msg->hdr.attr=(ushort)i32;
673 674
		msg->idx.attr=msg->hdr.attr;
	}
675
	if(JS_GetProperty(cx, hdr, "auxattr", &val) && !JSVAL_NULL_OR_VOID(val)) {
676 677
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
678 679
		msg->hdr.auxattr=i32;
	}
680
	if(JS_GetProperty(cx, hdr, "netattr", &val) && !JSVAL_NULL_OR_VOID(val)) {
681 682
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
683 684
		msg->hdr.netattr=i32;
	}
685
	if(JS_GetProperty(cx, hdr, "when_written_time", &val) && !JSVAL_NULL_OR_VOID(val))  {
686 687
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
688 689
		msg->hdr.when_written.time=i32;
	}
690
	if(JS_GetProperty(cx, hdr, "when_written_zone", &val) && !JSVAL_NULL_OR_VOID(val)) {
691 692
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
rswindell's avatar