js_msgbase.c 80.5 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 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
#include "userdat.h"
41
42
43
44
45
46

#ifdef JAVASCRIPT

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

} private_t;

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

} privatemsg_t;

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

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* 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 */

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

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

	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);
	}

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

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


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

126
127
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

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

	return(JS_TRUE);
}

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

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

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

174
	if(JS_GetProperty(cx, hdr, "to_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
175
176
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
177
178
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_ext\" string in recipient object");
rswindell's avatar
rswindell committed
179
			return(FALSE);
180
181
		}
		if((p->status=smb_hfield_str(msg, RECIPIENTEXT, cp))!=SMB_SUCCESS) {
182
			free(cp);
183
			JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header", p->status);
184
			return(FALSE);
185
		}
rswindell's avatar
rswindell committed
186
187
188
189
		if(p->smb.status.attr&SMB_EMAIL)
			msg->idx.to=atoi(cp);
	}

190
	if(JS_GetProperty(cx, hdr, "to_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
191
192
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
193
194
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_org\" string in recipient object");
rswindell's avatar
rswindell committed
195
			return(FALSE);
196
197
		}
		if((p->status=smb_hfield_str(msg, RECIPIENTORG, cp))!=SMB_SUCCESS) {
198
			free(cp);
199
			JS_ReportError(cx, "Error %d adding RECIPIENTORG field to message header", p->status);
200
			return(FALSE);
201
		}
rswindell's avatar
rswindell committed
202
203
	}

204
	if(JS_GetProperty(cx, hdr, "to_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
205
206
		if(!JS_ValueToInt32(cx,val,&i32))
			return(FALSE);
rswindell's avatar
rswindell committed
207
208
209
		nettype=(ushort)i32;
	}

210
	if(JS_GetProperty(cx, hdr, "to_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
211
212
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
213
214
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_net_addr\" string in recipient object");
rswindell's avatar
rswindell committed
215
			return(FALSE);
216
		}
217
		if((p->status=smb_hfield_netaddr(msg, RECIPIENTNETADDR, cp, &nettype))!=SMB_SUCCESS) {
218
			free(cp);
219
			JS_ReportError(cx, "Error %d adding RECIPIENTADDR field to message header", p->status);
220
			return(FALSE);
221
		}
222
	}
223
	free(cp);
224
225

	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
		if(p->smb.status.attr&SMB_EMAIL) {
			if(nettype==NET_QWK && msg->idx.to==0) {
				char fulladdr[128];
				msg->idx.to = qwk_route(scfg, msg->to_net.addr, fulladdr, sizeof(fulladdr)-1);
				if(fulladdr[0]==0) {
					JS_ReportError(cx, "Unrouteable QWKnet \"to_net_addr\" (%s) in recipient object"
						,msg->to_net.addr);
					return(FALSE);
				}
				if((p->status=smb_hfield_str(msg, RECIPIENTNETADDR, fulladdr))!=SMB_SUCCESS) {
					JS_ReportError(cx, "Error %d adding RECIPIENTADDR field to message header"
						,p->status);
					return(FALSE);
				}
				if(msg->idx.to != 0) {
					char ext[32];
					sprintf(ext,"%u",msg->idx.to);
					if((p->status=smb_hfield_str(msg, RECIPIENTEXT, ext))!=SMB_SUCCESS) {
						JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header"
							,p->status);
						return(FALSE);
					}
				}
			} else
				msg->idx.to=0;
		}
252
		if((p->status=smb_hfield_bin(msg, RECIPIENTNETTYPE, nettype))!=SMB_SUCCESS) {
253
			JS_ReportError(cx, "Error %d adding RECIPIENTNETTYPE field to message header", p->status);
254
			return(FALSE);
255
		}
rswindell's avatar
rswindell committed
256
257
	}

258
	if(JS_GetProperty(cx, hdr, "to_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
259
260
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
rswindell's avatar
rswindell committed
261
		agent=(ushort)i32;
262
		if((p->status=smb_hfield_bin(msg, RECIPIENTAGENT, agent))!=SMB_SUCCESS) {
263
			JS_ReportError(cx, "Error %d adding RECIPIENTAGENT field to message header", p->status);
264
			return(FALSE);
265
		}
rswindell's avatar
rswindell committed
266
	}
267
268
269
270
271
272
273

	return(TRUE);
}

static BOOL parse_header_object(JSContext* cx, private_t* p, JSObject* hdr, smbmsg_t* msg
								,BOOL recipient)
{
274
275
	char*		cp=NULL;
	size_t		cp_sz=0;
276
	char		from[256];
277
	ushort		nettype=NET_UNKNOWN;
278
	ushort		type;
279
280
	ushort		agent;
	int32		i32;
281
	jsval		val;
282
283
284
	JSObject*	array;
	JSObject*	field;
	jsuint		i,len;
285

286
287
	if(hdr==NULL) {
		JS_ReportError(cx, "NULL header object");
288
		goto err;
289
	}
290

291
	if(recipient && !parse_recipient_object(cx,p,hdr,msg))
292
		goto err;
293

294
	/* Required Header Fields */
295
	if(JS_GetProperty(cx, hdr, "subject", &val) && !JSVAL_NULL_OR_VOID(val)) {
296
297
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
298
299
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"subject\" string in header object");
300
			goto err;
301
		}
302
	} else
303
		cp=strdup("");
304
305

	if((p->status=smb_hfield_str(msg, SUBJECT, cp))!=SMB_SUCCESS) {
306
		JS_ReportError(cx, "Error %d adding SUBJECT field to message header", p->status);
307
		goto err;
308
	}
309
	msg->idx.subj=smb_subject_crc(cp);
310

311
	if(JS_GetProperty(cx, hdr, "from", &val) && !JSVAL_NULL_OR_VOID(val)) {
312
313
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
314
315
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from\" string in header object");
316
			goto err;
317
318
319
		}
	} else {
		JS_ReportError(cx, "\"from\" property required in header");
320
		goto err;	/* "from" property required */
321
322
	}
	if((p->status=smb_hfield_str(msg, SENDER, cp))!=SMB_SUCCESS) {
323
		JS_ReportError(cx, "Error %d adding SENDER field to message header", p->status);
324
		goto err;
325
	}
326
	if(!(p->smb.status.attr&SMB_EMAIL)) {
327
328
		SAFECOPY(from,cp);
		strlwr(from);
329
		msg->idx.from=crc16(from,0);
330
	}
331
332

	/* Optional Header Fields */
333
	if(JS_GetProperty(cx, hdr, "from_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
334
335
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
336
337
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_ext\" string in header object");
338
			goto err;
339
340
		}
		if((p->status=smb_hfield_str(msg, SENDEREXT, cp))!=SMB_SUCCESS) {
341
			JS_ReportError(cx, "Error %d adding SENDEREXT field to message header", p->status);
342
			goto err;
343
		}
344
		if(p->smb.status.attr&SMB_EMAIL)
345
346
347
			msg->idx.from=atoi(cp);
	}

348
	if(JS_GetProperty(cx, hdr, "from_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
349
350
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
351
352
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_org\" string in header object");
353
			goto err;
354
355
		}
		if((p->status=smb_hfield_str(msg, SENDERORG, cp))!=SMB_SUCCESS) {
356
			JS_ReportError(cx, "Error %d adding SENDERORG field to message header", p->status);
357
			goto err;
358
		}
359
360
	}

361
	if(JS_GetProperty(cx, hdr, "from_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
362
363
364
		if(!JS_ValueToInt32(cx,val,&i32)) {
			goto err;
		}
365
		nettype=(ushort)i32;
366
367
	}

368
	if(JS_GetProperty(cx, hdr, "from_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
369
370
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
371
372
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_net_addr\" string in header object");
373
			goto err;
374
		}
375
		if((p->status=smb_hfield_netaddr(msg, SENDERNETADDR, cp, &nettype))!=SMB_SUCCESS) {
376
			JS_ReportError(cx, "Error %d adding SENDERNETADDR field to message header", p->status);
377
			goto err;
378
		}
379
380
381
382
383
	}
	
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
		if(p->smb.status.attr&SMB_EMAIL)
			msg->idx.from=0;
384
		if((p->status=smb_hfield_bin(msg, SENDERNETTYPE, nettype))!=SMB_SUCCESS) {
385
			JS_ReportError(cx, "Error %d adding SENDERNETTYPE field to message header", p->status);
386
			goto err;
387
		}
388
389
	}

390
	if(JS_GetProperty(cx, hdr, "from_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
391
		if(!JS_ValueToInt32(cx,val,&i32))
392
			goto err;
393
		agent=(ushort)i32;
394
		if((p->status=smb_hfield_bin(msg, SENDERAGENT, agent))!=SMB_SUCCESS) {
395
			JS_ReportError(cx, "Error %d adding SENDERAGENT field to message header", p->status);
396
			goto err;
397
		}
398
399
	}

400
	if(JS_GetProperty(cx, hdr, "from_ip_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
401
402
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
403
404
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_ip_addr\" string in header object");
405
			goto err;
406
407
		}
		if((p->status=smb_hfield_str(msg, SENDERIPADDR, cp))!=SMB_SUCCESS) {
408
			JS_ReportError(cx, "Error %d adding SENDERIPADDR field to message header", p->status);
409
			goto err;
410
		}
411
412
	}

413
	if(JS_GetProperty(cx, hdr, "from_host_name", &val) && !JSVAL_NULL_OR_VOID(val)) {
414
415
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
416
417
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_host_name\" string in header object");
418
			goto err;
419
420
		}
		if((p->status=smb_hfield_str(msg, SENDERHOSTNAME, cp))!=SMB_SUCCESS) {
421
			JS_ReportError(cx, "Error %d adding SENDERHOSTNAME field to message header", p->status);
422
			goto err;
423
		}
424
425
	}

426
	if(JS_GetProperty(cx, hdr, "from_protocol", &val) && !JSVAL_NULL_OR_VOID(val)) {
427
428
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
429
430
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_protocol\" string in header object");
431
			goto err;
432
433
		}
		if((p->status=smb_hfield_str(msg, SENDERPROTOCOL, cp))!=SMB_SUCCESS) {
434
			JS_ReportError(cx, "Error %d adding SENDERPROTOCOL field to message header", p->status);
435
			goto err;
436
		}
437
438
	}

439
	if(JS_GetProperty(cx, hdr, "from_port", &val) && !JSVAL_NULL_OR_VOID(val)) {
440
441
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
442
443
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_port\" string in header object");
444
			goto err;
445
446
		}
		if((p->status=smb_hfield_str(msg, SENDERPORT, cp))!=SMB_SUCCESS) {
447
			JS_ReportError(cx, "Error %d adding SENDERPORT field to message header", p->status);
448
			goto err;
449
		}
450
451
	}

452
	if(JS_GetProperty(cx, hdr, "sender_userid", &val) && !JSVAL_NULL_OR_VOID(val)) {
453
454
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
455
456
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_userid\" string in header object");
457
			goto err;
458
459
460
		}
		if((p->status=smb_hfield_str(msg, SENDERUSERID, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERUSERID field to message header", p->status);
461
			goto err;
462
463
464
465
		}
	}

	if(JS_GetProperty(cx, hdr, "sender_server", &val) && !JSVAL_NULL_OR_VOID(val)) {
466
467
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
468
469
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_server\" string in header object");
470
			goto err;
471
472
473
		}
		if((p->status=smb_hfield_str(msg, SENDERSERVER, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERSERVER field to message header", p->status);
474
			goto err;
475
476
477
478
		}
	}

	if(JS_GetProperty(cx, hdr, "sender_time", &val) && !JSVAL_NULL_OR_VOID(val)) {
479
480
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
481
482
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_time\" string in header object");
483
			goto err;
484
485
486
		}
		if((p->status=smb_hfield_str(msg, SENDERTIME, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERTIME field to message header", p->status);
487
			goto err;
488
489
490
		}
	}
	
491
	if(JS_GetProperty(cx, hdr, "replyto", &val) && !JSVAL_NULL_OR_VOID(val)) {
492
493
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
494
495
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto\" string in header object");
496
			goto err;
497
498
		}
		if((p->status=smb_hfield_str(msg, REPLYTO, cp))!=SMB_SUCCESS) {
499
			JS_ReportError(cx, "Error %d adding REPLYTO field to message header", p->status);
500
			goto err;
501
		}
502
503
	}

504
	if(JS_GetProperty(cx, hdr, "replyto_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
505
506
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
507
508
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_ext\" string in header object");
509
			goto err;
510
511
		}
		if((p->status=smb_hfield_str(msg, REPLYTOEXT, cp))!=SMB_SUCCESS) {
512
			JS_ReportError(cx, "Error %d adding REPLYTOEXT field to message header", p->status);
513
			goto err;
514
		}
515
516
	}

517
	if(JS_GetProperty(cx, hdr, "replyto_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
518
519
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
520
521
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_org\" string in header object");
522
			goto err;
523
524
		}
		if((p->status=smb_hfield_str(msg, REPLYTOORG, cp))!=SMB_SUCCESS) {
525
			JS_ReportError(cx, "Error %d adding REPLYTOORG field to message header", p->status);
526
			goto err;
527
		}
528
529
	}

530
	nettype=NET_UNKNOWN;
531
	if(JS_GetProperty(cx, hdr, "replyto_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
532
		if(!JS_ValueToInt32(cx,val,&i32))
533
			goto err;
534
		nettype=(ushort)i32;
535
	}
536
	if(JS_GetProperty(cx, hdr, "replyto_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
537
538
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
539
540
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_net_addr\" string in header object");
541
			goto err;
542
		}
543
		if((p->status=smb_hfield_netaddr(msg, REPLYTONETADDR, cp, &nettype))!=SMB_SUCCESS) {
544
			JS_ReportError(cx, "Error %d adding REPLYTONETADDR field to message header", p->status);
545
			goto err;
546
		}
547
548
	}
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
549
		if((p->status=smb_hfield_bin(msg, REPLYTONETTYPE, nettype))!=SMB_SUCCESS) {
550
			JS_ReportError(cx, "Error %d adding REPLYTONETTYPE field to message header", p->status);
551
			goto err;
552
		}
553
554
	}

555
	if(JS_GetProperty(cx, hdr, "replyto_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
556
		if(!JS_ValueToInt32(cx,val,&i32))
557
			goto err;
558
		agent=(ushort)i32;
559
		if((p->status=smb_hfield_bin(msg, REPLYTOAGENT, agent))!=SMB_SUCCESS) {
560
			JS_ReportError(cx, "Error %d adding REPLYTOAGENT field to message header", p->status);
561
			goto err;
562
		}
563
564
	}

565
	/* RFC822 headers */
566
	if(JS_GetProperty(cx, hdr, "id", &val) && !JSVAL_NULL_OR_VOID(val)) {
567
568
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
569
570
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"id\" string in header object");
571
			goto err;
572
573
		}
		if((p->status=smb_hfield_str(msg, RFC822MSGID, cp))!=SMB_SUCCESS) {
574
			JS_ReportError(cx, "Error %d adding RFC822MSGID field to message header", p->status);
575
			goto err;
576
		}
577
578
	}

579
	if(JS_GetProperty(cx, hdr, "reply_id", &val) && !JSVAL_NULL_OR_VOID(val)) {
580
581
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
582
583
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"reply_id\" string in header object");
584
			goto err;
585
586
		}
		if((p->status=smb_hfield_str(msg, RFC822REPLYID, cp))!=SMB_SUCCESS) {
587
			JS_ReportError(cx, "Error %d adding RFC822REPLYID field to message header", p->status);
588
			goto err;
589
		}
590
591
	}

592
	/* SMTP headers */
593
	if(JS_GetProperty(cx, hdr, "reverse_path", &val) && !JSVAL_NULL_OR_VOID(val)) {
594
595
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
596
597
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"reverse_path\" string in header object");
598
			goto err;
599
600
		}
		if((p->status=smb_hfield_str(msg, SMTPREVERSEPATH, cp))!=SMB_SUCCESS) {
601
			JS_ReportError(cx, "Error %d adding SMTPREVERSEPATH field to message header", p->status);
602
			goto err;
603
		}
604
605
	}

606
	if(JS_GetProperty(cx, hdr, "forward_path", &val) && !JSVAL_NULL_OR_VOID(val)) {
607
608
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
609
610
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"forward_path\" string in header object");
611
			goto err;
612
613
		}
		if((p->status=smb_hfield_str(msg, SMTPFORWARDPATH, cp))!=SMB_SUCCESS) {
614
			JS_ReportError(cx, "Error %d adding SMTPFORWARDPATH field to message header", p->status);
615
			goto err;
616
		}
617
618
	}

619
	/* USENET headers */
620
	if(JS_GetProperty(cx, hdr, "path", &val) && !JSVAL_NULL_OR_VOID(val)) {
621
622
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
623
624
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"path\" string in header object");
625
			goto err;
626
627
		}
		if((p->status=smb_hfield_str(msg, USENETPATH, cp))!=SMB_SUCCESS) {
628
			JS_ReportError(cx, "Error %d adding USENETPATH field to message header", p->status);
629
			goto err;
630
		}
631
632
	}

633
	if(JS_GetProperty(cx, hdr, "newsgroups", &val) && !JSVAL_NULL_OR_VOID(val)) {
634
635
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
636
637
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"newsgroups\" string in header object");
638
			goto err;
639
640
		}
		if((p->status=smb_hfield_str(msg, USENETNEWSGROUPS, cp))!=SMB_SUCCESS) {
641
			JS_ReportError(cx, "Error %d adding USENETNEWSGROUPS field to message header", p->status);
642
			goto err;
643
		}
644
645
646
	}

	/* FTN headers */
647
	if(JS_GetProperty(cx, hdr, "ftn_msgid", &val) && !JSVAL_NULL_OR_VOID(val)) {
648
649
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
650
651
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_msgid\" string in header object");
652
			goto err;
653
654
		}
		if((p->status=smb_hfield_str(msg, FIDOMSGID, cp))!=SMB_SUCCESS) {
655
			JS_ReportError(cx, "Error %d adding FIDOMSGID field to message header", p->status);
656
			goto err;
657
		}
658
659
	}

660
	if(JS_GetProperty(cx, hdr, "ftn_reply", &val) && !JSVAL_NULL_OR_VOID(val)) {
661
662
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
663
664
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_reply\" string in header object");
665
			goto err;
666
667
		}
		if((p->status=smb_hfield_str(msg, FIDOREPLYID, cp))!=SMB_SUCCESS) {
668
			JS_ReportError(cx, "Error %d adding FIDOREPLYID field to message header", p->status);
669
			goto err;
670
		}
671
672
	}

673
	if(JS_GetProperty(cx, hdr, "ftn_area", &val) && !JSVAL_NULL_OR_VOID(val)) {
674
675
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
676
677
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_area\" string in header object");
678
			goto err;
679
680
		}
		if((p->status=smb_hfield_str(msg, FIDOAREA, cp))!=SMB_SUCCESS) {
681
			JS_ReportError(cx, "Error %d adding FIDOAREA field to message header", p->status);
682
			goto err;
683
		}
684
685
	}

686
	if(JS_GetProperty(cx, hdr, "ftn_flags", &val) && !JSVAL_NULL_OR_VOID(val)) {
687
688
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
689
690
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_flags\" string in header object");
691
			goto err;
692
693
		}
		if((p->status=smb_hfield_str(msg, FIDOFLAGS, cp))!=SMB_SUCCESS) {
694
			JS_ReportError(cx, "Error %d adding FIDOFLAGS field to message header", p->status);
695
			goto err;
696
		}
697
698
	}

699
	if(JS_GetProperty(cx, hdr, "ftn_pid", &val) && !JSVAL_NULL_OR_VOID(val)) {
700
701
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
702
703
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_pid\" string in header object");
704
			goto err;
705
706
		}
		if((p->status=smb_hfield_str(msg, FIDOPID, cp))!=SMB_SUCCESS) {
707
			JS_ReportError(cx, "Error %d adding FIDOPID field to message header", p->status);
708
			goto err;
709
		}
710
711
	}

712
	if(JS_GetProperty(cx, hdr, "ftn_tid", &val) && !JSVAL_NULL_OR_VOID(val)) {
713
714
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
715
716
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_tid\" string in header object");
717
			goto err;
718
719
		}
		if((p->status=smb_hfield_str(msg, FIDOTID, cp))!=SMB_SUCCESS) {
720
			JS_ReportError(cx, "Error %d adding FIDOTID field to message header", p->status);
721
			goto err;
722
		}
723
724
	}

725
	if(JS_GetProperty(cx, hdr, "date", &val) && !JSVAL_NULL_OR_VOID(val)) {
726
727
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx);
728
729
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"date\" string in header object");
730
			goto err;
731
		}
732
733
		msg->hdr.when_written=rfc822date(cp);
	}
734

735
	/* Numeric Header Fields */
736
	if(JS_GetProperty(cx, hdr, "attr", &val) && !JSVAL_NULL_OR_VOID(val)) {
737
		if(!JS_ValueToInt32(cx,val,&i32))
738
			goto err;
739
		msg->hdr.attr=(ushort)i32;
740
741
		msg->idx.attr=msg->hdr.attr;
	}
742
	if(JS_GetProperty(cx, hdr, "auxattr", &val) && !JSVAL_NULL_OR_VOID(val)) {
743
		if(!JS_ValueToInt32(cx,val,&i32))
744
			goto err;
745
746
		msg->hdr.auxattr=i32;
	}
747
	if(JS_GetProperty(cx, hdr, "netattr", &val) && !JSVAL_NULL_OR_VOID(val)) {
748
		if(!JS_ValueToInt32(cx,val,&i32))
749
			goto err;
750
751
		msg->hdr.netattr=i32;
	}
752
	if(JS_GetProperty(cx, hdr, "when_written_time", &val) && !JSVAL_NULL_OR_VOID(val))  {
753
		if(!JS_ValueToInt32(cx,val,&i32))
754
			goto err;
755
756
		msg->hdr.when_written.time=i32;
	}
757
	if(JS_GetProperty(cx, hdr, "when_written_zone", &val) && !JSVAL_NULL_OR_VOID(val)) {
758