js_msgbase.c 85.3 KB
Newer Older
1
2
3
4
5
6
7
8
/* 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)		*
 *																			*
9
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
10
11
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
 *																			*
 * 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"
37
#include "js_request.h"
38
#include "userdat.h"
39
40
41
42
43
44

#ifdef JAVASCRIPT

typedef struct
{
	smb_t	smb;
45
	int		status;
46
47
48
49
	BOOL	debug;

} private_t;

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

} privatemsg_t;

58
59
static const char* getprivate_failure = "line %d %s JS_GetPrivate failed";

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

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

91
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
92
93
94
95
96

	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);
97
		return JS_TRUE;
98
99
	}

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

107
	JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
108
	return JS_TRUE;
109
110
111
}


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

124
125
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

126
	rc=JS_SUSPENDREQUEST(cx);
127
	smb_close(&(p->smb));
128
	JS_RESUMEREQUEST(cx, rc);
129

130
	return JS_TRUE;
131
132
}

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

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

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

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

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

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

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

	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
		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;
		}
250
		if((p->status=smb_hfield_bin(msg, RECIPIENTNETTYPE, nettype))!=SMB_SUCCESS) {
251
			JS_ReportError(cx, "Error %d adding RECIPIENTNETTYPE field to message header", p->status);
252
			return(FALSE);
253
		}
rswindell's avatar
rswindell committed
254
255
	}

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

	return(TRUE);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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